Dice Roll Game ( Python ) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Dice Roll Game ( Python )

Hey can somebody help me with this code I really dont understand #PLAYER 1 #This game involves 2 players rolling a single die until they get to a total of 100. #The player who gets to 100 with fewer rolls wins. #For this assignment you will need one while loop for each player. #The while loop will add a single dice roll to the total score until the total score reaches 100. #Each player will have a total score variable and a count variable. #Every time you add a dice roll to the total, add 1 to the count variable. #PLAYER1 import random dice1 = random.randint ( 0, 10 ) player1 = random.randint ( 0, 10) c1 = 0 sum1 = 0 print("Number for player1: " + str( player1)) #PLAYER 2 dice2 = random.randint ( 0,10) player2 = random.randint ( 0,10) c2 = 0 sum2 = 0 print("Number for player2: " + str( player2)) #PLAYER 1 while ( player1 != 10): sum1 = sum1 + dice1 c1 = c1 + 1 player1 = random.randint ( 0, 10) print("You rolled: " + str(c1) + " time(s) the dice player1") #PLAYER 2 while ( player2 != 10): sum2 = sum2 + dice2 c2 = c2 + 1 player2 = random.randint ( 0 ,10) print ("You rolled: " + str(c2) + " time(s) the dice player2") #FINAL winner = min (player1, player2) print (" The winner is: " + str( winner)) That is the code that I did but it is wrong and I dont know what to do next

4th Dec 2019, 2:01 AM
PaolaPiacentini21
PaolaPiacentini21 - avatar
1 Answer
+ 1
your code makes too much unnecessary steps. simply do something like this for player 1 import random p1dice = 0 p1roll = 0 while p1dice < 100: p1dice += random.randint(1, 6) p1roll += 1
4th Dec 2019, 2:02 PM
Shen Bapiro
Shen Bapiro - avatar