Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在输出中显示冒号以显示时间?_Python_String_Integer_Output - Fatal编程技术网

Python 如何在输出中显示冒号以显示时间?

Python 如何在输出中显示冒号以显示时间?,python,string,integer,output,Python,String,Integer,Output,输出应以以下格式显示时间:上午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:')) c

输出应以以下格式显示时间:上午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()

看起来你需要一种退出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()

如果
cse_time
的输入格式为“0800”为“8:00”,则可以将
str(cse_time)+“a.m.”
替换为
str(cse_time)[:2]+“:”+str(cse_time)[2::+'a.m.
以添加分号。或者您可以将
cse\u时间
设置为字符串,这样输入可以是
8:00

对于
cse\u时间
,您希望输入什么?类似于“0833”的内容?尝试创建一个接受数字的输入并显示此格式:8:00首先修复缩进,如果所有数字都产生
8:00
,缩进不好的问题无法回答?如果我输入
850
?@vishes\u shell如何确定while循环下的缩进是正确的?OP是这么说的吗?如果你不是100%确定,不要编辑问题。接下来的三行也可能在while循环下。Wait for OPIt看起来缩进不良,OP可能缩进了while循环下的所有内容,因此可以退出while循环,因为再次更改
变量。这不是问题所在