[英]I created a guessing game and I can't understand why my -= command function doesn't work
[英]My guessing game is not working as my expectation: my if else statement doesn't work
secret_element = "Oxygen"
guess = ""
amount = 3
element = {
"A" : "Nitrogen",
"B" : "Krypton",
"C" : "Xenon",
"D" : "Helium",
"E" : "fluorine",
"F" : "Lithium",
"G" : "Oxygen"
}
b = 0
while b < 3:
print("Insert alphabet A, B, C, D, E, F or G to find the element")
guess = str(input("All you need is luck\n"))
if guess != secret_element:
b += 1
amount -= 1
print(amount, "attempt left\neLPOZO")
else:
print("Congrats,you got the right one!" ,secret_element,"!")
它是:
secret_element = "Oxygen"
guess = ""
amount = 3
element = {
"A" : "Nitrogen",
"B" : "Krypton",
"C" : "Xenon",
"D" : "Helium",
"E" : "fluorine",
"F" : "Lithium",
"G" : "Oxygen"
}
b = 0
while b < 3:
print("Insert alphabet A, B, C, D, E, F or G to find the element")
guess = str(input("All you need is luck\n"))
if element[guess] != secret_element:
b += 1
amount -= 1
print(amount, "attempt left\neLPOZO")
else:
print("Congrats,you got the right one!" ,secret_element,"!")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.