Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Get quick and reliable solutions to your questions from a community of seasoned experts on our user-friendly platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you should roll two dice (Hint: use the randint function!), and print out their values. If the values on both dice are 1, then it is called snake eyes, and you should break out of the loop. You should also use a variable to keep track of how many rolls it takes to get snake eyes.

Sample Run:

Rolled: 6 5
Rolled: 5 2
Rolled: 3 6
Rolled: 6 2
Rolled: 1 2
Rolled: 5 3
Rolled: 1 4
Rolled: 1 1
It took you 8 rolls to get snake eyes.

I have most of the code but when it prints it say you rolled 0 times every time.
import random

# Enter your code here

num_rolls = 0


import random
# Enter your code here

while True:

roll_one = random.randint(1,6)
roll_two = random.randint(1,6)
print ("Rolled: " +str(roll_one) +"," + str(roll_two))
if (roll_one == 1 and roll_two == 1):
print ("it took you " + str(num_rolls) + " rolls")
break

output:
Rolled: 3,5
Rolled: 6,4
Rolled: 2,4
Rolled: 3,6
Rolled: 5,2
Rolled: 1,1
it took you 0 rolls

suppose to say:
It took you (however many rolls) not 0


Sagot :

import random

num_rolls = 0

while True:

   r1 = random.randint(1, 6)

   r2 = random.randint(1, 6)

   print("Rolled: " + str(r1) + "," + str(r2))

   num_rolls += 1

   if r1 == r2 == 1:

       break

print("It took you "+str(num_rolls)+" rolls")

I added the working code. You don't appear to be adding to num_rolls at all. I wrote my code in python 3.8. I hope this helps.

The program uses loops and conditional statements.

Loops perform repetitive operations, while conditional statements are statements used to make decisions

The program in Python where comments are used to explain each line is as follows:

#This imports the random module

import random

#This initializes the number of rolls to 0

num_rolls = 0

#The following loop is repeated until both rolls are 1

while True:

   #This simulates roll 1

   roll_one = random.randint(1,6)

   #This simulates roll 2

   roll_two = random.randint(1,6)

   #This prints the outcome of each roll

   print ("Rolled: " +str(roll_one) +"," + str(roll_two))

   #This counts the number of rolls

   num_rolls+=1

   #When both rolls are the 1

   if (roll_one == 1 and roll_two == 1):

       #This exits the loop

       break

#This prints the number of rolls

print ("it took you " + str(num_rolls) + " rolls")

Read more about similar programs at:

https://brainly.com/question/14912735