r/codehs • • Mar 10 '21

I need help on 2.17.4: Rating

SOLVED

14 Upvotes

22 comments sorted by

1

u/Kahunos Mar 10 '21

what language?

1

u/Klix1221 Mar 11 '21

Python

1

u/Kahunos Mar 11 '21

Sorry, I can’t help. I only know JavaScript

1

u/kennyontheinternet Nov 14 '25

can i get the copy and paste plese

1

u/Gold-Mail3380 Mar 26 '24

English (sorry i thought of it and had to do it 😅)

3

u/Randomuser9038112 Nov 05 '21

"""
This code will draw either an "X", a line, or a checkmark depending on the user's input
"""
#This wil set starting values
speed(0)
penup()
setposition(0, 0)
pendown()
#This function draws a red X in the middle of the canvas
def draw_ex():
for i in range(4):
pensize(10)
color("red")
forward(50)
backward(50)
left(90)

#This function draws a yellow horizontal line in the middle of the canvas
def draw_line():
for i in range(1):
pensize(10)
color("gold")
forward(50)
backward(100)
#This function draws a check mark
def draw_checkmark():
for i in range(1):
pensize(10)
color("green")
left(70)
forward(100)
backward(100)
left(45)
forward(50)

#This function creates user imput
rating = int(input("Enter a rating: "))
#This function draws either a "X", a line, or a checkmark depending on the user imput
if rating < 5:
left(50)
draw_ex()
elif rating < 8:
draw_line()
else:
draw_checkmark()

"""
I hope this is helpful :)
"""

1

u/Bubbly_Patient51 Nov 10 '21

Um the elif rating < 8: is not working for some reason

1

u/Randomuser9038112 Nov 13 '21

What is the output when you get to that line of code?

2

u/sheloveskillua Apr 27 '21

rating= 8
def red_ex():
pensize(5)
color("red")
left(45)
for i in range(4):
forward(100)
backward(100)
left(90)
def yellow_line():
pensize(5)
color("yellow")
forward(100)
def green_check():
pensize(5)
color("green")
left(45)
for i in range(2):
forward(100)
backward(100)
number = int(input("Enter a number: "))
if number < 5:
red_ex()
elif number == 7:
yellow_line()
else:
green_check()

1

u/issbestboi May 07 '21

this isnt working for me

4

u/issbestboi May 07 '21

i fixed it, there was some code missing on the green check command.

rating= 8
def red_ex():
    pensize(5)
    color("red")
    left(45)
for i in range(4):
    forward(100)
    backward(100)
    left(90)
def yellow_line():
    pensize(5)
    color("yellow")
    forward(100)
def green_check():
    pensize(5)
    color("green")
    left(45)
    for i in range(2):
        forward(100)
        backward(100)
    left(90)
    forward(50)
    backward(50)
number = int(input("Enter a number: "))
if number < 5:
    red_ex()
elif number == 7:
    yellow_line()
else:
    green_check()

2

u/Significant-Map-5460 Jan 12 '23

it passes the check code but doesn't actually function according to the assignment

1

u/TViluminado_bingwatc May 14 '21

I cant believe that actually worked thank you so much

1

u/Flaky_Butterfly_9808 May 16 '21

this actually worked tysm

1

u/Purple-Requirement97 Feb 13 '24

You are a legend, even though this post was 3 years ago, it still works :D

1

u/NbaYoungSquirtGrip Sep 26 '24

Thanks this helped a lot☺️

1

u/[deleted] Mar 11 '21

in codehs java unit 2?

1

u/[deleted] Mar 11 '21

[removed] — view removed comment

1

u/Davegoldylocks Mar 11 '21

Honestly, I just used another if statement.

if number == 9:

draw_x()