-1
print_list=input("Do you wish to print list \n:")

if print_list == "yes":
    for item in List:
        print (item , "%2.f" %(Speed),"m/s")

elif print_list == "no":
    print ("Thank you")

if print_list != "yes" or "no":
    while True:
        print ("Invalid Input")
        break

this is what happened:

Do you wish to print list 
:hhh
Invalid Input
Press "Enter Key" when the vehicle passes Sensor 1 
:

What I was hoping was for the program to ask the question "Do you wish to print list", when the user input is invalid.

Rafał Rawicki
  • 22,324
  • 5
  • 59
  • 79
HELP
  • 1
  • 3

2 Answers2

2

If you want the first statement to happen again then it has to be inside the loop. Basically all of this needs to be inside the while loop. And the break will cause the loop to end, so definitely don't put it after invalid input since you want the user to be asked again.

Alex Hall
  • 34,833
  • 5
  • 57
  • 89
0
while True:
    print_list=input("Do you wish to print list \n:")

    if print_list == "yes":
        for item in List:
            print (item , "%2.f" %(Speed),"m/s")
        break

    elif print_list == "no":
        print ("Thank you")
        break

    else:
        print ("Invalid Input\n")
Rahul
  • 2,515
  • 3
  • 25
  • 29