Interesting little exercise

1. Demand, write function, two input time format 1970-1-112: 00: 00,1970-1-1 14:30:00, the time difference between the two is calculated, the required output "2 hours and 30 minutes."

import time
def func(start,end):
struct_start=time.strptime(start,"%Y-%m-%d %H:%M:%S")
struct_end=time.strptime(end,"%Y-%m-%d %H:%M:%S")
stump_start=time.mktime(struct_start)
stump_end=time.mktime(struct_end)
cal_time=stump_end-stump_start
diff_min=cal_time // 60
hour=int(diff_min // 60)
min=int(diff_min % 60)
print(f"{hour}时{min}分")
func("2018-9-30 12:00:00","2018-9-30 12:30:00")

2. Requirements: Use random.random () Gets [m, n] is an integer
Import Random
DEF FUNC (m, n-):
Re = int ((random.random () * (n-m-+. 1) + m))
Print (Re)
FUNC (19, 29)
 

 

Guess you like

Origin www.cnblogs.com/jiangzongyou/p/11616953.html