Python学习笔记(八)Python练习题一

1.使用while循环输出1.2.3.4.5.6.8.9.10

2.求1-100的所有数之和

3.输出1-100的内所有奇数

4.输出1-100内的所有偶数

5.求1-2+3-4+5.。。。99之和

6.用户登录(3次机会)

解答:

1. 

#!/usr/bin python
#-*-coding:utf8-*-
count = 1
while count <=10:
    if count!=7:
        print(count)
    count=count+1
"""
或者 if count == 7:
pass
else:
print(count)

 2.

#!/usr/bin python
#-*-coding:utf8-*-
count=1
n=1
while count<100:
    count=count+1
    n=n+count
print(n)

 3.

#!/usr/bin python
#-*-coding:utf8-*-
count=1
n=1
while count<99:
   count=count+2
  print(n)
"""
count=0
while count<100:
  count=count+1
  if count%2 ==0:
pass
else:
print(count)

4.

#!/usr/bin python
#-*-coding:utf8-*-
count=2
n=2
while count<100:
    count=count+2
    n=n+count
print(n)
"""
count=0
while count<100:
  count=count+1
  if count%2 ==0:
print(count)
else:
 pass

 5.

#!/usr/bin python
#-*-coding:utf8-*-
count=1
n=1
while count<99:
    count=count+1
    if count%2 == 0:
        n=n-count
    else:
        n=n+count
print(n)

 6

#!/usr/bin python
#-*-coding:utf8-*-
count=3
while count!=0:
    count=count-1
    inp1=input("请输入用户:")
    inp2=input("请输入密码:")
    if inp1=="zengtao":
        if inp2=="zt":
            print("正确,欢迎",inp1)
            count=0
        else:
            print("密码错误,请重试")
            print("您还有",count,"次机会")
    else:
        print("用户或密码错误,请重试")
        print("您还有",count,"次机会")
"""
count = 0
        while count < 3:
            user = input('>>>')
            pwd = input('>>>')
            if user == 'alex' and pwd == '123':
                print('欢迎登陆')
                print('..........')
                break
            else:
                print('用户名或者密码错误')
            count = count + 1

 补充:

字符型数字转换为数字

inp=int()

posted @ 2019-02-13 19:50  魅力无法挡  阅读(220)  评论(0编辑  收藏  举报