I am working on a program that will choose a random winner depending on the number they are given. I have completed this program, however I am having trouble finding a solution to one particular thing.
Here is my code:
player1Luck = 0
player1Luck = player1Luck / 2
player1Luck = player1Luck + 15
if player1Luck > 50:
player1Luck = player1Luck + 30
probabilities.extend([player1] * int(player1Luck))
print(player1Luck)
print(player1 + " Your number is:", str(player1num) + "! You have a percentage to win of: ", str(player1Luck) + "%!")
else:
probabilities.extend([player1] * int(player1Luck))
print(player1 + " Your number is:", str(player1num) + "! You have a percentage to win of: ", str(player1Luck) + "%!")
So, the first part (before the if statement) is completely fine, numbers are adding up etc perfectly. It's only when inside of the if statement that numbers are adding up wrongly. For example I said to add an extra 30 to the player1Luck variable if it is above 50, instead the number is drastically low to what it used to be before I decided to implement this feature. Here is what my code looked like before I changed the variable names and such to try and fix this problem.
newnum = player2num / 2
newnumadded = newnum + 10
if newnumadded > 50:
bonusnum = newnumadded + 50
print(player2 + " Your number is:", str(player2num) + "! You have a percentage to win of: ", str(bonusnum) + "%!")
probabilities.extend([player2] * int(bonusnum))
else:
print(player2 + " Your number is:", str(player2num) + "! You have a percentage to win of: ", str(newnumadded) + "%!")
probabilities.extend([player2] * int(newnumadded))
I am aware the problem could lie in some mistyped code but I have looked through it thoroughly and am struggling quite badly, I am also quite new to Python so structuring code may be quite insufficient from myself.
Aucun commentaire:
Enregistrer un commentaire