I'm trying to figure out how to make a program run over and over and over again, but I don't know. Could someone help? Thanks! :/ Here is the code:
print('To select an answer, type the number before the answer! Enjoy! Please give us some feedback on how to improve!')
person = input('Enter your name: ')
print'Hello', person
import sys
import random
class Question(object):
def __init__(self, question, answer, options):
self.question = question
self.answer = answer
self.options = options
def ask(self):
print self.question + "?"
for n, option in enumerate(self.options):
print "%d) %s" % (n + 1, option)
response = int(sys.stdin.readline().strip()) # answers are integers
if response == self.answer:
print "CORRECT"
else:
print "WRONG, TRY AGAIN"
questions = [
Question("How many legs are on a horse ", 4, ["one", "two", "three", "four", "five"]),
Question("How many wheels are on a bicycle", 2, ["one", "two", "three","twenty-six"]),
Question("How many letters are in the alphabet", 3, ["twenty four", "twenty two", "twenty six", "twenty eight"]),
Question("Who won the Super Bowl this year", 2,["Seahawks","Patriots", "Packers", "Ravens"]),
Question("Who was the Offensive Rookie of the Year for the National Football League", 1, ["Odell Beckham Junior", "Mike Evans", "Jeremy Hill"]),
Question("Who was the first president of the United States", 2, ["John Adams", "George Washington", "James Madison"]),
Question("How many yards are in a National Football League stadium", 3, ["ninety", "eighty", "hundred"]),
# more verbose formatting
Question(question="What colour is a swan in Australia",
answer=1,
options=["black", "white", "pink", "green"]), # the last one can have a comma, too
]
random.shuffle(questions) # randomizes the order of the questions
for question in questions:
question.ask()
print('Thank you for playing! Want to play again? Simply run this program again!')