I created a dice rolling game where the outcome shows the highest sum of rolls per player. As you can see from the if/elif statements, it's not very eloquent. I do not want someone to rewrite those statements into something more efficient. I would like to know if there is a better way of writing it and what that suggestion would be?
import random
total_rolls = []
total_rolls_for = 0
player_one = []
player_two = []
player_three = []
player_four = []
max_total = []
max_total_for = []
while len(player_one) < 5:
player_one.append(random.randint(1,12))
if len(player_one) == 5:
print("Player one rolled:", player_one)
while len(player_two) < 5:
player_two.append(random.randint(1,12))
if len(player_two) == 5:
print("Player two rolled:", player_two)
while len(player_three) < 5:
player_three.append(random.randint(1,12))
if len(player_three) == 5:
print("Player three rolled:", player_three)
while len(player_four) < 5:
player_four.append(random.randint(1,12))
if len(player_four) == 5:
print("Player four rolled:", player_four)
print("The sum of p1 is:", sum(player_one))
print("The sum of p2 is:", sum(player_two))
print("The sum of p3 is:", sum(player_three))
print("The sum of p4 is:", sum(player_four))
if sum(player_one) > sum(player_two) and sum(player_one) > sum(player_three) and sum(player_one) > sum(player_four):
print("aPlayer one has a higher score with:",sum(player_one))
elif sum(player_two) > sum(player_one) and sum(player_two) > sum(player_three) and sum(player_two) > sum(player_four):
print("aPlayer two has a higher score with:",sum(player_two))
elif sum(player_three) > sum(player_one) and sum(player_three) > sum(player_two) and sum(player_three) > sum(player_four):
print("aPlayer three has a higher score with:",sum(player_three))
elif sum(player_four) > sum(player_one) and sum(player_four) > sum(player_two) and sum(player_four) > sum(player_three):
print("aPlayer four has a higher score with:",sum(player_four))
elif sum(player_one) == sum(player_two) and sum(player_one) > sum(player_three) and sum(player_one) > sum(player_four):
print("Player one and two has a higher score with:",sum(player_one))
elif sum(player_two) == sum(player_one) and sum(player_two) > sum(player_three) and sum(player_two) > sum(player_four):
print("Player two and player one has a higher score with:",sum(player_two))
elif sum(player_three) == sum(player_one) and sum(player_three) > sum(player_two) and sum(player_three) > sum(player_four):
print("Player three and player one has a higher score with:",sum(player_three))
elif sum(player_four) == sum(player_one) and sum(player_four) > sum(player_two) and sum(player_four) > sum(player_three):
print("Player four and player one has a higher score with:",sum(player_four))
elif sum(player_two) == sum(player_three) and sum(player_two) > sum(player_one) and sum(player_two) > sum(player_four):
print("Player two and three has a higher score with:",sum(player_two))
elif sum(player_two) == sum(player_four) and sum(player_two) > sum(player_three) and sum(player_two) > sum(player_one):
print("Player two and player four has a higher score with:",sum(player_two))
elif sum(player_three) == sum(player_four) and sum(player_three) > sum(player_two) and sum(player_three) > sum(player_one):
print("Player three and player four has a higher score with:",sum(player_three))
elif sum(player_four) == sum(player_one) == sum(player_two) and sum(player_four) > sum(player_three):
print("Player four and player one and player two has a higher score with:",sum(player_four))
elif sum(player_three) == sum(player_one) == sum(player_two) and sum(player_one) > sum(player_four):
print("Player three and player one and player two has a higher score with:",sum(player_one))
elif sum(player_four) == sum(player_three) == sum(player_two) and sum(player_four) > sum(player_one):
print("Player four and player three and player two has a higher score with:",sum(player_four))
elif sum(player_one) == sum(player_three) == sum(player_four) and sum(player_four) > sum(player_two):
print("Player one and player three and player four has a higher score with:",sum(player_four))
elif sum(player_one) == sum(player_four) == sum(player_three) == sum(player_two):
print("all players have the same value:", sum(player_one))