3

私はPythonの初心者なので、多くの用語や何かを本当に知りません。分を時間と分に変換する方法を教えてください EX: 75 分 -> 0 日、1 時間、15 分

print("Welcome to the Scheduler!")
print("What is your name?")
name = input()
print("How many chocolates are there in the order?")
chocolates = input()
print("How many chocolate cakes are there in the order?")
chocolate_cakes = input()
print("How many chocolate ice creams are in the order?")
chocolate_ice_creams = input()
total_time = float(chocolates) + float(chocolate_cakes) + float(chocolate_ice_creams)
print("Total Time:")
print("How many minutes do you have before the order is due?")
minutes = input()
extra_time = float(minutes) - float(total_time)
print("Your extra time for this order is", extra_time)

time = extra_time // 60

print("Thank you,", name)
4

5 に答える 5

4

1440 分以上の分単位の入力が与えられた場合、少なくとも 1 日はあります。したがって、これ (および時間の他の側面) を処理するために、モジュラス (%) を使用できます。

days = 0
hours = 0
mins = 0

time = given_number_of_minutes   
days = time / 1440     
leftover_minutes = time % 1440
hours = leftover_minutes / 60
mins = time - (days*1440) - (hours*60)
print(str(days) + " days, " + str(hours) + " hours, " + str(mins) +  " mins. ")

これはうまくいくはずです。

于 2016-01-26T14:21:43.857 に答える
1

整数を取得するには、実際には値を切り捨てる必要があります。

import math

def transform_minutes(total_minutes):

    days = math.floor(total_minutes / (24*60))
    leftover_minutes = total_minutes % (24*60)
    
    hours = math.floor(leftover_minutes / 60)
    mins = total_minutes - (days*1440) - (hours*60)
    
    #out format = "days-hours:minutes:seconds"
    out = '{}-{}:{}:00'.format(days, hours, mins)
    return out
于 2021-06-21T13:03:54.180 に答える