Answer to Question #98211 in Python for bob jones

Question #98211
In this assignment, you will draw a student schedule by using a while loop. You will ask the user for their first and last names, and then a list of their classes and room numbers.

The loop should stop when they enter STOP for their next class.

Print the schedule in the same format as the example below. Remember to use the tab escape character to make it nicely formatted.
1
Expert's answer
2019-11-11T16:35:09-0500



I'd like to look at the schedule format as to the requirement in the assignment:

"Print the schedule in the same format as the example below."


In fact there is no example with that format.

So I use an arbitrary format for the class schedule to be printed.

Thank you.


Version 1.


first_name = input('Enter your first name: ')
last_name = input('Enter your last: ')

classes = []

while True:
   class_name = input('Enter a name of the (next) class (or STOP/Stop/stop): ')

   if class_name not in ['STOP', 'Stop', 'stop']:
      room_number = input('Enter a room number of the class: ')
      classes.append((class_name, room_number))
   else:
      break   

if classes:
   print('\n'+first_name, last_name + '\'s schedule:')
   print('-------------------------')
   print('Class\t\tRoom')
   print('-------------------------')   
   for num, (class_name, room_number) in list(enumerate(classes, start=1)):
      print(str(num)+'.'+class_name, '\t', room_number)


Version 2 with exceptions.


while True:
   start = input("\nWould you like to draw new student's class schedule? (yes/no or y/n) ")
   #print("start =", start)
   try:
      assert(start in ["yes", "y", "no", "n"])
   except AssertionError:
      print("\nPlease, enter one of the following: 'yes', 'y', 'no', 'n'")
   else:
      if start in ["yes", "y"]:
         first_name = input("\nEnter your first name: ")
         last_name = input("Enter your last: ")

         classes = []

         while True:
            class_name = input("Enter a name of the (next) class (or STOP/Stop/stop): ")
            try:
               assert(class_name in ["STOP", "Stop", "stop"])
               break
            except AssertionError:
               pass
            room_number = input("Enter a room number of the class: ")
            classes.append((class_name, room_number))

         try:
            assert(classes)
            print('\n{0} {1}\'s class schedule:'.format(first_name, last_name))
            print('{0:2} {1:25} {2}'.format(" ", "Class", "Room"))
            for num, (class_name, room_number) in list(enumerate(classes, start=1)):
               #print(str(num)+'.', class_name, '\t', room_number)
               print('{0}. {1:25} {2}'.format(num, class_name, room_number))
         except AssertionError:
            pass
      else:
         break

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS