Python Day 39 – while loops

Today I learned that while loops are the same as for loops except they continuously run until a condition is met. So one must be extra careful to use break or other criteria for certain while loops otherwise they’ll continue to run forever!

This could be very useful for the choose your own adventure story. For instance if I want the player to continually guess an answer until they get it right I could write something similar to:

movement = [“left”, “back”]

chosen_movement = “”
while chosen_movement not in movement:
chosen_movement = input(“please choose a direction to run from the zombies”)

print(“You ran away! Well done”)

Also was reminded by the Udemy course the importance of putting .casefold() after a variable if I want to account for lower and uppercase answers!

Leave a Reply

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

You are commenting using your 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: