my aim is to run the while loop until the user inputs a option that is in my list. If they do the while loop should end.
exchangeCurrency = input("what currency would you like to convert to: ").upper()
myList = ["USD", "ERU", "BRL", "JPY", "TRY"]
while exchangeCurrency != myList:
print("this is not a valid inpit")
continue
else:
break
CodePudding user response:
while True:
exchangeCurrency = input("what currency would you like to convert to: ").upper()
if exchangeCurrency in myList:
break
CodePudding user response:
a simple solution that may work
isTrue = True
while isTrue:
if exchangeCurrency != myList:
print("try again. Invalid currency")
else:
print("this currency is on the list")
isTrue = False
CodePudding user response:
This would be the code:
myList = ["USD", "ERU", "BRL", "JPY", "TRY"]
userInput = input("Enter a currency: ").upper()
while userInput not in myList:
print("Currency not found")
userInput = input("Enter a currency: ").upper()
CodePudding user response:
exchangeCurrency = input("what currency would you like to convert to: ").upper()
myList = ["USD", "ERU", "BRL", "JPY", "TRY"]
while exchangeCurrency not in myList:
print("Error: currency not found")
exchangeCurrency = input("what currency would you like to convert to: ").upper()