首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JES while循环

JES while循环
EN

Stack Overflow用户
提问于 2015-11-20 19:00:40
回答 1查看 367关注 0票数 1

我正在做一项任务,但我总是遇到while循环的麻烦。下面从图像上的第一个数字到输入的下一个数字绘制一条线。它也这样循环,但它每次都要求第一个和第二个数字,而不是转到ext和下一个,依此类推。

有人能在这方面给我一些帮助吗?

代码语言:javascript
复制
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("C:/Users/glarm/OneDrive/Documents/RMIT/Introduction to programming/Assignments/Assingment 2/map.png")
    show(map)
    numCities=requestInteger("Enter the number of cities you wish to visit:")
    counter=0
    # Draw a line between previously entered point and current one
    while numCities > 0:
     currentCity = requestInteger("Enter the city you would like to visit")
     previousCity = requestInteger("Enter the city you would like to visit next")
     #currently asking for first city then the next but you need to enter the previous city before the next... 
     startX = currentCity
     startY = currentCity
     endX = previousCity 
     endY = previousCity 
     addLine(map, cityXvalue[startX], cityYvalue[startY], cityXvalue[endX], cityYvalue[endY])
     counter=counter+1  
     repaint(map) 
EN

回答 1

Stack Overflow用户

发布于 2015-11-21 21:26:48

我想通了,这就是代码...

代码语言:javascript
复制
 def maplevel1():
    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("C:/Users/glarm/OneDrive/Documents/RMIT/Introduction to programming/Assignments/Assingment 2/map.png")
    show(map)
    numCities=requestInteger("Enter the number of cities you wish to visit:")
    counter=0
    # Draw a line between previously entered point and current one
    while numCities > 0:
     startCity = requestInteger("Enter the city you would like to visit")
     nextCity = requestInteger("Enter the city you would like to visit next")

     startX = startCity
     startY = startCity
     endX = nextCity 
     endY = nextCity 
     addLine(map, cityXvalue[startX], cityYvalue[startY], cityXvalue[endX], cityYvalue[endY])
     counter=counter+1
     repaint(map)

     while counter>0:
      startCity=nextCity
      nextCity=requestInteger("Enter the city you would like to visit next")
      startX = startCity
      startY = startCity
      endX = nextCity 
      endY = nextCity 
      addLine(map, cityXvalue[startX], cityYvalue[startY], cityXvalue[endX], cityYvalue[endY])
      repaint(map)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33825028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档