python 全站开发 (52- 58课)
while 循环2
实例1输出除7以外的1-10的所有数字
分析1条件为除去7
代码实现
s1 = 1
while True
if s1 = = 7:
s1 += 1
print(s1)
if s1 = = 10:
break
s1 += 1
例2输出1-100内所有的正整数之和
b1 = 1
b2 = 0
while True:
print(b1)
b1 = b1 +b2
if b1 = = 100:
break
b1 += 1
print(b1)
例3输出1-100内的所有正整数
s1 = 1
while True:
print(s1)
if s1 = = 100:
break
s1+= 1
例4输出1-100内所有奇数
d1 = 1
while d1< 101
temp = d1%2
if temp = =1: #temp 为余数1 余数为1的为奇数 ,余数为0的为偶数
print(d1)
else:
pass
d1 += 1
例5 输出1-2+3-4+5........99的结果
s =10
c = 1
while c < 100:
temp = c % 2
if temp = =1:
s = s + d
else:
c += 1
print(s)
例6 实现3次登录的实现
i = 0
while i < 3
user = raw_input("username:")
pwd = raw_input("password")
if user = = "akse" and pwd = = "123"
print("yes")
else:
print("no")
i += 1
例7 隐藏明文密码登录
代码实现
import getpass
user = input("username")
password = getpass.getpass("password")
print(username,password)
#j监测登录
_username = "akde"
_password = 123as
if _username = =username and _password = =password
print("chengguong")
else:
print("cuwu")

浙公网安备 33010602011771号