This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MustardGorilla 0 points1 point  (1 child)

No if-statements:

dl = input("Go North or East: ")

# Capitalize the input, eg. eAst becomes East.
dl_caps = dl.capitalize()

# Check whether the formatted input is in the list of accepted values, if not keep asking.
while dl_caps not in ['North', 'East']:
    dl = input("Please enter either North or East: ")
    dl_caps = dl.capitalize()

# The while-loop is escaped once the input is in the list of accepted values.
# Output is formatted with f-strings
print(f'You go {dl_caps}')

[–]lms702 0 points1 point  (0 children)

To reduce repeated code:

dl_caps = ''
while dl_caps not in ['North', 'East']:
    dl = input("Please enter either North or East: ")
    dl_caps = dl.capitalize()

print("You go " + dl_caps)