100+ Python challenging programming exercises 9
Question 81
Please write a program to randomly print a integer number between 7 and 15 inclusive.
Hints: Use random.randrange() to a random integer in a given range.
请编写一个程序,随机打印一个介于7和15之间的整数。
提示:对给定范围内的随机整数使用random.randrange()。
Solution:
import random
print(random.randrange(7,16))
Question 82
Please write a program to compress and decompress the string "hello world!hello world!hello world!hello world!".
Hints: Use zlib.compress() and zlib.decompress() to compress and decompress a string.
请编写一个程序来压缩和解压缩字符串“hello world!hello world!hello world!hello world!”。
提示:使用zlib.c