我正在做一项任务,我需要在地图上的点之间画一条线。我使用 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)