python | time模组计算时间差

python | time模组计算时间差,第1张

python | time模组计算时间差

time模组的实质是计算从1970年1月1日迄今经过了多久时间,因此较适合简单计算时间差的程序,如计算程序运行时长。
下面这个练习只是试图简单模拟“无人”停车场自动计费装置,且代码编写得并不美观简明,甚至不够完整,还需要进一步修改。
望各位博友海涵。

import time

private_owner=["A11111","B11111","C11111","D11111"] #list of private park-lot owner
temporary_car={} 


gate_enter=input("輸入您的車牌號: ")
if gate_enter in private_owner: #detect if the vehicle IS private car
     print("歡迎, 月租用戶"+gate_owner+" !") 
else:
     temporary_car[gate_enter] = int(time.time()) #mark entering time trick
     print("歡迎, 訪客"+gate_enter+" !")
     print(temporary_car)
     
#------

gate_leave=input("輸入您的車牌號: ")
if gate_leave in private_owner: #detect if the vehicle IS private car
     print("歡迎, 月租用戶"+gate_owner+" !")
else:
     leave_time=int(time.time()) #mark leaving time trick
     if gate_leave in temporary_car:
          parking_time= abs(temporary_car[gate_enter] - leave_time) #caculate the parking period
          print(leave_time)
          print(parking_time)
          print("歡迎, 訪客"+gate_enter+" !")
          print(temporary_car)         
     else:
          print("Please contact parking-lot manager ASAP.")
          

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5721120.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存