-2
if not bingo_num in player_1_num:
print(bingo_num, "is not in", player1,"s list")
if not bingo_num in player_2_num:
print(bingo_num, "is not in", player2,"s list")
我正在製作賓果遊戲,這就是我的代碼的樣子。我曾嘗試查看列表
if not bingo_num in player_1_num:
print(bingo_num, "is not in", player1,"s list")
也
if bingo_num not in player_1_num:
print(bingo_num, "is not in", player1,"s list")
但產量總是說
數摘得54
54約翰的名單被發現!
54不是阿俊的名單
54不是約翰的名單
我想知道我怎麼能解決這個錯誤
我的整個碼。我只是一個初學者所以它可能是混亂和某些部分可能是不必要的
print("BINGO")
print("You must pick 6 numbers each in the range 1-100")
player_1_num = []
player_2_num = []
import random
player1 = input("Player 1 enter your name")
player2 = input("Player 2 enter your name")
print()
print("Time for ", player1, "to enter their numbers")
p1_num1 = int(input("Enter your first number"))
p1_num2 = int(input("Enter your second number"))
p1_num3 = int(input("Enter your third number"))
p1_num4 = int(input("Enter your fourth number"))
p1_num5 = int(input("Enter your fifth number"))
p1_num6 = int(input("Enter your sixth number"))
print()
print("Time for ", player2, "to enter their numbers")
p2_num1 = int(input("Enter your first number"))
p2_num2 = int(input("Enter your second number"))
p2_num3 = int(input("Enter your third number"))
p2_num4 = int(input("Enter your fourth number"))
p2_num5 = int(input("Enter your fifth number"))
p2_num6 = int(input("Enter your sixth number"))
player_1_num.append(p1_num1)
player_1_num.append(p1_num2)
player_1_num.append(p1_num3)
player_1_num.append(p1_num4)
player_1_num.append(p1_num5)
player_1_num.append(p1_num6)
player_2_num.append(p2_num1)
player_2_num.append(p2_num2)
player_2_num.append(p2_num3)
player_2_num.append(p2_num4)
player_2_num.append(p2_num5)
player_2_num.append(p2_num6)
print()
print()
print(player1, "your numbers are", player_1_num)
print(player2, "your numbers are", player_2_num)
while len(player_1_num) > 0 or len(player_2_num) > 0:
print()
input("Press enter to roll a number")
bingo_num = random.randint(1,100)
print("The number picked was ",bingo_num)
if bingo_num in player_1_num:
print(bingo_num, "was found in", player1,"s list!")
player_1_num.remove(bingo_num)
if bingo_num in player_2_num:
player_2_num.remove(bingo_num)
print(bingo_num, "was found in", player2,"s list!")
if not bingo_num in player_1_num:
print(bingo_num, "is not in", player1,"s list")
if not bingo_num in player_2_num:
print(bingo_num, "is not in", player2,"s list")
if len(player_1_num) == 0:
print(player1.upper()," HAS WON THE GAME")
break
if len(player_2_num) == 0:
print(player2.upper()," HAS WON THE GAME")
break
print(player1, "your numbers are", player_1_num)
print(player2, "your numbers are", player_2_num)
input("Press enter to exit")
粘貼所有的代碼和你的輸入 – zhangxaochen
你需要給我們的樣本數據了。很可能你在混合字符串和整數值。 –
你如何設置賓果數值? –