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)
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
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7d4fd4d4-77c7-4e93-950b-25099f54e660%2F499a4019-fa4d-499d-9956-abbf323572d0%2Fifarepi_processed.jpeg&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education