4.11.4 Snake Eyes CodeHS Answers

We thoroughly check each answer to a question to provide you with the most correct answers. Found a mistake? Tell us about it through the REPORT button at the bottom of the page. Ctrl+F (Cmd+F) will help you a lot when searching through such a large set of questions.

The most common answer for the 4.11.4 Snake Eyes CodeHS is:

import random
# Enter your code here
num_rolls = 0
while True:
num_rolls += 1
dice_one = random.randint(1, 6)
dice_two = random.randint(1, 6)
print("Rolled: " + str(dice_one) + " " + str(dice_two))

if (dice_one == 1 and dice_two == 1):
print("It took you " + str(num_rolls) + " rolls to get snake eyes.")
break

It correctly implements a loop to roll two dice until both dice show a 1, which is referred to as “snake eyes” in dice games. Here’s your code with proper indentation for clarity:

import random

num_rolls = 0
while True:
    num_rolls += 1
    dice_one = random.randint(1, 6)
    dice_two = random.randint(1, 6)
    print("Rolled: " + str(dice_one) + " " + str(dice_two))

    if dice_one == 1 and dice_two == 1:
        print("It took you " + str(num_rolls) + " rolls to get snake eyes.")
        break

This code will continuously roll two six-sided dice (using random.randint(1, 6)) until both dice come up as 1. The number of rolls it takes to achieve this outcome is tracked by the num_rolls variable, which is incremented with each roll. When snake eyes are rolled, the program prints how many rolls it took and then exits the loop with break.

Just run this code in a Python environment to see how it works. The number of rolls it takes to get snake eyes can vary greatly due to the randomness.

Was this helpful?

quizzma
Quizzma Team
+ posts

The Quizzma Team is a collective of experienced educators, subject matter experts, and content developers dedicated to providing accurate and high-quality educational resources. With a diverse range of expertise across various subjects, the team collaboratively reviews, creates, and publishes content to aid in learning and self-assessment.
Each piece of content undergoes a rigorous review process to ensure accuracy, relevance, and clarity. The Quizzma Team is committed to fostering a conducive learning environment for individuals and continually strives to provide reliable and valuable educational resources on a wide array of topics. Through collaborative effort and a shared passion for education, the Quizzma Team aims to contribute positively to the broader learning community.




Leave a Comment

Your email address will not be published. Required fields are marked *