Branching If
if simplest.py
password = input("password: ") if password == "abcd": print("access granted")
if simpler.py
number = 5 if number > 0: print("Stay positive!")
if simple.py
word = "Hi" #single equal sign = assignment of value on RIGHT of #the equals sign to the variable on the LEFT of the equals sign if word == "Hi": #double equal sign == comparison of two values: print("G'Day!")
candy bar.py
print("Welcome to the movies.") age = int(input("How old are you?")) if (age < 13): print("You are not old enough to watch a movie.") print("Thanks for coming.") candyBarClosed = True if(candyBarClosed): print("Candy bar is not open.")
- ask me for the magic word. if i respond "please", say "thankyou".
- ask me for my age. if i am younger than 18, say "sorry you are too young to vote."
- Imagine your lucky number is the number 3. Ask me for a number between 1 and 5. If i guess 3, you should say "you got it!"
- make the lucky number in the previous question a random number.