Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python JES while循环_Python_Loops_While Loop_Jes - Fatal编程技术网

Python JES while循环

Python JES while循环,python,loops,while-loop,jes,Python,Loops,While Loop,Jes,我正在做一项作业,但我总是遇到while循环的麻烦。下面画了一条线,从图像上的第一个数字到输入的下一个数字。它也循环这个,但每次都要求输入第一个和第二个数字,而不是下一个和下一个等等 有人能帮我吗 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

我正在做一项作业,但我总是遇到while循环的麻烦。下面画了一条线,从图像上的第一个数字到输入的下一个数字。它也循环这个,但每次都要求输入第一个和第二个数字,而不是下一个和下一个等等

有人能帮我吗

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) 

我想出来了,这是密码

 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)

我想出来了,这是密码

 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)