输出应以此格式显示时间:上午8:00
def save_time():
cse_info = {}
again = 'Y'
while again.lower() == 'y':
cse_num = int(input('Enter course number:'))
cse_time = int(input('Enter course meeting time:'))
cse_info['CS' + str(cse_num)] = str(cse_time) + ' a.m.'
again = input('Do you want to enter another course?')
print(cse_info)
save_time()
答案 0 :(得分:0)
看起来你需要一种方法来退出你的while循环...它应该可以工作。
def save_time():
cse_info = {}
again = 'Y'
while again.lower() == 'y':
cse_num = int(input('Enter course number:'))
cse_time = int(input('Enter course meeting time:'))
break # maybe you want to check for an exit condition?
cse_info['CS' + str(cse_num)] = str(cse_time) + ' a.m.'
again = input('Do you want to enter another course?')
print(cse_info)
save_time()
这次我会为你做这件事,但这不是一个家庭作业网站。
def save_time():
cse_info = {}
while True:
cse_num = int(input('Enter course number:'))
cse_time = int(input('Enter course meeting time:'))
cse_info['CS' + str(cse_num)] = str(cse_time) + ' a.m.'
again = input('Do you want to enter another course? (1=yes 2=no')
if not again: break
print(cse_info)
save_time()
答案 1 :(得分:0)
如果cse_time
的输入格式为" 0800"在" 8:00",然后您可以用str(cse_time) + ' a.m.'
替换str(cse_time)[:2]+":"+str(cse_time)[2:] + ' a.m.'
以添加分号。或者您可以cse_time
为字符串,因此输入可以是8:00
。