在python中计算

到目前为止我做了什么:


import datetime

   distance_tobecovered = float(input("Please enter a number for the startime = input("Please input the time for the alarm in format HH:")

    fixed_charge = 3.5

    perkilo_charge = 2.1 * distance_tobecovered

    valueforall = fixed_charge + perkilo_charge

    v = valueforall + (2 * distance_tobecovered * 0.99

)


偶然的你
浏览 110回答 2
2回答

SMILET

您正在与input_time.hour整数进行比较。没有这样的整数 N&nbsp;23 <= N <= 6,因此您elif语句中的条件永远不会为真。您应该简单地将elif语句替换为else.

catspeake

如果您输入的时间为:10:24,则此:datetime.datetime.strptime(startime,"%H:%M") 将起作用。如果您将时间输入为 10,您的示例将起作用。一切都取决于您如何定义时间输入。另外,你的比较似乎不对。import datetimedistance_tobecovered = float(input("Please enter a number for the distance: "))startime = input("Please input the time for the alarm in format HH:MM :")fixed_charge = 3.5perkilo_charge = 2.1 * distance_tobecoveredvalueforall = fixed_charge + perkilo_chargev = valueforall + (2 * distance_tobecovered * 0.99)input_time = datetime.datetime.strptime(startime, "%H:%M")if ((input_time.hour>=23) or (input_time.hour < 6)):&nbsp; &nbsp; print("night or early morning")&nbsp; &nbsp; print(v)#does some calculationelse:&nbsp; &nbsp; print("day")&nbsp; &nbsp; print("#does some calculation ")
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python