python - Adding numbers to variables within an if statement -
i working on program choose random winner depending on number given. have completed program, having trouble finding solution 1 particular thing.
here code:
player1luck = 0 player1luck = player1luck / 2 player1luck = player1luck + 15 if player1luck > 50: player1luck = player1luck + 30 probabilities.extend([player1] * int(player1luck)) print(player1luck) print(player1 + " number is:", str(player1num) + "! have percentage win of: ", str(player1luck) + "%!") else: probabilities.extend([player1] * int(player1luck)) print(player1 + " number is:", str(player1num) + "! have percentage win of: ", str(player1luck) + "%!")
so, first part (before if statement) fine, numbers adding etc perfectly. it's when inside of if statement numbers adding wrongly. example said add 30 player1luck variable if above 50, instead number drastically low used before decided implement feature. here code looked before changed variable names , such try , fix problem.
newnum = player2num / 2 newnumadded = newnum + 10 if newnumadded > 50: bonusnum = newnumadded + 50 print(player2 + " number is:", str(player2num) + "! have percentage win of: ", str(bonusnum) + "%!") probabilities.extend([player2] * int(bonusnum)) else: print(player2 + " number is:", str(player2num) + "! have percentage win of: ", str(newnumadded) + "%!") probabilities.extend([player2] * int(newnumadded))
i aware problem lie in mistyped code have looked through thoroughly , struggling quite badly, quite new python structuring code may quite insufficient myself.
Comments
Post a Comment