My code is for a 10-faced dice-rolling game. There are 2 players who start off with 50 points, then they both roll a dice and get a random score between 1-10. The player with the highest roll gets the difference between the rolls deducted from their score (50 points), but the loser gets the difference between the rolls added to their score. To win the game you must reach the score 0, or below.
#Imported to help flow, and random to simulate dice rolls
print("Welcome to the dice rolling game.")
#Printed to make it more friendly to the user :)
time.sleep(1)
playernames=[]
#Add player's names to a list
playernames.append(input("\nWhat is player 1's name?"))#.append is used to add multiple names to list
playernames.append(input("\nWhat is player 2's name?"))
time.sleep(1)
#Prints players names from the list
print("\nPlayer 1:",playernames[0])
print("Player 2:",playernames[1])
input("\nPress enter to begin: ")
dicelist=[0,0]
dicelist[0]=random.randint(1,10)
dicelist[1]=random.randint(1,10)
for i in range(0,2):
print(playernames[i],"rolls a",dicelist[i])
diceDifference=abs(dicelist[0]-dicelist[1])
score0=20
score1=20
while True:
if dicelist[0]>dicelist[1]:
print("\nPlayer 1 wins")
time.sleep(1)
print("\nPlayer 2 loses",diceDifference,"points")
print("Player 2 gains",diceDifference,"points")
print("player 1:",score0-diceDifference)
print("player 2:",score1+diceDifference)
score0==0
exit
elif dicelist[1]>dicelist[2]:
print("\nPlayer 2 wins")
time.sleep(1)
print("\nPlayer 2 loses",diceDifference,"points")
print("\nPlayer 1 gains",diceDifference,"points")
print("player 1:",score0+diceDifference)
print("player 2:",score1-diceDifference)
score1==0
exit
else:
print("It's a draw")
time.sleep(1)
print("No change in score")
print("The score is: ","\nPlayer 1:",score0,"\nPlayer 2:",score1)
time.sleep(1)