2015-02-24 123 views
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 
+3

你是指哥伦比亚? – 2015-02-24 16:41:30

+0

另外,检查缩进,一些'else'块是 – 2015-02-24 16:46:15

回答

2

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

对于像日本和意大利这样的其他人来说也是如此。

+0

从你上面提供的,这是'L = [...]'的第一行。问题有多个,所以只需检查每个国家的名称。 – Ken 2015-02-24 17:00:17