Changes between Version 53 and Version 54 of ControlSystems/SoftwareTeam/IntroToPython


Ignore:
Timestamp:
Sep 4, 2017, 7:28:50 PM (8 years ago)
Author:
cdelgigante
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/IntroToPython

    v53 v54  
    206206 * `round(x,[n])`:  Rounds a decimal number x to n digits after the decimal point.  The [] means that the n is optional, if you don't include it, n=0.
    207207 * `sum(iterable)`:  Sums all the numbers in the list ''iterable''.
    208  * str.isdigit():   Strings and some other variable types like lists have some special functions just for them, called methods.  This one returns true of all of the digits in the string are numbers, others are [[https://docs.python.org/3/library/stdtypes.html#string-methods|here]].   '123' would return ''True'', "Cat" would return ''False''. Handy for validation
     208 * `<string>.isdigit()`:   Strings and some other variable types like lists have some special functions just for them, called methods.  This one returns true of all of the digits in the string are numbers, others are [[https://docs.python.org/3/library/stdtypes.html#string-methods|here]].   '123' would return ''True'', "Cat" would return ''False''. Handy for validation.  You call them *on* the variable itself.
    209209
    210210Here's some examples of how they're used (don't forget to look at earlier lessons for range() and print().
     
    228228{{{
    229229#!python
    230 while(!x.isdigit())
     230while (!x.isdigit())  # The ! means 'not'.  In this case if x is not all digits, run the block of code in the while loop
    231231   x=input("Enter x")
    232 while(!x.isdigit())
     232while (!y.isdigit())
    233233   y=input("Enter y")
    234 z=pow(x,y)
     234z = pow(x,y)
    235235if z>100:
    236236  print("That's-a big number!")