Home > Software design >  i tried to create a program for in case of an error in entering the input but after that it does not
i tried to create a program for in case of an error in entering the input but after that it does not

Time:12-05

after i type 5 it continue to loop and dont't get to the if statement

def facility():
     global user
     while user != 1 and user != 2 and user != 3 and user != 4:
            user =input("please choose between this four number. \n[1/2/3/4]\n")
     if user == 1:
             y = ("PBl Classroom")
     elif user == 2:
             y = ("meeting room")
     elif user == 3:
             y =("Workstation Computer Lab,ITMS") 
     elif user == 4:
             y = ("swimming pool")
     print("you have choose",y)

user = int(input("please choose your facility..\n "))

CodePudding user response:

You use int(input(...)) on your first call, but input(...) in the function. Thus the values are strings, not integers and your comparisons will fail.

Here is a fix with minor improvements:

def facility():
     user = int(input("please choose your facility..\n "))
     while user not in (1,2,3,4):
            user = int(input("please choose between this four number. \n[1/2/3/4]\n"))
     if user == 1:
             y = ("PBl Classroom")
     elif user == 2:
             y = ("meeting room")
     elif user == 3:
             y =("Workstation Computer Lab,ITMS") 
     elif user == 4:
             y = ("swimming pool")
     print("you have chosen", y)

facility()
  • Related