-6
空白クイズに塗りつぶしを作成しようとしています。対ifループ*間違った選択*
答えが正しくないときにforループを使用すると、リストの最初の要素に常に戻りますが、これを回避する方法はありますか?または別のループを使用しますか?
下記の完全なコードを参照してください。 ITは完全ではありません EASYの回答選択でのみ動作します。 問題は、最初に空白(想像)で正しく答えると表示され、2番目のもので失敗すると表示されます。
非常に助かります。 quiz()
のためにも適用することができる同様の
def level():
global a
a = raw_input('Please select Level? (Easy/Medium/Hard): ')
pending = True
while pending:
if a == 'Easy':
pending = False
return attempts()
elif a == 'Medium':
pending = False
return 'Med'
elif a == 'Hard':
pending = False
return 'Hard'
else :
print 'Invalid option'
print '\n'
何か:
imag = '***1*** there is no heaven, It is ***2*** if you try, No hell below us, Above us only sky, ***1*** all the people living for today, ***1*** there is no ***3***, It is not hard to do, Nothing to kill or die for, And no religion too, ***1*** all the people living life in ***4***.'
imag_ans = ['Imagine', 'easy', 'heaven', 'peace']
blanks = ['***1***', '***2***', '***3***', '***4**']
def level():
print 'Please select Level? (Easy/Medium/Hard)'
global a
a = raw_input()
if a == 'Easy':
return attempts()
if a == 'Medium':
return 'Med'
if a == 'Hard':
return 'Hard'
else :
print 'Invalid option'
print '\n'
return level()
def attempts():
print 'How many attempts will you need?'
global numberofatt
numberofatt = raw_input()
try:
float(numberofatt)
except ValueError:
print "Please enter a number for attempts"
return attempts()
numberofatt = int(numberofatt)
if numberofatt <= 0 :
print 'Please enter a positive number'
return attempts()
else :
return quiz(a)
def quiz(level):
i = 0
global user_ans
global i
print 'Please fill in the blanks, you have ' + str(numberofatt) + ' attempts'
for blank in blanks:
print 'Fill in blank' + blank
user_ans = raw_input()
if user_ans == imag_ans[i]:
i = i + 1
global imag
imag = imag.replace(blank, user_ans)
print "Correct!"
print imag
else :
return att()
n = 1
def att():
if n == numberofatt :
return 'Game Finished'
if user_ans != imag_ans[i]:
global n
n = n + 1
#blank = 0
print 'Try Again'
return quiz(a)
print level()
"ifループ"のようなものはありません – khelwood
あなたが何を求めているのかは明らかではありません。 – hspandher
また、 'global'がどのように動作するのかを調べたいかもしれません。 – Lafexlos