Head First Programming
A learner's guide to programming
using the Python language
( O'Reilly Media; )
David Griffiths (著) Paul Barry (著)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Programming A learner's guide to programming using the Python language (David Griffiths(著)、Paul Barry(著)、 O'Reilly Media; )のChapter 7(Building a Graphical User Interface: Going all gooey)、LONG EXERCISE(p.224)を解いてみる。
LONG EXERCISE(p.224)
コード(BBEdit)
sample224.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import pygame.mixer
sounds = pygame.mixer
sounds.init()
def waitFinish(channel):
while channel.get_busy():
pass
sound_correct = sounds.Sound('correct.wav')
sound_wrong = sounds.Sound('wrong.wav')
number_asked = 0
number_correct = 0
number_wrong = 0
print('Press 1 for correct, 2 for incorrect, or 0 to end: ')
response = int(input())
while response != 0:
number_asked += 1
if response == 1:
number_correct += 1
waitFinish(correct.play())
elif response == 2:
number_wrong += 1
waitFinish(sound_wrong.play())
print('Press 1 for correct, 2 for incorrect, or 0 to end: ')
response = int(input())
print('asked: {0}'.format(number_asked))
print('correct: {0}'.format(number_correct))
print('wrong: {0}'.format(number_wrong))
pygameのインストールがなかなか上手くいかなかったから、とりあえず次に進むことに。
0 コメント:
コメントを投稿