1 Replies - 9400 Views - Last Post: 21 June 2009 - 07:21 AM Rate Topic: -----

#1 brianmen  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 14-June 09

How to restart a script from the beginning?

Posted 20 June 2009 - 09:48 PM

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
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.

Is This A Good Question/Topic? 0
  • +

Replies To: How to restart a script from the beginning?

#2 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: How to restart a script from the beginning?

Posted 21 June 2009 - 07:21 AM

You can try this-
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."


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1