摘要: a = 5 b = 6 c = 1 def max_num(): re = (a if a>b else b)if(a if a>b else b)>c else c rt = (a if a<b else b)if(a if a<b else b)<c else c return re,rt l 阅读全文
posted @ 2020-07-21 16:21 kaiyaoweixiao 阅读(234) 评论(0) 推荐(0) 编辑
摘要: def list1(): ''' 查看元素是否在列表中,存在就返回位置,不存在就返回-1 :return: index ''' l = [1, 2, 3, 4, 5, 6] for i in range(len(l)): if l[i] == 2: return i return -1 re = l 阅读全文
posted @ 2020-07-21 15:20 kaiyaoweixiao 阅读(249) 评论(0) 推荐(0) 编辑
摘要: # dic = dict(('name','apple')) # Unexpected type(s): \ # (Tuple[str, str])报错 # Possible types: (Mapping) \ # (Iterable[Tuple[Any, Any]]) #可迭代对象必须是映射关系 阅读全文
posted @ 2020-07-21 10:24 kaiyaoweixiao 阅读(373) 评论(0) 推荐(0) 编辑
摘要: >>> a = [1,2,3,4,5,6,7,8,9,0] >>> n = 3 >>> c= [a[i:i+n] for i in range(0, len(a), n)] 阅读全文
posted @ 2020-07-20 21:04 kaiyaoweixiao 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 定义函数是聚合,调用函数是打散。 def list(*a): print(a) list(*[1,2,3]) #(1,2,3) print(*a) #1 2 3 阅读全文
posted @ 2020-07-15 15:59 kaiyaoweixiao 阅读(145) 评论(0) 推荐(0) 编辑
摘要: l1 = [] l = list() for k in range(3): for i in range(4): l.append(int(input(f'请输入第{i+1}人成绩:'))) print( sum(l)//len(l)) l1.append(l) print(l1) 阅读全文
posted @ 2020-07-14 11:09 kaiyaoweixiao 阅读(347) 评论(0) 推荐(0) 编辑
摘要: # 让一个数字和他相邻的数字比较, # 如果前一个数字大于后一个数字,交换两个数据的位置 nums = [3, 2, 1, 6, 5, 4] j = 0 while j < len(nums) - 1: flag = True # 假设每一趟都没换行 i = 0 while i < len(nums 阅读全文
posted @ 2020-07-13 11:32 kaiyaoweixiao 阅读(118) 评论(0) 推荐(0) 编辑
摘要: #九九乘法表 #i = 0 #控制内循环 j = 0# 控制外循环 while j < 9: j += 1 i = 0 while i < j: i += 1 print(f'{i}*{j}={i * j}',end ='\t ',sep='') print() ''' ''' for i in r 阅读全文
posted @ 2020-07-13 11:30 kaiyaoweixiao 阅读(101) 评论(0) 推荐(0) 编辑
摘要: max_num = int(input('请输入一个数:')) while True: num = int(input('请在输入一个数:')) if num > max_num: max_num = num else: if num == 0: break print(max_num) 阅读全文
posted @ 2020-07-13 11:26 kaiyaoweixiao 阅读(124) 评论(0) 推荐(0) 编辑
摘要: li = [i for i in range(1,101)] start_index = 0 end_index = len(li)-1 num = int(input('您要找的数是:') while start_index <= end_index : mid_index = (start_in 阅读全文
posted @ 2020-07-13 11:21 kaiyaoweixiao 阅读(132) 评论(0) 推荐(0) 编辑