(sorry if this is a dumb question, I'm still learning)
I'm making a program that, for part of the prog, rolls four dice and subtracts the lowest dice from the outcome. The code I'm using is
die1 = random.randrange(6) + 1
die2 = random.randrange(6) + 1
die3 = random.randrange(6) + 1
die4 = random.randrange(6) + 1
if die1 <= die2 and die1 <= die3 and die1 <= die4:
drop = die1
elif die2 <= die1 and die2 <= die3 and die2 <= die4:
drop = die2
elif die3 <= die1 and die3 <= die2 and die3 <= die4:
drop = die3
else:
drop = die4
cha = die1 + die2 + die3 + die4 - drop
Thats the best I could come up with from my so-far limited coding ability. Is there a better way to make it organize the four dice in order of size, then add together the three highest while ignoring the leftover? Or is the code I'm using the best way to do it?