要求如下1.能输入停车时间,单位为小时,输入时间为整数
2.能根据输入时间自动算出停车费。
你题目的解答代码如下:
time = int(input("请输入一个整数时间:"))
if time<=2:
m = 5
else:
m = 5 + (time-2)*2
print("停车费",m)
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
如有帮助,敬请采纳,你的采纳是我前进的动力,O(∩_∩)O谢谢!!!!!!!!
# -*- coding: UTF-8 -*-
"""
@项目名称:百度经验.py
@作 者:陆地起飞全靠浪
@创建日期:2022-04-29-10:07
"""
import time
def get_mony(start_time):
# 获取当前时间
now_time = time.strftime("%H:%M").split(':')
H, M = [int(x) for x in now_time]
if M != 0:
# 不足一个小时按一个小时算
H += 1
# 总的停车时间
stop_time = H - start_time
mony = 0
if stop_time <= 2:
mony = 5
else:
mony = (stop_time - 2) * 2 + 5
print(f'停车费为{mony}元')
return mony
if __name__ == '__main__':
start_time = int(input("输入停车开始时间:"))
get_mony(start_time)
def function(the_time):
if the_time < 2:
return 5
plus = 5
the_time -= 2
while the_time > 0:
plus += 2
the_time -= 1
return plus
if __name__ == '__main__':
res = function(10)
print("停车费:", res)
while 1:
s_time = input("请输入停车时间: ")
cost = 5
if s_time.isdigit():
s_time = int(s_time)
if s_time <= 2:
print(f'停车费[ {cost} ] 元')
else:
s_time -= 2
print(f'停车费[ {s_time * 2 + cost} ] 元')
break
else:
print("输入有误,请重新输入(整数)时间!")
import datetime
import math
start = datetime.datetime.fromisoformat('2021-06-25 01:10:00')
end = datetime.datetime.strptime('2021-6-25 9:30:00','%Y-%m-%d %H:%M:%S')
start_stamp = datetime.datetime.timestamp(start)
end_stamp = datetime.datetime.timestamp(end)
hour = math.ceil((end_stamp-start_stamp)/60/60)
money = 0 if hour<=1 else 4 if hour<=2 else (hour-2)*2+4
money = money if money<20 else 20
print(hour,money)
import datetime
def parking_fees(start_time):
start_hours = int(start_time)
now_time = datetime.datetime.now()
now_hours = now_time.hour
parking_hours = now_hours - start_hours + 1
if parking_hours <= 2:
parking_cost = 5
else:
parking_cost = 5 + (parking_hours - 2) * 2
return parking_cost
if name == "main":
start_time = input("请输入开始时间:")
park_fees = parking_fees(start_time)
print(park_fees)
class ParkingLotChargingStandard:
@staticmethod
def charge(parkingTime):
if parkingTime < 1 or parkingTime == 1:
return 5
elif parkingTime > 1:
return (int(parkingTime) + 1) * 2
if __name__ == '__main__':
charge = ParkingLotChargingStandard()
parkingTime = input("停车时间:")
parkingRate = charge.charge(float(parkingTime))
print("停车费用:", parkingRate)