简体   繁体   中英

How do I make it so that the code will ask you your name again if the user answers no after my if statement?

Here is my code:

fullName = input("Hello there, what is your name?")

fName = (fullName[0:fullName.index(" ")])

sName = (fullName[fullName.index(" ")+1:])

print("So, your first name is", fName)
print("and your second name is", sName)
answer = input("Is this correct")

Here is where I'm having most of my issues, everything before this works fine to my knowledge:

if answer == "Yes" or answer == "yes":
    print("Great, lets get started!")
elif answer == "No" or answer == "no":

Just a simple and quick answer, maybe there is easier way.

fullName = input("Hello there, what is your name?")
fName, sName = fullName.split()

print("So, your first name is", fName)
print("and your second name is", sName)
answer = input("Is this correct?")

while not (answer == "Yes" or answer == "yes"):
    fullName = input("Hello there, what is your name?")
    fName, sName = fullName.split()
    print("So, your first name is", fName) 
    print("and your second name is", sName)
    answer = input("Is this correct?")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM