刽子手给出了奇怪的结果

时间:2015-02-24 16:40:00

标签: python

我哪里错了?代码运行正常,但是当我输入“COLUMBIA”时,它说的是“错误的猜测!!”。然而,该计划本身就是说答案是“哥伦比亚”。我无法弄清楚原因。

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

1 个答案:

答案 0 :(得分:2)

数组条目中有一个空格' COLUMBIA'。删除空格,COLUMBIA工作正常。

其他一些国家也是如此,例如日本和意大利。