I am doing some practice on graph data structures using a small railway network. In the beginning, I ask for a starting destination and an end destination from the user. The user inputs must be a value from a list of destinations. What I've written so far:
a = 0
b = 0
while a == 0:
start_point = input("\nWhat is your starting location?\n").title()
if start_point in valid_destinations:
print("That is a valid starting location.")
a = 1
else:
print("Please choose one of the cities in our network.")
continue
while b == 0:
end_point = input("\nWhat is your destination\n").title()
if end_point in valid_destinations:
print("That is a valid destination.")
b = 1
else:
print("Please choose one of the cities in our network.")
continue
Because they are separate questions, does that mean there must be separate while loops? I tried doing them both within one but I couldn't get the validation function to work properly. It functions as written above but I feel it could be more efficient with less repetition.