Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

I want my python code to restart if variable contain is "No"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This will do:

while True:
    nameQuestion = "Whats ur name?"
    print(nameQuestion)
    name = input()
    ageAuestion = "How old r u?"
    print(ageAuestion)
    age = input()
    print("Your name is: " + name + " " + "age: " + age + "?(yes or no)")
    answer = input()
    if answer == "Yes":
        print("Name: " + name + ", " + "Age: " + age)
        break
    else:
        print("Error")
        continue

While Doc


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...