python练习1

1.使用while循环输入123456 89

#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = 1
while n <11:
  if n==7:
    pass
  else:     
print(n)
  n
= n + 1 print('----end----')

 

2.求1-100的和

#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = 1
s = 0
while n < 101:
  s = s + n
  n = n + 1
print(s)

 

3.输出1-100中的所有偶数

#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = 1
while n < 101:
    temp = n % 2
    if temp = 0:
        print(n)
    else:
        pass
print('----end----')

 

4.求1-2+3-4.....+99的和

#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = 1
s = 0
while n < 101:
  temp
= n % 2
  if temp == 0:      s = s - n
  else:      s = s + n   n = n + 1 print(s)

 

5.用户登录,三次机会!

#!/usr/bin/env python
# -*- coding: utf-8 -*-
count = 0
while count < 3:
    user = input('>>>')
    password = input('>>>')
    if user == 'gxtbest' and password == '123':
        print('欢迎登陆')
        print('..........')
        break
    else:
        print('用户名或者密码错误')
    count = count + 1

 

posted @ 2018-11-13 19:13  GXTbest  阅读(159)  评论(0)    收藏  举报