© 2019 BrainStemSchool.com

December 13, 2016

December 9, 2016

December 7, 2016

Please reload

if's - selection structures

December 15, 2016

https://youtu.be/YQgFQcLOLBY

 

The if structure explains the processing in the following: 

 

Input > Processing > Output

 

The traditional program flow.

 

Simple

if this then that

decisions

 

Syntax: 

 

if this :

    Do that

 

Example:

 

if x < 9:

     print(“x is less than 9.”)

 

Making it useful

 

Ask about something you don’t know - user input:

 

age=input(“What is your age?”)

age=int(age)

if age>=21:

    print(“Please drink responsibly.”);

    print(“If you’re drinking, don’t drive.”);

print(“Have a great day!”)

 

It’s not: “do this or do that” - we will cover those soon

It’s:  “do this or don’t do this”

But it’s best to say: “if this then do that”

which implies: “if not this, then don’t do that”

 

 

 

Share on Facebook
Share on Twitter
Please reload

Please reload

Recent Posts
Tags