Changes between Version 44 and Version 45 of ControlSystems/SoftwareTeam/IntroToPython


Ignore:
Timestamp:
Sep 4, 2017, 6:58:19 PM (8 years ago)
Author:
cdelgigante
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/IntroToPython

    v44 v45  
    1515Python, like every programming language, has a structure.  Here are the big parts:
    1616
    17  * ''Variables'':  Things you assign to and read from.  Like in Algebra. `a="Dump Truck"` sets the      variable A to the string "Dump Truck".   You can set them to numbers to or fancy things like lists.  They're basically the nouns.
     17 * ''Variables'':  Things you assign to and read from.  Like in Algebra. `a="Dump Truck"` sets the      variable A to the string "Dump Truck".   You can set them to numbers to or fancy things like lists.  They're basically the nouns.
    1818 * ''Control Structures'':  These are instructions like IF this is      true THEN do that….  These are like      grammar rules, like use active voice, or use punctuation.
    19  * ''Functions'': These do things. They take nouns as arguments, do something, and can return nouns. In `redCar = paintCarRed(blueCar)`, `paintCarRed` is a function. They're the verbs, they do things, and they take variables and return variables.  Some functions are built in to Python, but you can create your own.
     19 * ''Functions'': These do things. They take nouns as arguments, do something, and can return nouns. In `redCar = paintCarRed(blueCar)`, `paintCarRed` is a function. They're the verbs, they do things, and they take variables and return variables.  Some functions are built in to Python, but you can create your own.
    2020 * ''Libraries'':  A lot of other people have written      functions to do things.  A lot of      things.   When these things are      bundled together they're called libraries.       You can tell a computer to use a library and save your self a lot      of typing.
    2121
     
    183183Yeah, this is a little harder, but I bet you can do it.  Ask a neighbor for help if you need to.  I'll give you three hints:
    184184
    185  1. You can tell a print to not end with a new line by adding an end="" to the print statement, like `print("Im a teapot!",end="")`''. ''
    186  1. An empty print statement `print("")` just prints a new line.
    187  1. If you want to loop over a set of numbers, use a `range()`.  For example, `for x in range(0,5)` will make x go from 0 to 4 incrementing 1 each time it loops.  The first number is where you start, and the second number is where you want to stop __minus 1__.  Don't ask why.  Its really nerdy.  Not buying it?  Fine. [https://softwareengineering.stackexchange.com/questions/110804/why-are-zero-based-arrays-the-norm Don't say I didn't warn you.]
     185 1. You can tell a print to not end with a new line by adding an end="" to the print statement, like this `print("Im a teapot!",end="")`''. ''
     186 1. An empty print statement `print("")` just prints a new line, basically wrapping any line you're on.
     187 1. If you want to loop over a set of numbers, use a `range()`.  For example, `for x in range(0,5)` will make x go from 0 to 4 incrementing 1 each time it loops.  The first number is where x starts, and the second number is where x will stop __minus 1__.  Don't ask why---its just the way computers and programs work.  Don't believe me?  Fine. [https://softwareengineering.stackexchange.com/questions/110804/why-are-zero-based-arrays-the-norm Don't say I didn't warn you.]
    188188
    189 The answer is [wiki:ProgrammingAnswerPotatoExercise here].
     189The solution is [wiki:ProgrammingAnswerPotatoExercise here].
    190190
    191191----