2017-03-13 7 views
0

1から9の間の乱数を生成し、その両方を含めてユーザーに数字を推測させ、あまりにも低い、高い、または高いと推測するかどうかを伝える必要があります。Python:while while loop

私は多くの異なる答えをチェックしましたが、私はエラーを見つけることができませんでしたが、明らかにwhile文の直後にコード行に詰まり、 "if"を読みません。私はPython 2.7.13を使用しています。

import random 

list1 = range(1, 10) 
times = 0 
numcpu = random.choice(list1) 
running = True 
while running: 
    numhum = raw_input("Try to guess the random number between 1 and 9 the CPU generated: ") 
    if numhum in list1: 
     if numhum == numcpu: 
      print ("You got it mate! It only took you " + times + " times") 
      break 
     else: 
      print("Try again") 
      continuar = str(input("Continue (y/n)?")) 
      if continuar == "y": 
       times = times + 1 
      elif continuar == "n": 
       print "Ciao" 
      else: 
       print "Don't mess around with me, human" 
    elif numhum == "exit": 
     print("Ciao") 
     running = False 
    else: 
     "Don't mess around with me, human" 
+1

'list1'のint(numhum)が動作する場合:だからここのコードです。 –

答えて

0

使用raw_input代わりのラインでinput

continuar = str(input("Continue (y/n)?"))