In the below program the result of the if statement near the end is occasionally wrong but I cannot see a pattern in it. I have debugged it as much as possible but I cannot find my error. I'm sorry for the large amount of code but I don't know where the error is in that code all I know is that it is somewhere in the code below.
Help would be much appreciated!
I am not hugely experienced in python so please explain any answers in detail
for i in range(1,10):
import random
Cards = list(range(0,8))
print("shuffling...")
random.shuffle(Cards)
#print(Cards)
PlayerCards = []
ComputerCards = []
CardsLen = int(len(Cards)) / 2
for i in range(int(CardsLen)):
PlayerCards.append(Cards[0])
del Cards[0]
ComputerCards.append(Cards[0])
del Cards[0]
#print(PlayerCards)
#print(ComputerCards)
Ab5s = ['9', '12', '1', '10', '5', '6', '6', '8']
#print(Ab5s)
Ab5sS = sorted(Ab5s, key = int)
#print(Ab5sS)
AbNames = ['Magic', 'Cunning', 'Courage', 'Wisdom', 'Temper']
#print(AbNames)
Ab5Name = AbNames[4]
AbNamesDict = {5: Ab5s}
PlayerCardNum = PlayerCards[0]
ComputerCardNum = ComputerCards[0]
PlayerCardAb5 = Ab5s[PlayerCardNum]
ComputerCardAb5 = Ab5s[ComputerCardNum]
PlayerAbVal = Ab5s[PlayerCardNum]
ComputerAbVal = Ab5s[ComputerCardNum]
#print(PlayerAbVal)
#print(ComputerAbVal)
while True:
try:
PlayerAbUse = "Temper" #input("Which ability do you want to use ")
PlayerAbUse = PlayerAbUse.title()
PlayerAbNum = (AbNames.index(PlayerAbUse) + 1)
break
except ValueError:
print("error")
continue
AbList = AbNamesDict[PlayerAbNum]
PlayerAbVal = (AbList)[PlayerCardNum]
ComputerAbVal = (AbList)[ComputerCardNum]
#print(PlayerAbVal)
#print(ComputerAbVal)
print("Player has " + PlayerCardAb5 + " " + Ab5Name)
print("Computer has " + ComputerAbVal + " " + Ab5Name)
WonCards = []
#This is where I believe it is going wrong
if PlayerAbVal < ComputerAbVal:
Winner = 0
else:
if PlayerAbVal == ComputerAbVal:
Winner = 2
else:
Winner = 1
WonCards.append(PlayerCards.pop(0))
WonCards.append(ComputerCards.pop(0))
if Winner == 0:
print("Computer Win ")
while len(WonCards) > 0:
ComputerCards.append(WonCards.pop(0))
print("")
else:
if Winner == 1:
print("Player Win ")
while len(WonCards) > 0:
PlayerCards.append(WonCards.pop(0))
print("")
else:
print("Draw ")
Winner = random.randint(1,2)