gpt4 book ai didi

time - 如何将分钟转换为天、小时和分钟?

转载 作者:行者123 更新时间:2023-12-02 00:56:06 25 4
gpt4 key购买 nike

我是 Python 的初学者,所以我真的不知道很多术语或任何东西。请问如何将分钟转换为小时和分钟例如: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)

最佳答案

好吧,如果您输入的分钟数大于等于 1440 分钟,那么您至少有一天的时间。因此,为了处理这个(以及时间的其他方面),我们可以使用模数 (%)。

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. ")

这应该有效。

关于time - 如何将分钟转换为天、小时和分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35004952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com