Previous post of this article :-
<ul> <li><a href="https://utopian.io/utopian-io/@meblogger/introduction-to-programming-in-python-and-javascript-issue-1" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Introduction to programming in Python and JavaScript - Issue#1 <li><a href="https://utopian.io/utopian-io/@meblogger/introduction-to-programming-in-python-and-javascript-issue-2" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Introduction to programming in Python and JavaScript - Issue#2 <li><a href="https://utopian.io/utopian-io/@meblogger/6tpyhq-introduction-to-programming-in-python-and-javascript-issue-3" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Introduction to programming in Python and JavaScript - Issue#3 <p dir="auto"><img src="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1515082303/pm2uixu9xbzyrkbxqvzv.jpg" alt="Python-JavaScript.jpg" srcset="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1515082303/pm2uixu9xbzyrkbxqvzv.jpg 1x, https://images.hive.blog/1536x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1515082303/pm2uixu9xbzyrkbxqvzv.jpg 2x" /><br /> <a href="https://www.techworm.net/2016/07/javascript-python-java-todays-top-3-programming-languages.html" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">image Source <h6><center>4.2.2 The <code>for command <p dir="auto">For means for. This command depends on a variable that is initialized at the beginning of the order. Then, as long as a certain condition is true, we execute the code, then the variable is incremented. <h5>JavaScript Code - <pre><code>// in this for loop, the variable used will be called k for (k = start value, k <end value, k = k + increment) { // code that will be executed as long as // the variable k did not reach the end value // the value of k can be used in this code // at each pass, the value of k increases by increment }; <h5>Python Code - <pre><code>## in this for loop, the variable used will be called k for k in range (start value, end value, increment): ## the indented code will be executed as long as ## the variable k did not reach the end value ## the value of k can be used in this code ## at each pass, the value of k increases by increment <h5>Example - <p dir="auto">Here is another way to construct the sum of the numbers from 1 to 10, excluding 10. <pre><code>sum = 0 for (k = 1; k <10; k = k + 1) { sum = sum + k } document.write ("the sum is worth" + sum) <pre><code>sum = 0 for k in range (1,10,1): sum = sum + k print ("the sum is worth", sum) <hr /> <h3><center><code>5 . The functions <hr /> <p dir="auto">A function is a piece of code, possibly depending on certain variables,which can be executed directly using his name. This allows -<br /> 1 . not to re-type code snippets that would be very similar;<br /> 2 . to clearly break down the main program into several parts.<br /> The functions can be made available to other programs, or even other programmers. Their name must begin with a letter, no accented letter or special character is allowed, except <code>"_". Be careful to distinguish the capital letters tiny ones. <h5>JavaScript Code - <pre><code>function functionName (argument1, argument2, ...) { // lines of code return output // optional command: // the contents of the output variable // can be used directly } <h5>Python Code - <pre><code>def functionName (argument1, argument2, ...): ## lines of code that must be indented return output ## optional command: ## the contents of the output variable ## can be directly used <p dir="auto">If the function has no arguments, it must still have parentheses. <h5>A first example- <p dir="auto">Here is a function without arguments that displays an alert message. <pre><code>function danger () { document.write ("danger function executed") } <pre><code>def danger (): print ("danger function performed") <p dir="auto">We note that parentheses must be present, even if there is no argument inside.The only way to use this feature is to call it directly to display the message on the screen. <p dir="auto"><code>danger () will print the message <code>"danger function executed" on the screen. <h5>A second example - <p dir="auto">Here is a function that returns three times the number passed as an argument. <pre><code>function triple(x) { t=3*x return t } def triple(x) : t=3*x return t <p dir="auto">In the code above, the variable t is a local variable: it is created during the execution of the function and destroyed as soon as the function has finished its execution.<br /> Here are two uses of the triple function if x is a variable to which a value is already assigned:<br /> 1 . <code>result = triple (x) will store the triple of the contents of the variable x in the variable result.<br /> 2 . <code>document.write (triple (x)) (JavaScript) or print <code>(triple (x)) (Python) will print triple the contents of the variable x on the screen. <h6>Basic rule for function arguments - <p dir="auto">Unless you're doing advanced programming, you do not want to change the arguments passed into parameters in a function. It may be useful to assign the values of parameters in local variables. <hr /> <h3><center><code>6 . Importing functions or plugins <hr /> <p dir="auto">The scripts can be put in a separate file as follows. The advantage this way of proceeding is that the script can be used in other scripts of simple and effective way. This simplifies the reading of the scripts and it also makes it possible to change only one file in case the code is improved! <h5>JavaScript Code - <p dir="auto">The original file is an HTML file. Scripts are stored directly in JavaScript<br /> apart: this avoids using HTML tags whenever you program<br /> in JavaScript. <p dir="auto">Here is the external file.js: <code>document.write ("this script is external").<br /> Here is the HTML code: - <pre><code><html> <body> <script src="externe.js"></script> </body> </html> <h5>Python Code - <p dir="auto">To tell Python to use the code in the <code>external.py file, it simply insert the following line at the beginning of the main program.<br /> <center><code>from external import * <hr /> <h3><center><code>7 . Interaction with the user <hr /> <p dir="auto">A program often requires information from the user. The Next code (JavaScript on the left and Python on the right) asks the user a question.<br /> The answer to this question will be stored as a string in the variable answer. <div class="table-responsive"><table> <thead> <tr><th>reponse = prompt("question")<th>reponse = raw_input("phrase") <tbody> <p dir="auto">If we want to transform the answer into an integer, we use the commands - <div class="table-responsive"><table> <thead> <tr><th>parseInt(reponse)(in JavaScript)<th>int(reponse)(en Python) <tbody> <p dir="auto">If you want to transform the response into a floating-point number, you use the orders- <div class="table-responsive"><table> <thead> <tr><th>parseFloat (reponse) (in JavaScript)<th>float (reponse) (in Python). <tbody> <h6><code>Discussion Continued in next post........... <h3><center> Thanks For Reading <p dir="auto"><br /><hr /><em>Posted on <a href="https://utopian.io/utopian-io/@meblogger/6raxlt-introduction-to-programming-in-python-and-javascript-issue-4" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Utopian.io - Rewarding Open Source Contributors<hr /><p>
Sorry, your contribution cannot be approved because it does not follow the Utopian Rules.
You can contact us on Discord.
[utopian-moderator]
What is X thing for Y purpose" (buzzfeed style)?
Hey @missaelcastillo, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Upvote and Follow you. Follow me and upvote all my posts. Comment 'something' on any of my post and i'll do the same. Come lets earn together @byltc