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
Comments
Leave a comment