Python で簡単クイズ 2

こいつに悩まされた raw_input

1. クイズしたい問題数を入力
2. その数だけ質問をしてきてくれるクイズ

これに改良を加えていく。

[python]
# -*- coding: utf-8 -*-

from random import shuffle
print (‘Welcome to French Quiz’)

with open("questions2.txt") as f:
lines = f.readlines()

shuffle(lines)
numRight = 0
wrong = [ ]

numQuestions = int(input("How many questions would you like to take? "))

for line in lines[:numQuestions]:
question, rightAnswer = line.strip().split("\t")
answer = raw_input(‘What is ‘ + question + ‘ in English?’ + ‘ => ‘)
if answer.lower() == rightAnswer:
print(‘You got a right Answer. \n’)
numRight += 1

else:
print(‘No, the answer is %s.’ % rightAnswer + "\n")
wrong.append(question)

print(‘You got %d right’ % (numRight)) + "\n"
if (wrong):
print (‘You got these wrong: ‘)
for q in wrong:
print (q)
[/python]

スクリーンショット 2014-11-03 21.33.23

サンプル問題たち

[python]
conge paye paid vacation
montagne mountain
fleuve river
heureux happy
coeur heart
printemps spring
ete summer
automne fall
hiver winter
nord north
est east
sud south
ouest west
souvent often
parfois sometimes
jamais never
rarement rarely
[/python]

(Visited 89 times, 1 visits today)

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA