Introduction to programming in Python and JavaScript - Issue#2

in #utopian-io7 years ago (edited)

Python-JavaScript.jpg
Image Source

<h3><center><code>3 .The variables in computer science <hr /> <p dir="auto">Variables are the key elements of a programming language. We conceive a variable like a drawer containing information. The value of the variable may be called to change. To refer to the variable, we give a name. The variable names obey the following usual rules :-<br /> 1 . Their name must begin with a letter, no accented letter or character special is allowed, except <code>"_".<br /> 2 . You have to pay attention to upper and lower case letters. For example <code>X and <code>x are two names of different variables (this constraint is general to any programming HTML). <p dir="auto">In JavaScript and Python, a variable is automatically created when he is assigned a value. For example, the order - <pre><code>variableName = variableValue <p dir="auto">assigns the value Variablevalue in the drawer named variableName. <hr /> <h4><center>3 .1 The assignment of variables in computer science <hr /> <p dir="auto">Warning, unlike the symbol = in mathematics, in a programming language the symbol = should only be read in one direction. Above, one must understand that the drawer called variableName contains the variableValue object. We must do well difference between the drawer (the name of the variable) and its contents (the value of the variable).<br /> Thus, if in the content, we find the name of a variable, we must think that it is content of this variable. Here is an example that illustrates this phenomenon.<br /> <center><code>x = 5 <br /> <center><code>x = x + 1 <br /> The first line creates the variable x (if it is not already created) and assigns it the value 5. Then the second line takes the value that is in the variable x, adds 1 and assigns the result in the variable x. Here is the mental image of the second line that must be:<br /> <img src="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1514913780/ltfljfqxbzjp5kyvswnq.png" alt="pty1.png" srcset="https://images.hive.blog/768x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1514913780/ltfljfqxbzjp5kyvswnq.png 1x, https://images.hive.blog/1536x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1514913780/ltfljfqxbzjp5kyvswnq.png 2x" /> <h5>Note <p dir="auto">The variable assignments are in the computer memory. Unless you use a print command <code>(document.write in JavaScript or print in Python), we do not do not see the assignments occur. In Python, there is an exception in the Python window Interpreter, where the <code>x command displays the value of <code>x. <hr /> <h4><center>3.2 Numeric variables <hr /> <p dir="auto">There are two types of numeric variables in JavaScript and Python: integers and floating-point numbers In Python, there is a third type: long integers (which can be arbitrarily large). <h4>Conversion functions <p dir="auto">The <code>parseInt and <code>parseFloat functions are JavaScript functions that allow to convert a variable to an integer or floating point respectively. Their Python equivalents are <code>int and <code>float. <h4>Reminders about the entire division <p dir="auto">When performing the integer division of two integers a and b, we obtain a remain r and a quotient q such that a = <code>q · b + r and 0 6 r <| b |.<br /> For example, dividing 7 by 2 gives a quotient of 3 and a remainder of 1. <hr /> <h5><center>3.2.1 Mathematical Operators <hr /> <p dir="auto">For Python, use the import math command to access all commands below which start with math. (small caps). For JavaScript, it just enter Math. (with capital) before these commands. <div class="table-responsive"><table> <thead> <tr><th>Name<th>Maths<th>JavaScript<th>Python 2.6 <tbody> <tr><td>addition<td>a + b<td>a + b<td>a + b <tr><td>subtraction<td>a − b<td>a - b<td>a - b <tr><td>multiplication<td>a · b<td>a * b<td>a * b <tr><td>division<td>a/b<td>a / b<td>float(a) / float(b) <tr><td>power<td>ab<td>Math.pow(a,b)<td>math.pow (a, b) or a ** b <tr><td>whole part<td>ent(a)<td>Math.floor(a)<td>math.floor(a) <tr><td>entire division<td><td> <tr><td>· quotient<td>⌊ab⌋<td>Math.floor(a/b)<td>a / b <tr><td>· rest<td>a (mod b)<td>a % b<td>a % b <hr /> <h5><center>3.2.2 Mathematical functions <hr /> <div class="table-responsive"><table> <thead> <tr><th>JavaScript<th><th>Python 2.6<th> <tbody> <tr><td>Math.abs(x)<td>Math.acos(x)<td>abs(x)<td>math.acos(x) <tr><td>Math.asin(x)<td>Math.atan(x)<td>math.asin(x)<td>math.atan(x) <tr><td>Math.ceil(x)<td>Math.cos(x)<td>math.ceil(x)<td>math.cos(x) <tr><td>Math.exp(x)<td>Math.floor(x)<td>math.exp(x)<td>math.floor(x) <tr><td>Math.log(x)<td>Math.pow(x,y)<td>math.log(x)<td>math.sin(x) <tr><td>Math.round(x)<td>Math.sin(x)<td>math.round(x)<td>math.cos(x) <tr><td>Math.round(x)<td>Math.sin(x)<td>math.round(x)<td>math.cos(x) <tr><td>Math.sqrt(x)<td>Math.tan(x)<td>math.sqrt(x)<td>math.sqrt(x) <hr /> <h5><center>3.2.3 Mathematical constants Operators <hr /> <div class="table-responsive"><table> <thead> <tr><th>JavaScript<th><th>Python 2.6<th> <tbody> <tr><td>Math.PI<td>Math.E<td>math.pi<td>math.e <hr /> <h5><center>3.3 Strings of characters <hr /> <p dir="auto">A variable can be assigned a string of characters. This is a text surrounded quotation marks (<code>"or", without mixing).<br /> <center> <code>| text = "it's great!" | text = 'This is awesome! | <p dir="auto">In JavaScript, we must use the special character \ to display characters that are confusing (\ 'for the apostrophe and <code>\\ for displaying <code>\). In Python, you also need use <code>\ 'for the apostrophe. <hr /> <h5><center>3.3.1 Concatenation of strings <hr /> <p dir="auto">The + operator also concatenates two strings. for example <code>"good" +<code>"day" gives <code>"hello".<br /> In JavaScript, note that 21+ <code>"apples" gives <code>"21 apples" because it transforms the number 21 as a string. On the other hand in Python, such an operation causes an error. We must first transform the number 21 as a string using the str function. The command so will <code>str (21) + "apples". <hr /> <h5><center>3.3.2 Display of accented and special characters <hr /> <p dir="auto">In Python, you have to start the program with the following line, so that the characters accented and special are well recognized. <h4><center><code># -*- coding: cp1252 -*- <hr /> <h5><center>3.3.3 Line breaks and spaces <hr /> <p dir="auto">In JavaScript, we jump to the line using <code><br /> (or <code><br> which is not not the last standard but still working). In JavaScript, when there are several spaces after, only a space is reported (in fact this comes from the HTML language), but non-breaking spaces are added using & <code>nbsp; (another HTML command). <p dir="auto">In Python, a line break is made on the display using <code>\ n. We can perform a line break in the code using <code>\. The <code>\ n \command allows you to jump line in the display and in the code. In addition, spaces in strings are all shown on the display. In Python, the following code - <pre><code>Hi = "This is a rather long string \ n \ containing several lines \ text (This works \ n the same way in C / C ++). \ n \ Note that blanks at the beginning \ n of line are significant. \ N " print (Hi) <p dir="auto">give this to the display - <pre><code>This is a rather long chain containing multiple lines of text (This works in the same way in C / C ++). Note that the whites at the beginning line are significant. <h5><code>Tutorial Continued in next post. <h2><center>Thanks For Reading..................................... <p dir="auto"><br /><hr /><em>Posted on <a href="https://utopian.io/utopian-io/@meblogger/introduction-to-programming-in-python-and-javascript-issue-2" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Utopian.io - Rewarding Open Source Contributors<hr /><p>
Sort:  

Enjoy the vote and reward!

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Your contribution cannot be approved yet, because it is in the wrong category. The correct category for your post is Blog. See the Utopian Rules. Please edit your post to use the right category at this link, as shown below:

<p dir="auto">You can contact us on <a href="https://discord.gg/UCvqCsx" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Discord.<br /> <strong><a href="https://utopian.io/moderators" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">[utopian-moderator]

Hey @meblogger I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x