'''
@Author: your name
@Date: 2020-07-25 14:31:56
@LastEditTime: 2020-07-25 14:43:50
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day19.py
'''
import random
# Question 75
# 生成随机数
def Q75():
ans=random.randrange(7,16)
print (ans)
# 编码/解码
# Question 76
# Please write a program to compress and decompress the string "hello world!hello world!hello world!hello world!".
# Use zlib.compress() and zlib.decompress() to compress and decompress a string.
def Q76():
import zlib
s='hello world!hello world!hello world!hello world'
s=bytes(s,'utf-8')
r=zlib.compress(s)
print(r)
print(zlib.decompress(r))
# Question 77
# 计时
def Q77():
import datetime
s=datetime.datetime.now()
for i in range(100):
x=1+1
e=datetime.datetime.now()
print("time spend:{}".format((e-s).microseconds))
# Question 78
# Please write a program to shuffle and print the list [3,6,7,8].
def Q78():
l=[3,6,7,8]
random.shuffle(l)
print(l)
# Question 79
# Please write a program to generate all sentences where subject is in ["I", "You"] and verb is in ["Play", "Love"] and the object is in ["Hockey","Football"].
def Q79():
who=["I", "You"]
how=["Play", "Love"]
what=["Hockey","Football"]
for i in who:
for j in how:
for t in what:
# print("sentences:{}".format(i+" "+j+" "+t))
print("{} {} {}".format(i,j,t))
if __name__ == "__main__":
# Q75()
# Q76()
# Q77()
# Q78()
Q79()
【Python Practice】Day 19 Question 75-79
最新推荐文章于 2024-02-10 09:11:59 发布