一、while ... else 方法
while else 的作用就是,确定循环正确执行完毕,else里面可以提示完成的情况。
二、练习题
1、编译型语言是编译完之后执行,解释性语言是边编译边执行,编译型语言有 java 、c ,解释型语言 有python
2、在解释器里运行代码,用解释器运行python 文件
3、单行注释用‘‘ "" 都可以 多行只能用 """" """
4、True False
5、注意变量名称不能以数字开头,不能有特殊符号,变量名不能词不达意,官方建议变量名称使用下划线 如 your_name = "SmallNine"
6、id函数 具体使用 id()
7、
count = 0 user = "seven" user_1 = "alex" password = "123" while count < 3: user_ipt = input("输入你的账号") user_pw = input("输入你的密码") if user_ipt == user or user_ipt == user_1 and user_pw == password : print(user_ipt,"登录成功") break elif user_ipt != user or user_ipt != user_1 and user_pw != password : print("用户名密码输入错误") count += 1
8、
a)
count = 1 num = 0 while count <= 100: if count%2 ==0: num = num + count else: num = num - count count += 1 print(num)
b)
count = 0 while count <=12 : if count == 6: pass elif count == 10: pass else: print(count) count += 1
C)
count = 0
num =100
while count < 102 :
print(num)
if count < 50:
num -= 1
elif count == 50 :
num =0
else:
num +=1
count +=1
D)
count = 0 while count < 100 : if count%2 ==1: print(count) count +=1
E)
count = 0 while count <100 : if count % 2 ==0: print(count) count += 1
9、
n2 指向的是n1的内存地址也就是 123456
(1)、
user = input("姓名: ") local = input("地点: ") like = input("爱好: ") info = """ 敬爱的 %s 在 %s %s """%(user,local,like) print(info)
(2)、
while True: user = int(input("输入年份")) if user %4 == 0 and user % 100 != 0: print(user,"是闰年") elif user %400 == 0: print(user,"是闰年") else: print("不是呦")
(3)、
user = 0.0325 mn = 10000 year = 0 num = 0 while num < 20000: print(year) count = mn * user num = count + mn print(num) mn = num year += 1