所以這是一個簡單的文字遊戲im開始工作。 當我運行程序時,它會在它完成之前多次遍歷它們。不是每個人都喜歡我想要的一個。但我仍然希望它隨機選擇它們,所以我不確定是否有更好的方法來做到這一點?有人能告訴我我做錯了什麼嗎?文本遊戲if check1 and check2 and check3 statment
import random
from collections import defaultdict
Blist = ["hash browns", "eggs", "cheese", "sausage"]
Dictionary = {"a":1,"b":1,"c":1,"d":1}
Tup = (1,2,3,4,5)
check1 = False
check2 = False
check3 = False
def question():
answer = ((Blist), (Dictionary), (Tup))
new = (random.choice(answer))
print(new)
print("which is this?")
print("a List, Dictionary, or Tuple?")
x = str(input('what is it?\n'))
if check1 == True and check2 == True and check3 == True:
multiL()
else:
if x == 'list' and new == Blist:
global check1
check1 = True
print("that is correct, this is a list")
question()
if x == 'dictionary' and new == Dictionary:
global check2
check2 = True
print("that is correct, this is a dictonary")
question()
if x == 'tuple' and new == Tup:
global check3
check3 = True
print("that is correct, this is a tuple")
question()
if x == 're':
multiL()
else:
print("that is not one of the choices, try again?\n")
question()
def multiL():
print("done")
question()
AttributeError的:「元組」對象有沒有屬性「刪除」我不斷收到此錯誤 – Doppel
和即時通訊是一個白癡即時得到這個想法 – Doppel
這是我的元組不好,我沒有看過你的代碼正確。對於刪除工作,安納斯必須是一個列表。我已經在帖子中編輯了代碼,成爲一個疙瘩。 –