LogFAQs > #960600141

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
SpiritSephiroth
12/03/21 9:02:20 PM
#457:


1337toothbrush posted...
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:
[...]

Thanks I'll try this out!

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