Python Day 33 – more elif

Went further into if/elif/else statements, which is looking to be very useful to a potential choose your own adventure code game I’m thinking of making.

Learned that you can pack elif statements within a larger elif which allows for multiple potential trails of code depending on the variables. Par example… when in conversation with a pirate:

print(“How many years old are you? \n”)
age = int(input())

if age > 18:
print(“\nYou’re a strapping young lad, will you come work for me?\n”)
answer = input()
if answer == “yes”:
print(“\nYou made the right choice”)
elif answer == “no”:
print(“\nFine then I won’t be your friend”)
else:
print(“\nI don’t quite understand you. You must be dumb”)
else:
print(“\nOkay nevermind”)

Small thing I learned:

It’s important to use ‘==’ instead of ‘=’ when comparing values, ‘=’ is used when defining a variable.

Man I’m getting excited at the potentials here for some creativity 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: