2017-04-15 1 views
0

出力は、この形式で時刻を表示する必要があります午前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

foo 'cse_time'にはどのような入力がありますか? "0833"のようなもの? – kabanus

+0

数字を入力してこの形式を表示する入力を作成しようとしました:8:00 –

+2

インデントを最初に修正してください。インデントの悪い質問には返答できません。 – abccd

答えて

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

これはインデントが悪いようですが、OPはおそらくwhileループの下のすべてをインデントしたでしょうから、 'again'変数の変更のためにwhileループを終了することは可能です。これは問題ではない – abccd

0

cse_timeの入力は、「午前8時00分」である「0800」の形式である場合は、セミコロンで追加するstr(cse_time)[:2]+":"+str(cse_time)[2:] + ' a.m.'str(cse_time) + ' a.m.'を置き換えることができます。または、入力が8:00になるようにcse_timeを文字列にすることができます。

関連する問題