Continue to ask for input until correct answer is given(Python) (Non number values)
break
is what you want. Use it like so:
while 1:
answer = input("What is your favorite eldest daughter's name? ").lower()
if answer == "a" or answer == "al": #assuming this is the right answer
print("Of course, we all knew that")
break
elif answer == "c" or answer == "chris":
print("""Oh she must be standing right there.
But that\'s not it, try again.""")
elif answer == "e" or answer == "ed":
print("Not even the right gender. Try again.")
elif answer == "n" or answer == "nic":
print("Only biological children please.")
else:
print("I'm sorry. Only children. Were you thinking of the dogs?")
How to run python loop until correct input string is entered
Change beginning of code to:
while True:
name_question = input("You are the President of RSA, what is your name?: ")
if name_question == "Cyril":
name = True
break
else:
print("\nThat is incorrect, please try again.\n")
Take some inputs until 0 encountered, print each word in lowercase and break the loop
I'd suggest this, it's a combination of these 2 comments, sorry
count = 0
while True:
a = input()
if a == '0':
break
else:
print(a.lower())
count += 1
print(count)
Related Topics
Python Anaconda - How to Safely Uninstall
Python3 Tkinter Set Image Size
How to Count the Number of Files in a Directory Using Python
Iterate Over Worksheets, Rows, Columns
How to Change a Dataframe Column from String Type to Double Type in Pyspark
How to Create an Automatically Updating Gui Using Tkinter
Counting the Number of Duplicates in a List
What Is the Most Pythonic Way to Check If Multiple Variables Are Not None
Conditional Row Read of CSV in Pandas
Replacing Values in a Dataframe for Given Indices
Convert String to Python Class Object
Pip Installation /Usr/Local/Opt/Python/Bin/Python2.7: Bad Interpreter: No Such File or Directory
How to Append Two Bytes in Python
How to Remove Grid Lines on Image in Python
Get Usb Device Address Through Python
Convert String to Negative Number
Python - How to Sort Multidimensional List to Two-Dimensional List
How to Convert a Datetime Object to Milliseconds Since Epoch (Unix Time) in Python