Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem Help!
#1
I'm having trouble with the code for this problem:
Write a program for course registration. Students can use this program to add and drop courses. There should be a loop in the program that tells the user to enter A to add course, D to drop course or E to exit. If A is chosen, ask the user to enter the course to add. If the user is already registered in that course, display the message “You are already registered in that course”; otherwise, add the course to the user’s course list, display the message “Course added”, sort the list and display the list. If the user chooses D, ask the user to enter the course to drop. If the user is not registered in that course, display the message “You are not registered in that course”; otherwise, remove the course from the user’s course list, display the message “Course dropped” and display the list. The loop will stop when the user enters E.

Basically I'm having problems with having three while loops. I know looking at it, the "again" function is only going to make it repeat the first body of the first while statement. I need to find a way to access all three loops or know how to rewrite the code to make it work. Sorry for the long text.
course_list =[]
decision=input('Enter A to add course, D to drop course, and E to exit:[A/D/E]')
decision=decision.upper()

while decision == 'A':
    add_course=input("Enter course to add:")
    add_course.upper()
    if add_course in course_list:
        print("You are already registered in that course")
        print('Courses Registered:', course_list)
    else:
        course_list.append(add_course)
        print('Course added')
        print('Courses Registered:', course_list)
    again=input('Enter A to add course, D to drop course, and E to exit:[A/D/E]')

while decision == 'D':
    del_course=input('Enter course to drop:')
    del_course.upper()
    if del_course in course_list:
        course_list.remove(del_course)
        print('Course Dropped')
        print('Courses Registered:', course_list)
    else:
        print('You are not registered for that course')
        print('Courses Registered:', course_list)
    again=input('Enter A to add course, D to drop course, and E to exit:[A/D/E]')

while decision == 'E':
    print('Press ENTER to EXIT')
Reply


Messages In This Thread
Problem Help! - by Noxmancer - Sep-18-2019, 09:41 PM
RE: Problem Help! - by ichabod801 - Sep-18-2019, 09:55 PM
RE: Problem Help! - by Noxmancer - Sep-18-2019, 11:32 PM
RE: Problem Help! - by ichabod801 - Sep-18-2019, 11:52 PM
RE: Problem Help! - by Noxmancer - Sep-18-2019, 11:54 PM
RE: Problem Help! - by ichabod801 - Sep-18-2019, 11:55 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020