In: Computer Science
How can i quit this python program.
#********************************************************************************
#Program : SearchClassInfo.py
#Description: This program will ask a user to enter 6 courses and
will allow him
# to search a class by course number, room number, intructor or
time,
# the program will run until the user stop it.
#********************************************************************************
from os import sys
def main():
#Definition of 4 lists
courses = []
rooms = []
instructors = []
times = []
#Allow user to enter six courses
for x in range(2):
Course_Number =input('Enter the course number: ')
Room_Number = input('Enter a room number: ')
Instructor =input('Enter the Instructor of the course: ')
Time = input('Enter the time the course meets: ')
#Add elements in appriate list.
courses.append(Course_Number)
rooms.append(Room_Number)
instructors.append(Instructor)
times.append(Time)
loop = 1 #initialisation of a flag.
while loop != 0:
try:
#Display a menu of four choices to make to search a class.
print('\nEnter 1 to search by course number: ')
print('Enter 2 to search by room number: ')
print('Enter 3 to search by instructor: ')
print('enter 4 to search by time: ')
choice = int(input('Enter your choice: '))#ask user to enter his
choise for search.
if choice == 1 :
#ask user to enter course number for search of corresponding
elements.
Course_Number = input('Enter a course number: ')
if Course_Number in courses: #verify if the couse number entered is
in the list
#extract the index of the course number in list.
i=courses.index(Course_Number)
#printing elements on the same index as course number in other
lists.
print('\nThe detail for course',courses[i], 'are:'
'\nRoom:', rooms[i],
'\nInstructor:',instructors[i],
'\nTime:',times[i], end=' ''\n')
else:#message to alerte when course number does not exit
print('\nThis course number is not on schedule')
elif choice == 2 :
# #ask user to enter room number for search of corresponding
elements.
Room_Number = input('Enter a room number: ')
if Room_Number in rooms:#verify if the room number entered is in
the list
#extract the index of the room number in list.
i=rooms.index(Room_Number)
#printing elements on the same index as room number in other
lists.
print('\nThe detail for course',courses[i], 'are:'
'\nRoom:', rooms[i],
'\nInstructor:',instructors[i],
'\nTime:',times[i], end=' ' '\n')
else:#message to alerte when room number does not exit
print('\nThis room number is not on schedule')
elif choice == 3 :
Instructor = input('Enter the Instructor of the course: ')
if Instructor in instructors:
i=instructors.index(Instructor)
print('\nThe detail for course',courses[i], 'are:'
'\nRoom:', rooms[i],
'\nInstructor:',instructors[i],
'\nTime:',times[i], end=' ' '\n')
else:
print('\nThis instructor is not on schedule')
elif choice == 4 :
Time = input('Enter the time the course meets: ')
if Time in times:
i=times.index(Time)
print('\nThe detail for course',courses[i], 'are:'
'\nRoom:', rooms[i],
'\nInstructor:',instructors[i],
'\nTime:',times[i], end=' ' '\n')
else:
print('\nThis time is not on schedule')
elif choice!=' ':
print('Choice goes from 1--->4')
loop = 0
print('\nDo you want to continue? Enter y for yes')
control = input(' ')
if control == 'y'or'Y':
loop = 1
elif control!=' ':
sys.exit(0)
except:
print('incorrect choice, must be 1,2,3 or4')
pass
main()
The code in image:

The code in the text:
from os import sys
def main(): #Definition of 4 lists
courses = []
rooms = []
instructors = []
times = [] #Allow user to enter six courses
for x in range(2):
Course_Number =input('Enter the
course number: ')
Room_Number = input('Enter a room
number: ')
Instructor =input('Enter the
Instructor of the course: ')
Time = input('Enter the time the
course meets: ') #Add elements in appriate list.
courses.append(Course_Number)
rooms.append(Room_Number)
instructors.append(Instructor)
times.append(Time)
loop = 1 #initialisation of a flag.
while loop!=0:
try: #Display a menu of four
choices to make to search a class.
print('\nEnter 1
to search by course number: ')
print('Enter 2
to search by room number: ')
print('Enter 3
to search by instructor: ')
print('enter 4
to search by time: ')
choice =
int(input('Enter your choice: '))#ask user to enter his choise for
search.
if choice == 1 :
#ask user to enter course number for search of corresponding
elements.
Course_Number = input('Enter a course number:
')
if Course_Number in courses: #verify if the
course number entered is in the list#extract the index of the
course number in list.
i=courses.index(Course_Number) #printing elements on the same index
as course number in other lists.
print('\nThe detail for
course',courses[i], 'are:''\nRoom:',
rooms[i],'\nInstructor:',instructors[i],'\nTime:',times[i], end='
''\n')
else:#message to alerte when course number does
not exit
print('\nThis course number
is not on schedule')
elif choice == 2
: # #ask user to enter room number for search of corresponding
elements.
Room_Number = input('Enter a room number:
')
if Room_Number in rooms: #verify if the room
number entered is in the list #extract the index of the room number
in list.
i=rooms.index(Room_Number)
#printing elements on the same index as room number in other
lists.
print('\nThe detail for
course',courses[i], 'are:''\nRoom:',
rooms[i],'\nInstructor:',instructors[i],'\nTime:',times[i], end=' '
'\n')
else:#message to alerte when room number does
not exit
print('\nThis room number is
not on schedule')
elif choice == 3
:
Instructor = input('Enter the Instructor of the
course: ')
if Instructor in instructors:
i=instructors.index(Instructor)
print('\nThe detail for
course',courses[i], 'are:''\nRoom:',
rooms[i],'\nInstructor:',instructors[i],'\nTime:',times[i], end=' '
'\n')
else:
print('\nThis instructor is
not on schedule')
elif choice == 4
:
Time = input('Enter the time the course meets:
')
if Time in times:
i=times.index(Time)
print('\nThe detail for
course',courses[i], 'are:''\nRoom:',
rooms[i],'\nInstructor:',instructors[i],'\nTime:',times[i], end=' '
'\n')
else:
print('\nThis time is not on
schedule')
elif choice!='
':
print('Choice goes from 1--->4')
print('\nDo you
want to continue? Enter y for yes and n for no')
control =
input(' ')
if control ==
'y'or control=='Y':
loop = 1
elif control ==
'N' or control=='n':
loop=0
except:
print('incorrect
choice, must be 1,2,3 or4')
pass
main()
Output:

I just changed the condition in elif, so if the user enters n for no then the loop=0 and the while loop will be stopped.
I tried sys.exit() but it didn't worked for me.
If you have any doubt comment me.