摘要: def gcd(x, y): if y == 0: return x else: t = x % y x = y y = t return gcd(x,y) num1 = int(input('请输入第一个数字:')) num2 = int(input('请输入第二个数字:')) print(num 阅读全文
posted @ 2020-10-16 15:09 龚志军Flagon 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 列表生成与相关拓展 1 # 一般地 2 list1 = [] 3 for i in range(6): 4 list1.append(i) 5 # 列表生成式 6 list2 = [i for i in range(7) if not(i % 2)] 7 # 结合filter 8 list3 = f 阅读全文
posted @ 2020-10-16 14:42 龚志军Flagon 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 类的组合用法 1 class Turtle: 2 def __init__(self, x): 3 self.num = x 4 5 6 class Fish: 7 def __init__(self, y): 8 self.num = y 9 10 11 class Pool: 12 def __ 阅读全文
posted @ 2020-10-16 11:38 龚志军Flagon 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 最大约数的计算 1 def cd(x): 2 """求一个正整数的除自身外的最大约数""" 3 count = x // 2 4 if not(x >= 3): 5 print('请代入一个大于2的正整数!') 6 else: 7 while count-1: 8 if x % count == 0 阅读全文
posted @ 2020-10-16 11:36 龚志军Flagon 阅读(370) 评论(0) 推荐(0) 编辑
摘要: 检测城市、国家的输出情况,添加可灵活判断关键字参数的情况,city_func.py如下: 1 def city_country(city, country, population=0): 2 """返回一个形如'Santiago, Chile' 3 或者'Santiago, Chile -popul 阅读全文
posted @ 2020-10-16 10:27 龚志军Flagon 阅读(98) 评论(0) 推荐(0) 编辑