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:
- The
checkmark()
function definition has extra and misplaced parentheses. - The
secret_number = 1)
line has an extra parenthesis. - The
color("lime")
,right(45)
,forward(25)
,left(90)
, andforward(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. - The
speed(0)
andpensize(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:
- Ask the user to guess a number between 1 and 10.
- Keep asking the user to guess again if they don’t guess the secret number (which is set to 1).
- Print a congratulatory message and draw a lime checkmark when the user guesses the secret number correctly.
- Use turtle graphics commands to draw the checkmark.
Leave a comment