Continue prompting user input until 0 is key in

i’m having problem with my code. Not sure how to fix it. My program repeatedly prompts for the supermarket aisle numbers to visit. When 0 is entered, the input process will terminate. Then the program computes the minimum distance based on the best location to place the shopping basket and the number of aisles I need to pick items from. The program then displays the minimum distance. The following are my code:

totalAisles = int(input("Enter the number of aisles in supermarket: "))
visitAisle = int(input("Enter the aisle number to visit: "))
if visitAisle == 0:
    print("Not visiting any aisle")
else:
    aisle = []
    while True:
        visitAisle = int(input("Enter the aisle number to visit: "))
        if visitAisle == 0:
            break
        else:
            for i in range(totalAisles):
                visitAisle = int(input("Enter the aisle number to visit: "))
                aisle.append(visitAisle)
                #to find the best aisle to place the basket 
                highestAisle = max(aisle)
                lowestAisle = min(aisle)
                basket = round(highestAisle + lowestAisle) / 2
                minimumDistance += abs(basket - visitAisle) * 2
            print(f"The minimum distance is {minimumDistance} units")

Example runs

Run 1 Enter number of aisles in supermarket: 100

Enter the aisle number to visit: 1

Enter the aisle number to visit: 8

Enter the aisle number to visit: 5

Enter the aisle number to visit: 4

Enter the aisle number to visit: 10

Enter the aisle number to visit: 0

The minimum distance is 26 units

Run 2

Enter number of aisles in supermarket: 100

Enter the aisle number to visit: 1

Enter the aisle number to visit: 0

The minimum distance is 0 units

Run 3

Enter number of aisles in supermarket: 100

Enter the aisle number to visit: 0

Not visiting any aisle

Answer

UPDATED Here is a more streamlined way of doing it. I also made sure the user doesn’t enter duplicate aisle numbers and not more aisles than there are in the store. Most importantly, the computation step is much simplified.

totalAisles = int(input("Enter the number of aisles in supermarket: "))
aisle = []
visitAisle = None

while len(aisle) < totalAisles:
    visitAisle = int(input("Enter the aisle number to visit: "))
    if visitAisle == 0:
        if aisle:
            break
        else:
            print("Not visiting any aisle")
            break
    if visitAisle not in aisle and visitAisle != 0:
        aisle.append(visitAisle)
    else:
        print("You already entered that aisle number. Pick another one.")

#to find the best aisle to place the basket
if aisle:
    highestAisle = max(aisle)
    lowestAisle = min(aisle)
    basket = (highestAisle + lowestAisle) //2

    #traveling back and forth from the basket to each isle
    minimumDistance = 0
    for visitAisle in aisle:
        minimumDistance += abs(basket - visitAisle) * 2
    print(f"nThe minimum distance is {minimumDistance} units if you park the cart at aisle {basket}")