199 | | Here's a few handy functions, with some examples: |
200 | | |
201 | | input(prompt): Prompts the user for input by showing the prompt screen, returning whatever the user entered after they hit <enter>. |
| 199 | Here's a few handy functions built in to Python: |
| 200 | |
| 201 | * `input(prompt)`: Prompts the user for input by showing the prompt screen, returning whatever the user entered after they hit <enter>. |
| 202 | * `pow(x,y)`: Return x^y^ |
| 203 | * `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. |
| 204 | * `sum(iterable)`: Sums all the numbers in the list ''iterable''. |
| 205 | |
| 206 | |
| 207 | |
| 208 | Here's some examples of how they're used (don't forget to look at earlier lessons for range() and print(). |
| 209 | |
| 210 | {{ |
| 211 | |
| 212 | a=input("Pick a number, any number) |
| 213 | |
| 214 | print(a); |
| 215 | |
| 216 | b = pow(2,2) |
| 217 | |
| 218 | print(b) [ticket:4 # Answer is 4] |
| 219 | |
| 220 | c = round(3.14159, 2) |
| 221 | |
| 222 | print(c) #Answer is 3.14 |
| 223 | |
| 224 | d = sum([1,2,3,4]) |
| 225 | |
| 226 | print(d) # Answer is 10 |
| 227 | |
| 228 | }}} |
| 229 | |
| 230 | ---- |