How Do You Know if Something Gets a Single or Double Bond

v. Conditionals¶

Programs get actually interesting when nosotros can test conditions and change the program behaviour depending on the outcome of the tests. That'south what this affiliate is about.

v.i. Boolean values and expressions¶

A Boolean value is either true or false. It is named later on the British mathematician, George Boole, who commencement formulated Boolean algebra — some rules for reasoning about and combining these values. This is the footing of all modern computer logic.

In Python, the two Boolean values are True and False (the capitalization must be exactly as shown), and the Python blazon is bool.

                >>>                                blazon                (                True                )                <class 'bool'>                >>>                                blazon                (                truthful                )                Traceback (virtually recent phone call final):                File                "<interactive input>", line                i, in                <module>                NameError:                name 'true' is not defined              

A Boolean expression is an expression that evaluates to produce a event which is a Boolean value. For instance, the operator == tests if two values are equal. It produces (or yields) a Boolean value:

                >>>                                5                ==                (                3                +                ii                )                # Is 5 equal five to the result of 3 + two?                True                >>>                                5                ==                six                False                >>>                                j                =                "hel"                >>>                                j                +                "lo"                ==                "hello"                True              

In the first statement, the ii operands evaluate to equal values, so the expression evaluates to True ; in the 2nd statement, 5 is not equal to 6, so nosotros get False .

The == operator is one of six common comparison operators which all produce a bool event; here are all six:

                x                ==                y                # Produce Truthful if ... x is equal to y                10                !=                y                # ... ten is not equal to y                10                >                y                # ... ten is greater than y                x                <                y                # ... x is less than y                x                >=                y                # ... 10 is greater than or equal to y                ten                <=                y                # ... 10 is less than or equal to y              

Although these operations are probably familiar, the Python symbols are dissimilar from the mathematical symbols. A common fault is to use a single equal sign ( = ) instead of a double equal sign ( == ). Remember that = is an assignment operator and == is a comparing operator. Also, there is no such thing every bit =< or => .

Like any other types nosotros've seen and so far, Boolean values can be assigned to variables, printed, etc.

                >>>                                age                =                eighteen                >>>                                old_enough_to_get_driving_licence                =                age                >=                17                >>>                                print                (                old_enough_to_get_driving_licence                )                True                >>>                                type                (                old_enough_to_get_driving_licence                )                <class 'bool'>              

5.2. Logical operators¶

At that place are three logical operators, and , or , and non , that permit u.s. to build more complex Boolean expressions from simpler Boolean expressions. The semantics (meaning) of these operators is like to their meaning in English. For example, 10 > 0 and x < 10 produces True only if x is greater than 0 and at the aforementioned time, 10 is less than 10.

northward % 2 == 0 or n % iii == 0 is True if either of the weather is True , that is, if the number n is divisible past 2 or information technology is divisible past 3. (What exercise you lot call up happens if n is divisible by both 2 and by 3 at the same time? Will the expression yield True or Fake ? Try it in your Python interpreter.)

Finally, the not operator negates a Boolean value, and then non (x > y) is True if (x > y) is Fake , that is, if x is less than or equal to y .

The expression on the left of the or operator is evaluated first: if the effect is True , Python does not (and demand not) evaluate the expression on the correct — this is called short-circuit evaluation. Similarly, for the and operator, if the expression on the left yields Fake , Python does not evaluate the expression on the correct.

So there are no unnecessary evaluations.

5.3. Truth Tables¶

A truth table is a small table that allows united states to list all the possible inputs, and to give the results for the logical operators. Because the and and or operators each accept two operands, in that location are only 4 rows in a truth tabular array that describes the semantics of and .

a b a and b
Simulated False Fake
Faux Truthful False
True False Imitation
True Truthful True

In a Truth Tabular array, we sometimes use T and F equally shorthand for the two Boolean values: here is the truth table describing or :

a b a or b
F F F
F T T
T F T
T T T

The third logical operator, not , just takes a single operand, so its truth tabular array only has two rows:

5.iv. Simplifying Boolean Expressions¶

A fix of rules for simplifying and rearranging expressions is called an algebra. For example, we are all familiar with school algebra rules, such equally:

Here we see a dissimilar algebra — the Boolean algebra — which provides rules for working with Boolean values.

Outset, the and operator:

                x and False == Fake                Imitation and x == False                y and x == x and y                x and True == x                True and ten == x                ten and ten == x              

Here are some corresponding rules for the or operator:

                x or False == x                Fake or x == x                y or 10 == ten or y                ten or True == True                True or x == True                x or x == x              

2 non operators cancel each other:

five.5. Conditional execution¶

In gild to write useful programs, we almost e'er need the ability to bank check atmospheric condition and change the behavior of the plan appropriately. Provisional statements give us this ability. The simplest form is the if statement:

                          if                          x                          %                          2                          ==                          0                          :                          print                          (                          10                          ,                          " is fifty-fifty."                          )                          impress                          (                          "Did you know that 2 is the simply fifty-fifty number that is prime?"                          )                          else                          :                          print                          (                          x                          ,                          " is odd."                          )                          impress                          (                          "Did you know that multiplying two odd numbers "                          +                          "e'er gives an odd result?"                          )                        

The Boolean expression subsequently the if statement is called the condition. If information technology is true, then all the indented statements get executed. If not, then all the statements indented under the else clause become executed.

Flowchart of an if statement with an else clause

_images/flowchart_if_else.png

The syntax for an if statement looks like this:

                          if                          BOOLEAN                          EXPRESSION                          :                          STATEMENTS_1                          # Executed if status evaluates to Truthful                          else                          :                          STATEMENTS_2                          # Executed if condition evaluates to False                        

Every bit with the function definition from the terminal chapter and other compound statements similar for , the if statement consists of a header line and a body. The header line begins with the keyword if followed past a Boolean expression and ends with a colon (:).

The indented statements that follow are called a cake. The get-go unindented argument marks the end of the block.

Each of the statements within the first block of statements are executed in guild if the Boolean expression evaluates to Truthful . The entire first block of statements is skipped if the Boolean expression evaluates to False , and instead all the statements indented under the else clause are executed.

There is no limit on the number of statements that can appear under the two clauses of an if statement, but there has to exist at least one argument in each block. Occasionally, it is useful to have a department with no statements (ordinarily as a place keeper, or scaffolding, for code nosotros haven't written yet). In that case, we can utilize the laissez passer statement, which does nada except human activity equally a placeholder.

                          if                          True                          :                          # This is always Truthful,                          laissez passer                          #   and so this is ever executed, but information technology does cypher                          else                          :                          pass                        

5.6. Omitting the else clause¶

Flowchart of an if statement with no else clause

_images/flowchart_if_only.png

Another course of the if statement is i in which the else clause is omitted entirely. In this case, when the condition evaluates to True , the statements are executed, otherwise the flow of execution continues to the argument afterward the if .

                          if                          x                          <                          0                          :                          print                          (                          "The negative number "                          ,                          ten                          ,                          " is not valid here."                          )                          x                          =                          42                          impress                          (                          "I've decided to employ the number 42 instead."                          )                          print                          (                          "The foursquare root of "                          ,                          x                          ,                          "is"                          ,                          math                          .                          sqrt                          (                          x                          ))                        

In this case, the print function that outputs the square root is the one later on the if — non considering we left a blank line, but because of the way the code is indented. Note too that the function phone call math.sqrt(x) volition requite an fault unless we have an import math statement, usually placed about the elevation of our script.

Python terminology

Python documentation sometimes uses the term suite of statements to mean what we accept called a cake here. They mean the same affair, and since most other languages and reckoner scientists utilize the word cake, we'll stick with that.

Notice too that else is not a statement. The if statement has two clauses, ane of which is the (optional) else clause.

five.7. Chained conditionals¶

Sometimes at that place are more two possibilities and nosotros demand more than two branches. One way to limited a ciphering like that is a chained conditional:

                          if                          x                          <                          y                          :                          STATEMENTS_A                          elif                          x                          >                          y                          :                          STATEMENTS_B                          else                          :                          STATEMENTS_C                        

Flowchart of this chained provisional

_images/flowchart_chained_conditional.png

elif is an abbreviation of else if . Again, exactly one co-operative will exist executed. At that place is no limit of the number of elif statements merely only a single (and optional) final else statement is allowed and information technology must be the last branch in the statement:

                          if                          choice                          ==                          "a"                          :                          function_one                          ()                          elif                          selection                          ==                          "b"                          :                          function_two                          ()                          elif                          choice                          ==                          "c"                          :                          function_three                          ()                          else                          :                          print                          (                          "Invalid choice."                          )                        

Each status is checked in gild. If the first is simulated, the side by side is checked, and so on. If one of them is true, the respective co-operative executes, and the statement ends. Fifty-fifty if more than one condition is true, but the first truthful co-operative executes.

5.8. Nested conditionals¶

One provisional can too exist nested inside some other. (It is the same theme of composibility, again!) We could have written the previous example every bit follows:

Flowchart of this nested conditional

_images/flowchart_nested_conditional.png

                          if                          x                          <                          y                          :                          STATEMENTS_A                          else                          :                          if                          x                          >                          y                          :                          STATEMENTS_B                          else                          :                          STATEMENTS_C                        

The outer provisional contains two branches. The 2nd co-operative contains some other if statement, which has two branches of its own. Those two branches could contain provisional statements every bit well.

Although the indentation of the statements makes the construction apparent, nested conditionals very quickly become difficult to read. In general, it is a proficient thought to avoid them when we can.

Logical operators ofttimes provide a way to simplify nested conditional statements. For example, we tin can rewrite the following code using a unmarried conditional:

                          if                          0                          <                          x                          :                          # Assume 10 is an int here                          if                          10                          <                          ten                          :                          impress                          (                          "ten is a positive single digit."                          )                        

The print function is called just if nosotros make information technology by both the conditionals, so instead of the in a higher place which uses two if statements each with a simple condition, we could make a more than complex condition using the and operator. Now we but need a single if statement:

                          if                          0                          <                          10                          and                          10                          <                          ten                          :                          print                          (                          "x is a positive unmarried digit."                          )                        

5.ix. The render statement¶

The return argument, with or without a value, depending on whether the function is fruitful or void, allows us to finish the execution of a office before (or when) we achieve the end. 1 reason to use an early on return is if we notice an error condition:

                          def                          print_square_root                          (                          x                          ):                          if                          x                          <=                          0                          :                          print                          (                          "Positive numbers only, please."                          )                          return                          issue                          =                          ten                          **                          0.5                          print                          (                          "The square root of"                          ,                          10                          ,                          "is"                          ,                          result                          )                        

The function print_square_root has a parameter named x . The showtime matter it does is check whether 10 is less than or equal to 0, in which case it displays an error message and then uses render to get out the function. The flow of execution immediately returns to the caller, and the remaining lines of the function are non executed.

5.10. Logical opposites¶

Each of the 6 relational operators has a logical opposite: for example, suppose nosotros can become a driving licence when our age is greater or equal to 17, we can not get the driving licence when nosotros are less than 17.

Notice that the reverse of >= is < .

operator logical opposite
== !=
!= ==
< >=
<= >
> <=
>= <

Understanding these logical opposites allows us to sometimes get rid of non operators. non operators are oftentimes quite difficult to read in computer lawmaking, and our intentions will normally be clearer if nosotros can eliminate them.

For example, if we wrote this Python:

                          if                          not                          (                          age                          >=                          17                          ):                          print                          (                          "Hey, you're also young to get a driving licence!"                          )                        

it would probably be clearer to use the simplification laws, and to write instead:

                          if                          age                          <                          17                          :                          print                          (                          "Hey, you're too young to become a driving licence!"                          )                        

Ii powerful simplification laws (chosen de Morgan'due south laws) that are often helpful when dealing with complicated Boolean expressions are:

                not (x and y)  ==  (not x) or (not y)                not (x or y)   ==  (non 10) and (not y)              

For instance, suppose we can slay the dragon only if our magic lightsabre sword is charged to 90% or higher, and we take 100 or more energy units in our protective shield. We detect this fragment of Python code in the game:

                          if                          not                          ((                          sword_charge                          >=                          0.xc                          )                          and                          (                          shield_energy                          >=                          100                          )):                          impress                          (                          "Your attack has no event, the dragon fries you lot to a crisp!"                          )                          else                          :                          impress                          (                          "The dragon crumples in a heap. You rescue the gorgeous princess!"                          )                        

de Morgan's laws together with the logical opposites would allow us rework the condition in a (perhaps) easier to understand mode like this:

                          if                          (                          sword_charge                          <                          0.90                          )                          or                          (                          shield_energy                          <                          100                          ):                          print                          (                          "Your attack has no consequence, the dragon chips y'all to a crisp!"                          )                          else                          :                          print                          (                          "The dragon crumples in a heap. You rescue the gorgeous princess!"                          )                        

Nosotros could also go rid of the not by swapping around the then and else parts of the conditional. So here is a third version, also equivalent:

                          if                          (                          sword_charge                          >=                          0.90                          )                          and                          (                          shield_energy                          >=                          100                          ):                          print                          (                          "The dragon crumples in a heap. Y'all rescue the gorgeous princess!"                          )                          else                          :                          impress                          (                          "Your assail has no consequence, the dragon fries you to a crisp!"                          )                        

This version is probably the best of the three, because it very closely matches the initial English argument. Clarity of our code (for other humans), and making it like shooting fish in a barrel to run across that the code does what was expected should ever exist a high priority.

As our programming skills develop we'll detect we accept more than than i manner to solve any trouble. So good programs are designed. We make choices that favour clarity, simplicity, and elegance. The task title software architect says a lot nigh what we do — we are architects who engineer our products to balance dazzler, functionality, simplicity and clarity in our creations.

Tip

In one case our program works, we should play around a scrap trying to polish it up. Write good comments. Remember about whether the code would exist clearer with different variable names. Could nosotros have done it more elegantly? Should we rather use a role? Tin can we simplify the conditionals?

We think of our lawmaking as our creation, our work of art! Nosotros brand it great.

v.xi. Blazon conversion¶

We've had a kickoff wait at this in an earlier affiliate. Seeing it again won't hurt!

Many Python types come with a congenital-in part that attempts to convert values of some other type into its own type. The int office, for example, takes whatever value and converts it to an integer, if possible, or complains otherwise:

                >>>                                int                (                "32"                )                32                >>>                                int                (                "Hello"                )                ValueError: invalid literal for int() with base 10: 'Hi'              

int tin likewise convert floating-bespeak values to integers, but think that it truncates the fractional part:

                >>>                                int                (                -                ii.3                )                -2                >>>                                int                (                iii.99999                )                iii                >>>                                int                (                "42"                )                42                >>>                                int                (                1.0                )                1              

The float function converts integers and strings to floating-signal numbers:

                >>>                                bladder                (                32                )                32.0                >>>                                float                (                "3.14159"                )                three.14159                >>>                                float                (                i                )                one.0              

It may seem odd that Python distinguishes the integer value 1 from the floating-indicate value 1.0 . They may represent the aforementioned number, but they belong to different types. The reason is that they are represented differently inside the reckoner.

The str role converts any argument given to it to type string :

                >>>                                str                (                32                )                '32'                >>>                                str                (                three.14149                )                '3.14149'                >>>                                str                (                Truthful                )                'True'                >>>                                str                (                truthful                )                Traceback (nigh recent call last):                File                "<interactive input>", line                1, in                <module>                NameError:                proper noun 'true' is not defined              

str will work with any value and convert it into a string. As mentioned earlier, True is Boolean value; true is just an ordinary variable name, and is not divers here, so nosotros go an mistake.

5.12. A Turtle Bar Chart¶

The turtle has a lot more ability than we've seen and then far. The full documentation can be constitute at http://docs.python.org/py3k/library/turtle.html or within PyScripter, use Assistance and search for the turtle module.

Here are a couple of new tricks for our turtles:

  • We can get a turtle to brandish text on the canvas at the turtle'due south electric current position. The method to do that is alex.write("How-do-you-do") .
  • We tin can make full a shape (circle, semicircle, triangle, etc.) with a color. It is a two-stride process. First we call the method alex.begin_fill() , then nosotros draw the shape, then nosotros call alex.end_fill() .
  • We've previously set the color of our turtle — we can at present also gear up its fill up color, which demand not exist the same every bit the turtle and the pen color. We use alex.color("blue","blood-red") to set the turtle to draw in blue, and fill in red.

Ok, and then tin nosotros get tess to draw a bar chart? Let the states start with some data to be charted,

xs = [48, 117, 200, 240, 160, 260, 220]

Corresponding to each information measurement, we'll draw a simple rectangle of that height, with a stock-still width.

                          ane  2  3  iv  5  6  seven  8  9 x 11 12 13 fourteen
                          def                          draw_bar                          (                          t                          ,                          tiptop                          ):                          """ Get turtle t to draw one bar, of superlative. """                          t                          .                          left                          (                          90                          )                          t                          .                          forrard                          (                          elevation                          )                          # Draw upwards the left side                          t                          .                          right                          (                          ninety                          )                          t                          .                          frontward                          (                          twoscore                          )                          # Width of bar, forth the top                          t                          .                          right                          (                          90                          )                          t                          .                          forrard                          (                          height                          )                          # And down once again!                          t                          .                          left                          (                          xc                          )                          # Put the turtle facing the way we found it.                          t                          .                          forward                          (                          ten                          )                          # Go out small gap after each bar                          ...                          for                          v                          in                          xs                          :                          # Presume xs and tess are ready                          draw_bar                          (                          tess                          ,                          5                          )                        

_images/tess_bar_1.png

Ok, non fantasically impressive, but it is a nice kickoff! The important thing here was the mental chunking, or how we broke the trouble into smaller pieces. Our clamper is to draw one bar, and we wrote a office to do that. Then, for the whole chart, we repeatedly called our function.

Next, at the summit of each bar, we'll print the value of the data. Nosotros'll do this in the body of draw_bar , by adding t.write(' ' + str(peak)) as the new third line of the trunk. We've put a little space in forepart of the number, and turned the number into a string. Without this extra space we tend to cramp our text awkwardly against the bar to the left. The issue looks a lot ameliorate at present:

_images/tess_bar_2.png

And at present we'll add two lines to fill each bar. Our final program now looks similar this:

                          1  2  3  4  v  half-dozen  7  8  9 10 11 12 13 fourteen xv 16 17 18 19 twenty 21 22 23 24 25 26 27
                          def                          draw_bar                          (                          t                          ,                          height                          ):                          """ Get turtle t to draw ane bar, of height. """                          t                          .                          begin_fill                          ()                          # Added this line                          t                          .                          left                          (                          90                          )                          t                          .                          forward                          (                          elevation                          )                          t                          .                          write                          (                          "  "                          +                          str                          (                          meridian                          ))                          t                          .                          correct                          (                          90                          )                          t                          .                          forward                          (                          40                          )                          t                          .                          right                          (                          xc                          )                          t                          .                          forwards                          (                          superlative                          )                          t                          .                          left                          (                          xc                          )                          t                          .                          end_fill                          ()                          # Added this line                          t                          .                          forward                          (                          10                          )                          wn                          =                          turtle                          .                          Screen                          ()                          # Ready the window and its attributes                          wn                          .                          bgcolor                          (                          "lightgreen"                          )                          tess                          =                          turtle                          .                          Turtle                          ()                          # Create tess and prepare some attributes                          tess                          .                          color                          (                          "blue"                          ,                          "reddish"                          )                          tess                          .                          pensize                          (                          3                          )                          xs                          =                          [                          48                          ,                          117                          ,                          200                          ,                          240                          ,                          160                          ,                          260                          ,                          220                          ]                          for                          a                          in                          xs                          :                          draw_bar                          (                          tess                          ,                          a                          )                          wn                          .                          mainloop                          ()                        

It produces the post-obit, which is more satisfying:

_images/tess_bar_3.png

Mmm. Perhaps the bars should not exist joined to each other at the bottom. Nosotros'll need to pick up the pen while making the gap between the bars. We'll leave that every bit an exercise for yous!

5.13. Glossary¶

block
A grouping of consecutive statements with the same indentation.
body
The block of statements in a compound statement that follows the header.
Boolean algebra
Some rules for rearranging and reasoning about Boolean expressions.
Boolean expression
An expression that is either true or false.
Boolean value
There are exactly two Boolean values: True and Imitation . Boolean values result when a Boolean expression is evaluated by the Python interepreter. They have blazon bool .
branch
I of the possible paths of the flow of execution determined past conditional execution.
chained conditional
A conditional branch with more than two possible flows of execution. In Python chained conditionals are written with if ... elif ... else statements.
comparing operator
One of the six operators that compares two values: == , != , > , < , >= , and <= .
condition
The Boolean expression in a conditional argument that determines which branch is executed.
conditional statement
A argument that controls the flow of execution depending on some condition. In Python the keywords if , elif , and else are used for conditional statements.
logical operator
One of the operators that combines Boolean expressions: and , or , and not .
nesting
One program structure inside another, such every bit a conditional argument inside a branch of another conditional statement.
prompt
A visual cue that tells the user that the system is set to accept input information.
truth table
A curtailed tabular array of Boolean values that tin can draw the semantics of an operator.
blazon conversion
An explicit role telephone call that takes a value of one blazon and computes a corresponding value of some other type.
wrapping lawmaking in a function
The process of adding a function header and parameters to a sequence of program statements is often refered to as "wrapping the code in a role". This process is very useful whenever the program statements in question are going to exist used multiple times. It is even more useful when it allows the developer to express their mental chunking, and how they've broken a complex problem into pieces.

5.14. Exercises¶

  1. Assume the days of the calendar week are numbered 0,1,2,3,4,5,half dozen from Sun to Saturday. Write a part which is given the twenty-four hour period number, and it returns the twenty-four hour period proper noun (a cord).

  2. You keep a wonderful holiday (perhaps to jail, if you don't like happy exercises) leaving on day number iii (a Wed). You return dwelling after 137 sleeps. Write a general version of the program which asks for the starting day number, and the length of your stay, and it volition tell yous the name of day of the week you volition return on.

  3. Give the logical opposites of these conditions

    1. a > b
    2. a >= b
    3. a >= 18 and twenty-four hours == 3
    4. a >= 18 and day != 3
  4. What do these expressions evaluate to?

    1. 3 == 3
    2. iii != 3
    3. 3 >= four
    4. not (three < 4)
  5. Complete this truth table:

    p

    q

    r

    (not (p and q)) or r

    F

    F

    F

    ?

    F

    F

    T

    ?

    F

    T

    F

    ?

    F

    T

    T

    ?

    T

    F

    F

    ?

    T

    F

    T

    ?

    T

    T

    F

    ?

    T

    T

    T

    ?

  6. Write a function which is given an examination mark, and it returns a cord — the form for that mark — according to this scheme:

    Mark

    Class

    >= 75

    Get-go

    [70-75)

    Upper Second

    [60-70)

    Second

    [fifty-60)

    Third

    [45-l)

    F1 Supp

    [xl-45)

    F2

    < 40

    F3

    The square and round brackets announce closed and open intervals. A airtight interval includes the number, and open interval excludes it. And so 39.99999 gets class F3, merely forty gets class F2. Assume

                      xs                  =                  [                  83                  ,                  75                  ,                  74.9                  ,                  70                  ,                  69.ix                  ,                  65                  ,                  60                  ,                  59.9                  ,                  55                  ,                  50                  ,                  49.nine                  ,                  45                  ,                  44.9                  ,                  40                  ,                  39.9                  ,                  ii                  ,                  0                  ]                

    Test your function past printing the mark and the form for all the elements in this listing.

  7. Modify the turtle bar chart program so that the pen is upwards for the small gaps between each bar.

  8. Change the turtle bar chart program so that the bar for whatever value of 200 or more is filled with carmine, values between [100 and 200) are filled with yellow, and bars representing values less than 100 are filled with green.

  9. In the turtle bar chart program, what do you wait to happen if i or more of the data values in the list is negative? Try it out. Modify the program so that when it prints the text value for the negative confined, it puts the text beneath the bottom of the bar.

  10. Write a function find_hypot which, given the length of two sides of a right-angled triangle, returns the length of the hypotenuse. (Hint: x ** 0.five volition return the square root.)

  11. Write a role is_rightangled which, given the length of three sides of a triangle, will make up one's mind whether the triangle is right-angled. Assume that the third argument to the function is always the longest side. Information technology will return True if the triangle is right-angled, or False otherwise.

    Hint: Floating betoken arithmetic is non ever exactly authentic, and then it is not safe to examination floating point numbers for equality. If a expert programmer wants to know whether x is equal or close enough to y , they would probably lawmaking information technology up as:

                      if                  abs                  (                  ten                  -                  y                  )                  <                  0.000001                  :                  # If x is approximately equal to y                  ...                
  12. Extend the in a higher place plan and so that the sides can be given to the function in any order.

  13. If you lot're intrigued by why floating point arithmetic is sometimes inaccurate, on a piece of paper, divide ten by 3 and write down the decimal outcome. You lot'll find information technology does not cease, so y'all'll need an infinitely long sail of paper. The representation of numbers in computer retention or on your calculator has similar problems: retention is finite, and some digits may have to exist discarded. And so small inaccuracies creep in. Try this script:

                          import                          math                          a                          =                          math                          .                          sqrt                          (                          2.0                          )                          print                          (                          a                          ,                          a                          *                          a                          )                          print                          (                          a                          *                          a                          ==                          2.0                          )                        

daviessatterign.blogspot.com

Source: https://openbookproject.net/thinkcs/python/english3e/conditionals.html

0 Response to "How Do You Know if Something Gets a Single or Double Bond"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel