Changes between Version 15 and Version 16 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 4, 2017, 4:54:54 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v15 v16 41 41 42 42 After a bit, you'll be rewarded with the message in the bottom window: 43 44 Hello World45 46 43 {{{ 47 44 Hello World! … … 55 52 56 53 {{{ 54 #!python 57 55 location = 'HERE' 58 56 print("Welcome to our store\n") 59 57 if location == 'HERE': 60 58 print("We're here! Come on in\n") 59 print("Our ours are 11:00am-11:52am") 61 60 else: 62 61 print("Go away, we're out eating tacos\n") 63 62 print("Hope you had a good time") 64 63 }}} 65 Welcome to our store We're here! Come on in Hope you had a good time It should print "We're here! Come on in!". If it doesn't ask for help. Spacing matters in Python. 64 It should print: 65 {{{ 66 Welcome to our store We're here! Come on in Hope you had a good time 67 }}} 66 68 67 Now, change line one to Location='Poughkeepsie, NY'. It should print "Go away, we're out eating tacos". If I was in Poughkeepsie, I'd be out eating tacos too. Ummm, tacos. 69 Three things to note: 70 1. The double equals in location=='HERE' on the first line. It is called the ''condition''. This is a equals comparison. Other kinds of comparisons in python are listed here. Also note on that line 'HERE' is in quotes. That's to indicate its a string (a text value) not some variable. 71 2. Spacing and indents in Python are important. the line "We're here..." and the line below it are indented to indicate its a part of a statement ''block'' to run when the condition is ''true''. The second block on the else is run when the condition is ''false'', and only contains one lines. If you want to do stuff outside of the IF-THEN, don't indent it like the first and last print statements. 72 73 Now, change line one to Location='Poughkeepsie, NY'. It should print "Go away, we're out eating tacos". If I was in Poughkeepsie, I'd be out eating tacos too. Yummmm, tacos. 68 74 69 75 This control struction evaluates a *expression* (location=='HERE') and if its true, then do the THEN part, otherwise do the ELSE part. This is called the IF-THEN-ELSE structure, and it’s the most basic control structure.