python的练习
1、1-100的和
#!/usr/bin/env python
# -*- coding:utf8 -*-
n = 1
s = 0
while n < 101:
s = s + n
n = n + 1
print(s)
2、1-100的奇数和
n=1
s=0
while n < 101 :
a = n % 2
n = n + 1
if a == 0 :
pass
else :
s = s + n
print (s)
3、1-100的偶数之和
n=1
s=0
while n < 101 :
a = n % 2
n = n + 1
if a == 0 :
s = s + n
else :
pass
print (s)
4、0-100偶数加,奇数减如:0-1+2-3+4......
n=1
s=0
while n < 101 :
a = n % 2
n = n + 1
if a== 0 :
s = s + n
else :
s = s - n
print (s)
5、三次登陆不成功就退出来
count = 0
while count < 3:
user = input('>>>')
pwd = input('>>>')
if user == 'alex' and pwd == '123':
print('欢迎登陆')
print('..........')
break
else:
print('用户名或者密码错误')
count = count + 1