2019-11-19 homework

"""___author___ =JiangYiwei"""
from math import pi

# 1. 写一个生成式能够产生的数据为: 1, 2, 27, 256, 3125,…, 9**9
# 2. 写一个生成式能够产生1-10中所有半径是偶数的圆的面积
# 3. 写一个生成式交换字段的键和值,产生一个新的字典

# 1.
creat_jy = (x ** x for x in range(1, 10))
# for i  in creat_jy:
#     print(i)

# 2.
circle_jy = (pi * r ** 2 for r in range(1, 11) if r % 2 == 0)
# for i in circle_jy:
#     print(i)
# 3.
# dict1 = {'name': 'Kiki', 'age': "19"}
dict1 = {'a': 1, 'b': 2}
dict2 = dict((dict1[key], key) for key in dict1)
print(dict2)

# def i(n):
#     for key in dict1:
#         yield dict1[key], key
#
#
# dict2 = dict(i(dict1))
# print(dict2)

你可能感兴趣的:(2019-11-19 homework)