Advertisement
alext6453

Untitled

Mar 11th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. def ask_q(prompt, ans):
  2.     usr_try = input(prompt + '?: ')
  3.     if usr_try == ans:
  4.         return True
  5.     else:
  6.         return False
  7.  
  8. questions = {'When was the Weimar republic abolished': '1933',
  9.              'Was Adolf Hitler German-born?': 'No'}
  10.  
  11. print('Welcome to your history revision mini-test!')
  12.  
  13. while True:
  14.     start = input('Begin? (y/n): ')
  15.     if start != 'y':
  16.         break
  17.  
  18.     mark = 0
  19.  
  20.     for q, a in questions.items():
  21.         test = ask_q(q, a)
  22.         if test:
  23.             print('Correct!')
  24.             mark += 1
  25.         else:
  26.             print('Incorrect. The answer was: ', a)
  27.  
  28.     print('You scored {score}/{most}!'.format(score=mark, most=len(questions)))
  29.  
  30. print('Goodbye!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement