2017-10-28 126 views
0

所以我試圖製作一個選擇動物,字母和數字的彩票程序,把它們放到一個數組中,並與另一個隨機選擇的部分相比較。while循環在完成後就結束了所有的操作

測試與我所說的動物圓。

我有無效項while循環,它不會繼續前進,直到四隻動物的一個被接受。但是,當它這樣做,變無效去假和編碼後它不會使用的。我昨晚做了這個問題,而當我終於放棄了,去睡覺了,我決定,我會寫出來的flowgorithm(如果你還沒有聽說過它使一個流程圖和你可以通過編程與它一步步)。

我做到了,它像預期的那樣工作,我複製並粘貼它,而且我得到了和昨晚完全相同的問題。

這是代碼。

#import library 

import random 

#get variables 

game = True 
invalid = True 
animalarray = [""] 

animalarray.append("tiger") 
animalarray.append("cow") 
animalarray.append("turtle") 
animalarray.append("bird") 
lotteryarray = [""] 

#game loop 

#animal round 

    print("Pick a animal: ") 
    print("tiger") 
    print("cow") 
    print("turtle") 
    print("bird") 
    print(" ") 
    lotteryarray[0] = input() 

#while loop for invalid entry 

    while invalid == True: 
     if lotteryarray[0] == "tiger" or lotteryarray[0] == "cow" or lotteryarray[0] == "turtle" or lotteryarray[0] == "bird": 
      invalid == False 
     else: 
      print("Invalid entry!") 
      lotteryarray[0] = input() 
    print(" ") 
    print("You chose " + lotteryarray[0]) 

game == False 

而且這是我在shell得到:

Pick a animal: 
tiger 
cow 
turtle 
bird 

tiger 

老虎還有就是我放,它並沒有被打印。

這裏是flowgorithm,就像我說的,在flowgorithm這個工程。

flowgorithm of lottery game

回答

1

我想通了。

我打印什麼無效後,它是爲了改變爲假,並沒有改變,我改變了兩個等號,並且它的工作和改變了價值。