Page 261 -
P. 261
on with the show
Now that you know how to generate a sound using pygame, it's time to write the code for
TVN’s program. You were to base your program on the pseudo-code you created earlier.
You need to import
pygame’s “mixer” module import pygame.mixer
in order to play sounds.
Reuse the def wait_finish(channel):
“wait_finish()”
function from while channel.get_busy():
earlier.
pass
Create a mixer object
and initialize the sounds = pygame.mixer
pygame sound system.
sounds.init()
Load each of the
required sounds into its correct_s = sounds.Sound(“correct.wav")
own variable.
wrong_s = sounds.Sound(“wrong.wav")
This is what you'll
ask the question
master each time.
prompt = “Press 1 for Correct, 2 for Wrong, or 0 to Quit: "
Make sure the counts that
you’ll maintain are set to a
reasonable starting value. number_asked = 0
number_correct = 0
It would be OK to move these number_wrong = 0
three lines of code to the top
of the program, just so long as
they have starting values before
the while loop starts.
226 Chapter 7