摘要: 列表中先给定两个数字,后面的数字总是前两个数字之和。 阅读全文
posted @ 2019-05-14 18:13 hejp 阅读(231) 评论(0) 推荐(0) 编辑
摘要: print(list(range(10))) # 从0开始到10 print(list(range(6,11))) # 从6开始到10 print(list(range(1,10,2))) # 从1到10之间,取步长为2的值 print(list(range(10,0,-1))) # 步长-1,倒数。 sum100 = 0 for i in range(1,101): # pr... 阅读全文
posted @ 2019-05-14 18:09 hejp 阅读(449) 评论(0) 推荐(0) 编辑
摘要: astr = 'hello' alist = [10,20,30] atuple = ('bob','tom','alice') adict = {'name':'john','age':23} for ch in astr: print(ch) for i in alist: print(i) for name in atuple: print(name) fo... 阅读全文
posted @ 2019-05-14 17:07 hejp 阅读(941) 评论(0) 推荐(0) 编辑
摘要: 计算100以内偶数之和。 是余数的话就执行continue,跳过本次循环剩余部分。是偶数的话就直接执行 sum100 += conuter 进行累加 sum100 = 0 counter = 0 while counter < 100: counter += 1 # if counter % 2 == 1: continue sum100 += ... 阅读全文
posted @ 2019-05-14 15:19 hejp 阅读(1283) 评论(0) 推荐(0) 编辑
摘要: break是结束循环,break之后、循环体内代码不再执行。 阅读全文
posted @ 2019-05-14 13:58 hejp 阅读(1075) 评论(0) 推荐(0) 编辑
摘要: 累计从1加到100的和 阅读全文
posted @ 2019-05-14 12:46 hejp 阅读(2759) 评论(0) 推荐(0) 编辑
摘要: import random num = random.randint(1,10) counter = 0 while counter num: print('猜大了') elif answer < num: print('猜小了') else: print('猜对了') break counter += ... 阅读全文
posted @ 2019-05-14 12:39 hejp 阅读(153) 评论(0) 推荐(0) 编辑
摘要: import random num = random.randint(1,10) running = True while running: answer = int(input('guess the number: ')) if answer > num: print('猜大了') elif answer < num: print('猜... 阅读全文
posted @ 2019-05-14 12:25 hejp 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 去掉重复的代码,结果输出字体增加颜色。 import random all_choice = ['石头','剪刀','布'] win_list = [['石头','剪刀'],['剪刀','布'],['布','石头']] prompt = '''(0) 石头 (1) 剪刀 (2) 布 请选择(0/1/2): ''' computer = random.choice(all_choice) ind ... 阅读全文
posted @ 2019-05-14 09:58 hejp 阅读(166) 评论(0) 推荐(0) 编辑