Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # https://www.reddit.com/r/learnpython/comments/4zosbr/an_example_for_beginners_to_use/
- # http://pastebin.com/6gZEgVi2
- #
- import random
- import time
- # questions and answers list :
- data = [
- ("Does int(x) make x into an integer?", "yes"),
- ("Is Polkagrisen087 a good streamer?", "yes"),
- ("Is Justin Bieber a singer?", "yes"),
- ("Is Alexander Gay?", "no"), # Are you sure ?
- ]
- class QuestionAsker():
- def __init__(self):
- self.answers = 0
- self.display_help()
- self.run()
- def display_help(self):
- print
- print "=== The Quiz ==="
- print
- print "If invalid, scrip crashes"
- print
- print "Acceptable strings:"
- print " yes"
- print " no"
- print " c - show result"
- print " h - display this help"
- print
- def select_question(self):
- self.question, self.answer = random.choice(data)
- def run(self):
- self.select_question()
- while True:
- user_in = raw_input(self.question).strip().lower()
- if user_in == "c":
- print "Answers:", self.answers
- if user_in == "h":
- self.display_help()
- elif user_in == self.answer:
- print "that is correct!"
- self.answers += 1
- self.select_question()
- else:
- print "Wrong answer, you are not allowed to play my quiz"
- time.sleep(1)
- #raise TypeError("Invalid input") # Crashing the script.
- return # exit funtion (and end script)
- if __name__ == "__main__":
- QuestionAsker()
Add Comment
Please, Sign In to add comment