listHavingCourses # while loop execution while(1): # Ask user for a course courseEntryByUser = input("Enter a course name or type 'EXIT' to stop: ") # if 'EXIT' entered if courseEntryByUser # print list having courses by using a for loop print("List of courses: ") for eachCourseIdx in range(len(1listHavingCourses)): print(str(eachCourseIdx + 1) + ": " + listHavingCourses[eachCourseIdx]) # quit loop == "EXIT": break else: # otherwise # add course in list listHavingCourses.append(courseEntryByUser) # if list length = 6 if len(listHavingCourses) # print all courses menu and == 6: print("\nList of added courses: ") for eachCourseIdx in range(len(listHavingCourses)): print(str(eachCourseIdx + 1) + ": " + listHavingCourses[eachCourseIdx]) # ask user to delete a course courseToDelete = int(input("Enter a course number to delete: ")) # delete course by index print("The " + str(listHavingCourses[courseToDelete - 1]) + " deleted!\n") listHavingCourses.pop(courseToDelete - 1)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Python code. Could you add functions(def) to the code I have to make the code more readable. The output must be the same but you can change the style of the code. Thanks!
# empty list to hold courses
listHavingCourses
1
2
# while loop execution
while(1):
# Ask user for a course
7
courseEntryByUser = input("Enter a course name or type 'EXIT' to stop: ")
8.
# if 'EXIT' entered
10
if courseEntryByUser
== "EXIT":
# print list having courses by using a for loop
print("List of courses: ")
for eachCourseIdx in range(len(listHavingCourses)):
11
12
13
print(str(eachCourseIdx + 1) + ":
# quit loop
14
+ listHavingCourses[eachCourseIdx])
15
16
break
17
else:
18
# otherwise
19
# add course in list
20
listHavingCourses.append(courseEntryByUser)
21
# if list length
if len(listHavingCourses)
# print all courses menu and
print("\nList of added courses: ")
for eachCourseIdx in range(len(listHavingCourses)):
| print(str(eachCourseIdx + 1) + ": " + listHavingCourses[eachCourseIdx])
22
6
23
== 6:
24
25
26
27
28
# ask user to delete a course
29
courseToDelete = int(input("Enter a course number to delete: "))
# delete course by index
print("The " + str(listHavingCourses[courseToDelete - 1]) + " deleted!\n")
listHavingCourses.pop(courseToDelete - 1)
30
31
32
Transcribed Image Text:# empty list to hold courses listHavingCourses 1 2 # while loop execution while(1): # Ask user for a course 7 courseEntryByUser = input("Enter a course name or type 'EXIT' to stop: ") 8. # if 'EXIT' entered 10 if courseEntryByUser == "EXIT": # print list having courses by using a for loop print("List of courses: ") for eachCourseIdx in range(len(listHavingCourses)): 11 12 13 print(str(eachCourseIdx + 1) + ": # quit loop 14 + listHavingCourses[eachCourseIdx]) 15 16 break 17 else: 18 # otherwise 19 # add course in list 20 listHavingCourses.append(courseEntryByUser) 21 # if list length if len(listHavingCourses) # print all courses menu and print("\nList of added courses: ") for eachCourseIdx in range(len(listHavingCourses)): | print(str(eachCourseIdx + 1) + ": " + listHavingCourses[eachCourseIdx]) 22 6 23 == 6: 24 25 26 27 28 # ask user to delete a course 29 courseToDelete = int(input("Enter a course number to delete: ")) # delete course by index print("The " + str(listHavingCourses[courseToDelete - 1]) + " deleted!\n") listHavingCourses.pop(courseToDelete - 1) 30 31 32
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education