Changes between Version 56 and Version 57 of ControlSystems/SoftwareTeam/IntroToPython


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

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/IntroToPython

    v56 v57  
    207207 * `sum(iterable)`:  Sums all the numbers in the list ''iterable''.
    208208 * `<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, and it has to have a value before you can call these methods.
     209 * 'int(string)':  Converts an string to a number (so you can do things like math on it).
    209210
    210211Here's some examples of how they're used (don't forget to look at earlier lessons for range() and print().
     
    227228f = e.isdigit()
    228229print(f) #Result is True
     230
     231g = int("123")
     232print(g) #Result is 123
     233
    229234}}}
    230235
    231236Try running these yourself, making sure the results are as expected.
    232237
    233 You can even combine these functions with control structures to do some interesting stuff.  For example, try running this (entering values for x and why when prompted.  Try putting in non-numeric values too):
     238You can even combine these functions with control structures to do some interesting stuff, and even nest them.  For example, try running this (entering values for x and why when prompted.  Try putting in non-numeric or decimal values too):
    234239
    235240{{{
     
    241246while not y.isdigit():
    242247   y=input("Enter y-->")
    243 z = pow(x,y)
     248z = pow(int(x),int(y))
    244249if z > 100:
    245250  print("That's-a big number!")