0
我在哪裏錯了?該代碼運行良好,但是當我把「哥倫比亞」,它是說「錯誤的猜測!!」。但是,該計劃本身就是說,答案是「哥倫比亞」。我無法弄清楚爲什麼。Hang子手給出奇怪的結果
L=['INDIA', 'AUSTRALIA',' NETHERLANDS', 'PAKISTAN',' COLUMBIA','SPAIN',
'AUSTRIA',' GERMANY',' ITALY',' POLAND', 'CHINA',' JAPAN', 'FRANCE',
'MEXICO', 'BANGLADESH','MYANMAR','SINGAPORE','NORWAY','RUSSIA',
'SRILANKA' ,'ENGLAND','AMERICA','ALASKA','CANADA','DUBAI']
def space(s):
r=' '
for i in range(len(s)):
if s[i]!='A'and s[i]!='E' and s[i]!='I' and s[i]!='O' and s[i]!='U' and s[i]!=' ':
r=r+' _ '
else:
r=r+s[i]
return r
n=int(raw_input('Enter the number of rounds:'))
score_1=0
score_2=0
import random
for i in range(2*n):
if i%2==0:
x=random.randint(0,25)
a=space(L[x])
print a
b=raw_input('Enter your guess:')
if L[x]==b:
print 'You are correct!!'
score_1+=10
else:
print 'Wrong guess!!'
c=raw_input('Enter your guess :')
if L[x]==c:
print 'You are correct!!'
score_1+=6
else:
print 'Wrong guess!!'
d=raw_input('Enter your guess:')
if L[x]==d:
print 'You are correct!!'
score_1+=3
else:
print 'Wrong guess!!'
print 'The answer is',L[x]
if i%2==1:
x=random.randint(0,25)
e=space(L[x])
print e
f=raw_input('Enter your guess:')
if L[x]==f:
print 'You are correct!!'
score_2+=10
else:
print 'Wrong guess!!'
g=raw_input('Enter your guess :')
if L[x]==g:
print 'You are correct!!'
score_2+=6
else:
print 'Wrong guess!!'
h=raw_input('Enter your guess:')
if L[x]==h:
print 'You are correct!!'
score_2+=3
else:
print 'Wrong guess!!'
print 'The answer is',L[x]
print 'Player 1:',score_1
print 'Player 2:',score_2
你是指哥倫比亞? – 2015-02-24 16:41:30
另外,檢查縮進,一些'else'塊是 – 2015-02-24 16:46:15