标签:python
#使用while循环输入1 2 3 4 5 6 8 9 10
num = 1
while num <=11:
if num == 7 or num == 11:
num += 1
continue
print(num)
num += 1
#输出 1-100 内的所有奇数
num = 1
while num <= 100:
if num % 2 == 1:
print(num)
num += 1
#输出 1-100 内的所有偶数
num = 1
while num <= 100:
if num %2 == 0:
print(num)
num += 1
#求1-2+3-4+5 ... 99的所有数的和
a = ‘‘
b = 0
for i in range(1,100):
a += str(i)
if i % 2 == 0:
a += ‘+‘
b -= i
else:
a += ‘-‘
b += i
print(‘输出: \r\n %s \r\n计算结果:\r\n %s‘ % (a.rstrip(‘-‘),b))
用户登陆(三次机会重试)
name="LJS"
pswd="123"
i=1
while i < 4:
input_name = input("Username:")
input_pswd = input("Password:")
if input_name == name and input_pswd == pswd:
print("Welcome to my program!")
break
else:
print("The user name or password you entered is incorrect. Please enter again.")
i += 1
continue
标签:python
原文地址:http://blog.51cto.com/shengge520/2112752