School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,365 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,434 people online right now. Registration is fast and FREE... Join Now!




How to restart a script from the beginning?

 

How to restart a script from the beginning?

brianmen

20 Jun, 2009 - 08:48 PM
Post #1

New D.I.C Head
*

Joined: 14 Jun, 2009
Posts: 14



Thanked: 1 times
My Contributions
Hi all! I want to make the program I am working on restart if the user does not enter a correct value.
Here is my code
CODE
raw_input ("Press Enter to begin entering your answer")

question_one=raw_input("This is a question:")
question_one=question_one.upper()
while True:
    if question_one=="A":
        print "Correct!"
        break
    elif question_one=="B":
        print "This is also correct"
        break
    else:
        print "Error:", question_one, \
              "is an inproper answer."
        print "Please restart the program."


I want to make the program restart and start over from the top line if the else statement is reached so that the user can attempt to enter in one of the correct answers again. I do not want for the program to close, just restart. Thank you for your help.

User is offlineProfile CardPM
+Quote Post


shadhin

RE: How To Restart A Script From The Beginning?

21 Jun, 2009 - 06:21 AM
Post #2

D.I.C Regular
Group Icon

Joined: 16 Sep, 2008
Posts: 421



Thanked: 19 times
Dream Kudos: 3650
My Contributions
You can try this-
CODE

raw_input ("Press Enter to begin entering your answer")

while True:
    question_one=raw_input("This is a question:")
    question_one=question_one.upper()

    if question_one=="A":
        print "Correct!"
        break
    elif question_one=="B":
        print "This is also correct"
        break
    else:
        print "Error:", question_one, \
              "is an inproper answer."
        print "Please restart the program."

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 08:44PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month