LogFAQs > #960581480

LurkerFAQs, Active DB, DB1, DB2, DB3, DB4, DB5, DB6, DB7, Database 8 ( 02.18.2021-09-28-2021 ), DB9, DB10, DB11, DB12, Clear
Topic List
Page List: 1
TopicITT: Learning Python
1337toothbrush
12/03/21 9:40:07 AM
#456:


SpiritSephiroth posted...
Yeah I can't for the life of me figure that stupid bug out. I tried to put it in its own while loop while seperating part of the code into another while loop or if function and it didn't work. Actually made it worse so I'll leave it. Maybe I'll ask my friend for help once he's free from work.

Till then back to studying.
Are you talking about the part where you choose either left or right?

You can force it like so:
first_crossroad = ""
while first_crossroad != "right" and first_crossroad != "left":
[indent] first_crossroad = input("Right or Left?").lower()

That'll loop the input part until the user inputs a correct value. You can also replace the while condition with:
while first_crossroad not in ["right", "left"]:

Then you don't have to put an "and" between each of the acceptable commands, you can simple add to the list. You can even make it more programmatic by maintaining the list elsewhere, e.g.:
acceptable_commands = ["left", "right", "back", "forward", "batman"]
while first_crossroad not in acceptable_commands:
[...]

---
... Copied to Clipboard!
Topic List
Page List: 1