I am writing a game which has a set of rules to determine which card is a top trump however, when i want to say if "R" for example is in the word R1 do something, as i think that is my error, much appreciated help, Thanks. My game has 3 different colours Black Red and yellow which has a hierachy system for example Black Beats yellow but red beats Black and yellow beats red, this hierachy system is used always unless both colours are the same which then uses the higher number which i have not implemented yet.
import random
authorisedPlayers=["Jeffrey","Collin", "Collina","Danny","JephTheDuck","JerryJaye"]
cards = [["R1","R2","R3","R4","R5","R6","R7","R8","R9","R10"],["Y1","Y2","Y3","Y4","Y5","Y6","Y7","Y8","Y9","Y10"],["B1","B2","B3","B4","B5","B6","B7","B8","B9","B10"]]
PlayerOneDeck=[]
PlayerTwoDeck=[]
Player1=input("Enter Player 1: ")
Player2=input("Enter Player 2: ")
if (Player1 and Player2) in authorisedPlayers:
print("Hello " ,Player1,"and",Player2)
for i in range(0,14):
player1Hand=random.choice (cards)
cards.remove(player1Hand)
player2Hand=random.choice (cards)
cards.remove(player2Hand)
if "R" in player1Hand and "B" in player2Hand:
PlayerOneDeck.append(player1Hand)
PlayerOneDeck.append(player2Hand)
elif "R" in player2Hand and "B" in player1Hand:
PlayerTwoDeck.append(player1Hand)
PlayerTwoDeck.append(player2Hand)
elif "Y" in player1Hand and "R" in player2Hand:
PlayerOneDeck.append(player1Hand)
PlayerOneDeck.append(player2Hand)
elif "Y" in player2Hand and "R" in player1Hand:
PlayerTwoDeck.append(player1Hand)
PlayerTwoDeck.append(player2Hand)
elif "B" in player1Hand and "Y" in player2Hand:
PlayerOneDeck.append(player1Hand)
PlayerOneDeck.append(player2Hand)
elif "B" in player2Hand and "Y" in player1Hand:
PlayerTwoDeck.append(player1Hand)
PlayerTwoDeck.append(player2Hand)
lenP1=len(PlayerOneDeck)
lenP2=len(PlayerTwoDeck)
if lenP1>lenP2:
print(Player1," wins with ",lenP1,"cards!!!")
else:
print(Player2, " wins with ",lenP2,"cards!!!")
#NOW MAKE SURE YOU SAY IF B IS IN THE STRING OR A IS WHICHEVER ONE HAS B IS BETTER ETC AND ITERATE 15 TIMES
else:
print("Sorry Not an Authorised User")
My error message is :
Traceback (most recent call last):
File "main.py", line 16, in <module>
player2Hand=random.choice (cards)
File "/usr/lib/python3.8/random.py", line 290, in choice
raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence
Please Help, it is much appreciated, Sorry if my grammar and format is not to your acceptable standard .