Changes between Version 52 and Version 53 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 4, 2017, 7:26:21 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v52 v53 190 190 The solution is [wiki:ProgrammingAnswerPotatoExercise here]. This concludes Lesson 2. 191 191 192 192 193 = Lesson 3: Functions = 193 194 So are you tired of just printing stuff yet? In the last lesson, we introduced you to all sort of ways to make decisions and loop over code to make your program easier to read and shorter too. … … 205 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. 206 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 validation 207 209 208 210 Here's some examples of how they're used (don't forget to look at earlier lessons for range() and print(). … … 223 225 }}} 224 226 227 You can combine these functions with control structures to do interesting stuff too: 228 {{{ 229 #!python 230 while(!x.isdigit()) 231 x=input("Enter x") 232 while(!x.isdigit()) 233 y=input("Enter y") 234 z=pow(x,y) 235 if z>100: 236 print("That's-a big number!") 237 }}} 238 225 239 ---- 226 240 [[[wiki:ProgrammingReserve Programming]Archive | Programming Archive]]