我正在进行一项任务,我需要在地图上的点之间画一条线。我使用if语句构建它,但这限制了我可以做多少次,所以想要使用循环。
我到目前为止的代码如下所示,我可以添加城市并绘制一条线,但它会为自己绘制一条线而不是从起点到下一点(并继续)
任何人都可以帮忙吗?
def level1():
cityXvalue = [45,95,182,207,256,312,328,350,374,400]
cityYvalue = [310,147,84,201,337,375,434,348,335,265]
# Display the map image
map = makePicture(getMediaPath("map.png"))
show(map)
number = 0
# Ask user to enter numbers of the cities they wish to visit
cities = requestInteger("Enter the number of the city you would like to visit")
# Draw a line between previously entered point and current one
while cities > number:
city = requestInteger("Please choose a city number")
addLine(map,cityXvalue[city],cityYvalue[city], cityXvalue[city], cityYvalue[city])
repaint(map)