poll = {} pollingactive = True while pollingactive == True: name = input("\nWhat is your…
- User
poll = {} polling_active = True
while polling_active == True: name = input("\nWhat is your name?: ") poll[name] = '' while name in poll.keys(): name = input(f"{name.title()}, you can only answer the poll once") if name not in poll.keys(): poll[name] = '' break
codelocation = input(f"{name.title()}, if you could visit one place in the world, where would you go?: ") poll[name] = location prompt = input("Would you like to continue polling? (yes/no): ") while prompt != 'yes' and prompt != 'no': prompt = input("Invalid response detected, please enter yes or no: ") if prompt == 'no': breakCan you detect any problems with this python code?
- Assistant
There are a few problems with the code:
-
In the line
while polling_active == True:, the== Trueis redundant and can be removed. It can be written aswhile polling_active:. -
After the user enters their name, the code checks if the name is already in the dictionary. However, since the input value is stored in the variable, the condition will always be as is not yet stored in the dictionary. The inner loop can be removed.
-