2017-10-27 5 views
0

これは私のpythonコードの一部です。私はc/l/dではない別の手紙を入力した後、それは "動物はありますか?"と尋ねなければなりません。しかし、それは動作しません。私は別の手紙を入力した後、それは "1時間のaveregeの速度ですか?"ただもう一度これを尋ねると、「動物はいますか?」と私に尋ねる。python whileループエラー

私は別の文字コードを入力するときに私に尋ねます "動物はありますか?"

あなたは inputの順序を変更する必要が
type=input("enter the type of animal(cheetah:c,lion:l,deer:d):") 
speed=float(input("average speed for a hour(km):") 
while answer=="Y" or answer=="y": 
     while type=="c" or type=="d" or type=="l": 
      if type=="c": 
       ceetah_count+=1 
       total_c_speed+=speed 
      elif type=="d": 
       deer_count+=1 
       total_d_speed+=speed 
      else: 
      lion_count+=1 
      total_l_speed+=speed 
      animal_count+=1 
      total_speed+=speed 
      type=input("enter the type of animal(cheetah:c,lion:l,deer:d):") 
      speed=float(input("average speed for a hour(km):) 
     answer=input("are there any animals?(yes:y/no:n):)` 
+1

を**。 [mcve]を提供してください。 –

+0

字下げがうまくいけば、あなたのコードを見てください –

+1

「答え== "Y"」または答え== "y" 'の後にコロンが必要です:and type while ==" c "またはタイプ== "d"またはタイプ== "l" ': – toonarmycaptain

答えて

0

:あなたが求めているものが不明確**

while True: 
    type=input("enter the type of animal(cheetah:c,lion:l,deer:d):") 
    if type in ('c', 'd', 'l'): 
     speed=float(input("average speed for a hour(km):") 
     if type=="c": 
      ceetah_count+=1 
      total_c_speed+=speed 
     elif type=="d": 
       deer_count+=1 
       total_d_speed+=speed 
     else: 
      lion_count+=1 
      total_l_speed+=speed 
     animal_count+=1 
     total_speed+=speed 
    else: 
     answer=input("are there any animals?(yes:y/no:n):)") 
     if answer != 'y': 
      break