r/codehs • u/gwenkm323 • Sep 23 '23
Whats wrong with my loop?



My coding assignment says:
Ask the user if they want toppings: veg, meat or none. Output a drawing of the appropriate order. Display meat as red and veg as green circles on the pizza. None will just look like a plain pizza with slices.
Use a while loop to continue to ask the user if they want another pizza. When they finally say, "no", they say, " good bye".
The first part of my code works, but when I ask the user if they would like another pizza I can't get the positioning correct and it draws misplaced circle and lines even though the function itself is fine. I tried setposition in the loop rather than the function, and I'm still getting the same result. Any advice? My teacher assigned this today and its due tonight.
View all comments
Show parent comment
1
u/gwenkm323 Sep 23 '23
Sorry I know its long lmao
speed(10)
penup()
setposition(0,-100)
speed(0)
pendown()
radius = 100
def pizza():
for i in range(1):
begin_fill()
circle(radius)
color("yellow")
end_fill()
pensize(5)
color("red")
circle(radius)
left(90)
forward(200)
penup()
setposition(0,0)
pendown()
left(60)
forward(100)
backward(200)
penup()
setposition(0,0)
pendown()
left(60)
forward(100)
backward(200)
def pepperoni():
for i in range(12):
speed(0)
penup()
setposition(0,0)
forward(80)
pendown()
begin_fill()
circle(10)
end_fill()
penup()
backward(80)
color("red")
penup()
forward(80)
pendown()
begin_fill()
circle(10)
end_fill()
penup()
backward(80)
penup()
left(15)
penup()
forward(80)
pendown()
begin_fill()
circle(10)
end_fill()
penup()
backward(80)
left(15)
def veggie():
for i in range(12):
speed(0)
penup()
setposition(0,0)
forward(80)
pendown()
begin_fill()
circle(10)
end_fill()
penup()
backward(80)
color("green")
penup()
forward(80)
pendown()
begin_fill()
circle(10)
end_fill()
penup()
backward(80)
penup()
left(15)
penup()
forward(80)
pendown()
begin_fill()
circle(10)
end_fill()
penup()
backward(80)
left(15)
user_input = input("Would you like a pizza? (yes/no): ")
while user_input == "yes":
if user_input == "yes":
clear()
penup()
setposition(0,-100)
pendown()
pizza()
user_toppings = input("Would you like toppings? (yes/no): ")
if user_toppings == "yes":
user_toppings = input("What toppings would you like? (veggie/meat): ")
if user_toppings == "meat":
pepperoni()
elif user_toppings == "veggie":
veggie()
if user_toppings != "yes":
user_input = input("Would you like another pizza? (yes/no): ")
while user_input == "no":
if user_input == "no":
print("goodbye")
break