Changes between Version 115 and Version 116 of ControlSystems/SoftwareTeam/IntroToPython


Ignore:
Timestamp:
Sep 4, 2017, 11:42:10 PM (8 years ago)
Author:
cdelgigante
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/IntroToPython

    v115 v116  
    1616Python, like every programming language, has a structure.  Here are the big parts:
    1717
    18  * ''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.
     18 * ''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.
    1919 * ''Control Structures'':  These are core programming language instructions like IF this is true THEN do that….  These are a lot like grammar rules, like: use active voice, or use punctuation.  They're how you get stuff done.
    2020 * ''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.  Many functions are built in to Python, but you can (and should) create your own.
     
    4545Hello World!
    4646}}}
    47 The program told the computer to print the value of variable a on the screen.
     47The program told the computer to print the value of variable `a` on the screen.  Its considered a best practice to name your variables as nouns.
    4848
    4949And, boom, now you're a programmer.  The rest of learning how to code is just more details.  This is the end of Lesson 1.
     
    265265Run this one.  What does it output?  A lovely happy birthday song for two kids?   Now imagine if you had to write a program to print out a happy birthday for every single person in your grade without it.  It'd get pretty ugly, fast.
    266266
    267 The keyword `def` is used in Python to indicate a custom function, and you have to ''def''ine it in your program before you use it.  This function takes an argument of an age, and second argument of a list of names.  The "singHappyBirthday" line at the end actually ''calls'' or runs the custom function, with the two arguments it needs.
     267The keyword `def` is used in Python to indicate a custom function, and you have to ''def''ine it in your program before you use it.  This function takes an argument of an age, and second argument of a list of names.  The "singHappyBirthday" line at the end actually ''calls'' or runs the custom function, with the two arguments it needs.   Its considered a best practice to name your functions as verb phrases.
    268268
    269269A function can return a value too, by using the Python keyword `return` for example: