标签:pytho pwd 循环 else pre int and 三次 env
#!/usr/bin/env python
num = 1
while num <= 10:
if num != 7:
print(num)
num+=1
#!/usr/bin/env python
sum = 0
num = 1
while num <= 100:
sum = sum + num
num = num + 1
print(sum)
#!/usr/bin/env python
num = 1
while num <= 100:
if num % 2 != 0:
print(num)
num =num + 1
#!/usr/bin/env python
num = 1
while num <= 100:
if num % 2 == 0:
print(num)
num =num + 1
5.计算1-2+3=4+5.....99的和。
#!/usr/bin/env python
num = 1
sum1 = 0
sum2 = 0
while num < 100:
temp = num % 2
if temp != 0:
sum1 += num
else:
sum2 += num
num += 1
print(sum1-sum2)
6.用户登陆(三次重试机会)
#!/usr/bin/env python
count = 0
while count < 4:
user = input("请输入用户名:")
pwd = input("请输入密码:")
if user == ‘root‘ and pwd == ‘root‘:
print("登陆成功!")
else:
print("用户名或密码错误,请重新输入!")
count += 1
print("超过重试次数限制,登陆失败!")
标签:pytho pwd 循环 else pre int and 三次 env
原文地址:https://blog.51cto.com/magic3/2506393