MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

src/gamesbyexample/alphabetizequiz.py:18–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16
17
18def main():
19 # Fancy animation for the title:
20 slowPrint(ALPHABET, 0.02) # (!) Try changing 0.02 to 0.0 or 1.0.
21 slowPrint(' Alphabetize Quiz', 0.02)
22 slowPrint(REVERSE_ALPHABET, 0.02)
23 time.sleep(0.5)
24
25 print('''By Al Sweigart al@inventwithpython.com
26
27Enter the alphabetical order of the letters shown as fast
28as possible. Try to alphabetize as many as possible in {} seconds!
29
30Example:
31 P M O T Q <-- The letters.
32 > mopqt <-- Enter the correct alphabetical order.
33 ''&#x27;.format(QUIZ_DURATION))
34 input('Press Enter to begin...')
35
36 startTime = time.time() # Get the current time for the start time.
37 numCorrect = 0 # Number of questions answered correctly.
38 while True: # Main game loop.
39 # Come up with letters for the question:
40 quizLetters = random.sample(ALPHABET, QUESTION_SIZE)
41 print(' '.join(quizLetters))
42 response = input('> ').upper()
43 response = response.replace(' ', '') # Remove spaces.
44
45 # Check if the quiz's time is up:
46 if time.time() - 30 > startTime:
47 print("TIME'S UP!")
48 break
49
50 # Check if the response is correct:
51 if list(response) == sorted(quizLetters):
52 print(' Correct!\n')
53 numCorrect += 1 # Increase the score by 1.
54 else:
55 print(' Sorry, wrong. :(\n')
56
57 # After the loop exits, the quiz is over. Show the final score:
58 print('In {} seconds you'.format(QUIZ_DURATION))
59 print('got {} correct!'.format(numCorrect))
60 print('Thanks for playing!')
61
62
63def slowPrint(text, pauseAmount=0.1):

Callers 1

alphabetizequiz.pyFile · 0.70

Calls 1

slowPrintFunction · 0.70

Tested by

no test coverage detected