Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Quizzma Latest Articles

2.18.5 Guess A Number CodeHS Answers

The most common answer is:

speed(0)
pensize(10)
Draws a lime checkmark
def checkmark():)
color(“lime”)
right(45)
forward(25)
left(90))
forward(75)
)
Defines the user number and secret number
user_number = int(input(“Guess a number from (1-10):”))
secret_number = 1)
while user_number != secret_number:
user_number = int(input(“Guess a number from (1-10):”))
if user_number == secret_number:
print(“You win!!!!!! Yay!!!”)
checkmark()

However, this code has a few syntax errors and misplaced parentheses.

Let’s correct these issues and ensure the code works properly:

  1. The checkmark() function definition has extra and misplaced parentheses.
  2. The secret_number = 1) line has an extra parenthesis.
  3. The color("lime"), right(45), forward(25), left(90), and forward(75) commands suggest you are using a turtle graphics-like environment, so make sure to import the turtle module and set up turtle graphics commands correctly.
  4. The speed(0) and pensize(10) commands are set outside of any function, which might cause an error if the turtle graphics environment isn’t properly initialized before they are called.

Here’s the corrected version of the program:

import turtle

# Set up turtle graphics
turtle.speed(0)
turtle.pensize(10)

# Function to draw a lime checkmark
def checkmark():
    turtle.color("lime")
    turtle.right(45)
    turtle.forward(25)
    turtle.left(90)
    turtle.forward(50)  # Adjusted for a better checkmark appearance
    turtle.hideturtle()  # Hide the turtle after drawing

# Main game loop
secret_number = 1
user_number = int(input("Guess a number from (1-10): "))
while user_number != secret_number:
    user_number = int(input("Wrong guess. Try again: "))
    
if user_number == secret_number:
    print("You win!!!!!! Yay!!!")
    checkmark()

turtle.done()  # Keeps the window open until you close it manually

This program will:

  1. Ask the user to guess a number between 1 and 10.
  2. Keep asking the user to guess again if they don’t guess the secret number (which is set to 1).
  3. Print a congratulatory message and draw a lime checkmark when the user guesses the secret number correctly.
  4. Use turtle graphics commands to draw the checkmark.

Was this helpful?




Quizzma Team

Quizzma Team

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.

Related Posts