1

I'm working on an assignment and i keep running into trouble with the while loops. The below draws a line from the first number on an image then to the next number entered. it loops this too, but its asks for the first and second number each time instead of going to the ext and to the next etc.

Can anyone give me any help with this?

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) 
galen
  • 11
  • 1

1 Answers1

0

I figured it out, this is the code...

 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)
galen
  • 11
  • 1