# 随堂练习 age = int(input("请输入年龄:")) if age >= 22 and age <= 35: print("可以结婚") else: print("拖出去枪毙") print("==================================================") # 练习2 age = int(input("请输入年龄:")) sick = input("是否患有老年痴呆\n") if age >= 70 or sick == "是": print("不能开车") else: print("可以开车")
# 使用while循环实现 0-100 相加 i = 0 s = 0 while i < 100: i += 1 s += i print(s) ''' 第1次循环 i = 0,s += i = 0 + 0 = 0,s = 0,i = 1 第2次循环 i = 1,s += i = 0 + 1 = 1,s = 1,i = 2 第3次循环 i = 2,s += i = 1 + 2 = 3,s = 3,i = 3 。。。 第99次循环 i = 99,s += i = 4851 + 99 = 4950,s = 4950,i = 100 第100次循环 i = 1,s += i = 4950 + 100 = 5050,s = 5050,i = 101 ''' ''' 1、 将0-100所有3的倍数相加 2、 将0-100所有3的倍数相加 含3相加 3、 基数排序 46,37,42 37,46,42 37,42,46 使