Changes between Version 143 and Version 144 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 5, 2017, 8:05:39 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v143 v144 19 19 20 20 * ''Variables'': [[Image(https://mdn.mozillademos.org/files/13506/boxes.png,10%,right,nolink)]] Things you assign to and read from. Like in Algebra. `a="Dump Truck"` sets the variable `a` to the string "Dump Truck" (a string is just a sequence of letters and numbers strung together...hence the name). You can set them to strings/text, numbers or fancy things like lists. They're basically the nouns. You can think of a variable as a box you can store something in. 21 * ''Control Structures'': [[Image(https://docs.oracle.com/cd/A58617_01/server.804/a58236/03_strua.gif,15%,right)]]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. Control structures can let you do things selectively (conditionally), iteratively (repeatedly), and sequentially.21 * ''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. Control structures can let you do things selectively (conditionally), iteratively (repeatedly), and sequentially. 22 22 * ''Functions'': [[Image(https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Function_machine2.svg/220px-Function_machine2.svg.png,right,8%,nolink)]]These do things. They take nouns as arguments (inputs), do something, and can return (output) 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. The ability to create your own functions (new words!) is a big part of what makes programming languages so powerful. 23 23 * ''Packages'': A lot of other people have written new functions to do things. A lot of things. When these things are bundled together they're called ''packages'' or ''libraries'' which you can download and use. You can tell your program to use a package and save your self a lot of typing, and do things that would require 2 or 3 college degrees without all that study. … … 52 52 53 53 = Lesson 2: Control Structures = 54 In lesson 1, we had you create a program, "Hello World". Now, "Hello World" is not too exciting if you want to program robots, but its an important first step. We showed you how to run a function (or verb) `print`, which does something (shows on the screen the value of its argument `a`, where `a` is assigned the value "Hello World". 55 56 If you want to do more in a program and actually make decisions in your code, we need to introduce control structures. 57 58 == If-Then-Else: Decide, already! == 54 59 [[Image(https://docs.oracle.com/cd/A58617_01/server.804/a58236/03_strua.gif,20%,right)]] 55 In lesson 1, we had you create a program, "Hello World". Now, "Hello World" is not too exciting if you want to program robots, but its an important first step. We showed you how to run a function (or verb) `print`, which does something (shows on the screen the value of its argument `a`, where `a` is assigned the value "Hello World".56 57 If you want to do more in a program and actually make decisions in your code, we need to introduce control structures.58 59 == If-Then-Else: Decide, already! ==60 60 Selective execution of portions of your program is done with ''conditionals''. 61 61 Take the program below, it uses an If-Then-Else control structure to ask the program to make a decision, and run code based on that decision. You'll use these all the time.