python - How to move the turtle where I want to go -


so i'm trying complete question on programming course, , involves drawing stuff turtle. basically, i'm trying draw city skyline, program needs read multiple inputs user on 1 line (the heights of buildings). can draw building, uses last y-value.

from turtle import * h = input("heights: ") y = h.split() nxc = -200  #code background  fillcolor("darkslategray") in y:   in y:     nyc =   pencolor("black")   pendown()   begin_fill()   goto(nxc, nyc)   right(90)   forward(20)   right(90)   forward(nyc)   right(90)   forward(20)   right(90)   forward(nyc)   end_fill()   nxc = nxc + 20 

help please!

here's picture: description of question some of specifics

take out second for loop:

from turtle import * h = input("heights: ") y = h.split() nxc = -200  #code background  fillcolor("darkslategray") in y:   nyc =   pencolor("black")   pendown()   begin_fill()   goto(nxc, nyc)   right(90)   forward(20)   right(90)   forward(nyc)   right(90)   forward(20)   right(90)   forward(nyc)   end_fill()   nxc = nxc + 20 

this second loop reach end, updating nyc each time, before exits. thus, every iteration, nyc advance final value before python gets drawing code.


Comments