亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在python中計算

在python中計算

偶然的你 2022-12-14 20:56:30
到目前為止我做了什么: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)
查看完整描述

2 回答

?
SMILET

TA貢獻1796條經驗 獲得超4個贊

您正在與input_time.hour整數進行比較。沒有這樣的整數 N 23 <= N <= 6,因此您elif語句中的條件永遠不會為真。您應該簡單地將elif語句替換為else.



查看完整回答
反對 回復 2022-12-14
?
catspeake

TA貢獻1111條經驗 獲得超0個贊

如果您輸入的時間為:10:24,則此:datetime.datetime.strptime(startime,"%H:%M") 將起作用。如果您將時間輸入為 10,您的示例將起作用。


一切都取決于您如何定義時間輸入。


另外,你的比較似乎不對。


import datetime

distance_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.5

perkilo_charge = 2.1 * distance_tobecovered

valueforall = fixed_charge + perkilo_charge

v = valueforall + (2 * distance_tobecovered * 0.99)


input_time = datetime.datetime.strptime(startime, "%H:%M")


if ((input_time.hour>=23) or (input_time.hour < 6)):

    print("night or early morning")

    print(v)#does some calculation

else:

    print("day")

    print("#does some calculation ")


查看完整回答
反對 回復 2022-12-14
  • 2 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號