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.16.4 Happy Face CodeHS Answers

The most common answer is:

happy = input (“Are you happy?:”)
if happy == (“Yes, yes”):
smileylove()
speed(0)
def smileylove():
penup()
setposition (0,-100)
pendown()
color(“yellow”)
begin_fill()
circle(100)
end_fill()
color(“black”)
penup()
pensize(1)
setposition(-25,25)
for i in range (2):
begin_fill()
circle(5)
end_fill()
penup()
forward(50)
pendown()
penup()
setposition (-50,-25)
left(270)
pendown()
circle (50, 180)
penup()
smileylove()

To create a program that draws a smiley face based on user input, we need to adjust the structure of the code for proper execution. The main adjustments include:

  1. Moving the function definition to the beginning, before it’s called.
  2. Ensuring the input() function works correctly for checking if the user is happy.
  3. Correcting the syntax for string literals in input() and color() functions.
  4. Fixing the loop that draws the eyes to ensure both eyes are filled correctly.
  5. Removing the recursive call to smileylove() at the end of its definition to prevent infinite recursion.

Here’s the corrected and optimized version of your code:

import turtle

def smileylove():
    turtle.speed(0)  # Set the drawing speed to the fastest
    turtle.penup()
    turtle.setposition(0, -100)
    turtle.pendown()
    turtle.color("yellow")
    turtle.begin_fill()
    turtle.circle(100)
    turtle.end_fill()
    
    # Draw eyes
    turtle.color("black")
    positions = [(-25, 50), (25, 50)]  # Positions for the eyes
    for position in positions:
        turtle.penup()
        turtle.goto(position)
        turtle.pendown()
        turtle.begin_fill()
        turtle.circle(5)
        turtle.end_fill()
    
    # Draw smile
    turtle.penup()
    turtle.goto(-50, 0)
    turtle.pendown()
    turtle.setheading(-60)  # Orient the turtle to start the smile
    turtle.circle(50, 120)  # Draw the smile

happy = input("Are you happy? (Yes/No): ")
if happy.lower() == "yes":
    smileylove()

turtle.done()

This version asks the user if they are happy, and if the response is “Yes” (case-insensitive), it draws a smiley face. The face is yellow with two black eyes and a smile. The adjustments ensure that the program correctly interprets the user’s input and draws the smiley face accordingly.

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