Changes between Version 15 and Version 16 of ControlSystems/SoftwareTeam/IntroToPython


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

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/IntroToPython

    v15 v16  
    4141
    4242After a bit, you'll  be rewarded with the message in the bottom window:
    43 
    44 Hello World        
    45 
    4643{{{
    4744Hello World!
     
    5552
    5653{{{
     54#!python
    5755location = 'HERE'
    5856print("Welcome to our store\n")
    5957if location == 'HERE':
    6058   print("We're here! Come on in\n")
     59   print("Our ours are 11:00am-11:52am")
    6160else:
    6261   print("Go away, we're out eating tacos\n")
    6362print("Hope you had a good time")
    6463}}}
    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.
     64It should print:
     65{{{
     66Welcome to our store                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          We're here! Come on in                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Hope you had a good time 
     67}}}
    6668
    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.
     69Three things to note:
     701. 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. 
     712.  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
     73Now, 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.
    6874
    6975This 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.