Changes between Version 53 and Version 54 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 4, 2017, 7:28:50 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v53 v54 206 206 * `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. 207 207 * `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 validation208 * `<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. 209 209 210 210 Here's some examples of how they're used (don't forget to look at earlier lessons for range() and print(). … … 228 228 {{{ 229 229 #!python 230 while (!x.isdigit())230 while (!x.isdigit()) # The ! means 'not'. In this case if x is not all digits, run the block of code in the while loop 231 231 x=input("Enter x") 232 while (!x.isdigit())232 while (!y.isdigit()) 233 233 y=input("Enter y") 234 z =pow(x,y)234 z = pow(x,y) 235 235 if z>100: 236 236 print("That's-a big number!")