Changes between Version 50 and Version 51 of ControlSystems/SoftwareTeam/IntroToPython


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

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/IntroToPython

    v50 v51  
    197197Functions can take variables arguments as input, and may return variables as output.
    198198
    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>.
     199Here'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
     208Here's some examples of how they're used (don't forget to look at earlier lessons for range() and print().
     209
     210{{
     211
     212a=input("Pick a number, any number)
     213
     214print(a);
     215
     216b = pow(2,2)
     217
     218print(b) [ticket:4 # Answer is 4]
     219
     220c = round(3.14159, 2)
     221
     222print(c) #Answer is 3.14
     223
     224d = sum([1,2,3,4])
     225
     226print(d) # Answer is 10
     227
     228}}}
     229
     230----
    202231
    203232[[[wiki:ProgrammingReserve Programming]Archive | Programming Archive]]