Question
in below program when we add a record and then if we search a record which is not there it must say inavalid option or
in below program when we add a record and then if we search a record which is not there it must say inavalid option or data not found but it is shwoing an eror please fix it CODE:
# " Project: Train Management System "
name=[] #creating empty list for model name registration=[] # Creating empty list for Registration capacity=[] # Creating Empty list for capacity chasis=[] # creating list for chasis number engine=[] #creating list for engine number
def main(): #defining main function print("\t Welcome to Train Management Sysytem ") # print statement for title continueloop = True # appling condition while continueloop: # applying while loop if while is equal to condition print("1. Add record 2. View Record 3. Search Record 4. Update Record 5. Exit ") #print statement for options choice = eval(input("Select the option: ")) # input statement for user if choice==1: # applying if condition it only works if user input 1 add() #calling add function elif choice==2: # else if statement it only works if user input 2 view() #calling view function elif choice==3: # else if statement it only works if user inputs 3 search() #calling search function() elif choice==4: # else if statement it only works if choice is 4 update() #calling update function elif choice==5: # elif statement if choice is 5 print("programme terminates successfully") # print statement which runs if choice is 5 continueloop = False #loop terminates else: #else condition it wokrs when if condition is not satisfied print("Invalid option") # print statement for invalid option
def add(): #defining add function print("You selected to Add Records.")# print statement to print title check = 'y' # applying check count = 1 # initalizing 1 to count variable while check == 'y': # while loop which runs when check is equal to y name.append(input("Enter Model name: ".format(count))) # appending value to name list capacity.append(input("Capacity: ")) # assigning a capcitty to capacity list registration.append(input("Enter Registration Number: ")) #appendding a value to list engine.append(input("Enter engine number: ")) # initializing a new value to engine list chasis.append(input("Enter chasis number: ")) # appending a value to list by taking input count +=1 # increment of 1 to count check=(input("For another Record press y: "))# taking user input for check print(" Data added successfully ") # printing final statement def view():# defining view function if len(name) == 0: # check record added print("No data found") # if record is not found then this statement will bw printed for i in range(len(registration)): # applying for print("Model Name: ", name[i]) # print model name from model list print("capacity: ", capacity[i])# print capacity from capacity list print("registartion: ", registration[i])# printing registration number from registration list print("engine num: ", engine[i])# printing engine number from list print("chasis num: ", chasis[i]) # printing registration number from list def search():# defining search function print("search record") # printing title statement if len(name) == 0: # checking for records using if condition print("No Data found")# print statement to be printed when if condition not satisfies a = input("Enter chasis num: ")# taking user input to search record i = chasis.index(a)# checking user input in index of chasis list print("Model Name: ", name[i])# printing the specific record print("capacity: ", capacity[i]) # printing the capacity from its index print("registartion: ", registration[i])# printing the registration number that links with chasis number given print("engine num: ", engine[i]) # printing engine number found print("chasis num: ", chasis[i]) # printing chasis number found
def update():# defining update fnction if len(name) == 0: # checking record in name list print("No data found")# print statement when no data found b = input("Enter chasis number: ")# taking input from user print("Enter 1 to update model name")# printing option 1 print("Enter 2 to update capacity")# print statement to print a line print("Enter 3 to update registration number")# print statement for option 3 print("Enter 4 to update engine number") #printing option 4 print("Enter 5 to update chasis number")# printing optionn 5 line choice = eval(input("Select the option: ")) # taking choice from user if choice==1:# if condition it only works if choice is 1 new_name = input("Enter new model name: ") # making a new variable to enter a new value elif choice==2: # else if condition only works when choice is 2 new_capacity = eval(input("Enter new capacity: ")) # assigning a value to variable elif choice==3:# else if condition only works when choice is 3 new_registration = eval(input("Enter new registration number: ")) # when choice is 3 we assign value to this variable elif choice==4: # else if condition it only works when choice is 4 new_engine = eval(input("Enter new engine number: ")) # user input to assign a value to variable elif choice==5: # else if statement it only works if choice is 5 new_chasis = eval(input("Enter new chasis number: ")) # taking user input for this variable for x in range(0,len(chasis)):# applying for loop given range from 0 to chasis length if chasis[x] == b:# if condition to find b ib index of chasis if choice==1: # nested if condition only works if choice is equal to 1 name[x] = new_name # assigning name list a new value elif choice==2: # multiway selection it only works it choice is 2 capacity[x] = new_capacity # assigning a value to capacity list elif choice==3: # else if condition only works if choice is 3 registration[x] = new_registration # assigning a new value to registration elif choice==4: # elif condition only works if choice =4 engine[x] = new_engine # assigning a new value to engine elif choice==5: # else if ccndition only works if choice is 5 chasis[x] = new_chasis #assigning he value of variable to chasis list else: # else condition only works if non of if condition satisfied print("Invalid selection. Back to main menu") # print statement to be printed is else statement is staisfied
main() #calling main function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started