python简单练习2

来源:互联网 发布:aim 霹雳 知乎 编辑:程序博客网 时间:2024/06/16 18:03


12. py 判断工作日和周末

# coding=utf-8



a = int(input("Please input a number:"))
if a==6 or a==7:
    print("周末")
elif a>=1 and a<=5:
    print("工作日")
else:

    print("错误")


13.py while计算阶乘

# coding =utf-8


a = int(input("Please input a number:"))
i = 1
mul = 1
while i<=a:
    mul *=i
    print("%d--%d"%(i,mul))
    i+=1
print(mul)

14.py for逐个输出字符串

#coding =utf-8


a = str(input("Please input a string:"))


for x in a:
    if x == 'b':
       x = upper(x)
    print(x)

15.py 计算IBMI值

#coding = utf-8


# input weight:
m = float(input("Please input your weight(kg):"))
h = float(input("Please input your hight(m):"))
BMI = m/h**h
if BMI < 18.5:
    print("过轻")
elif BMI>= 18.5 and BMI<=25:
    print("正常")
elif BMI>= 25 and BMI<=28:
    print("过重")
elif BMI>= 28 and BMI<=32:
    print("肥胖")
elif BMI>= 32:
    print("严重肥胖")

16.py 用户登录

#coding=utf-8


name = str(input("请输入用户名:"))
passwd = str(input("请输入密码:"))


while (name != "python" or passwd != "123456"):
    print("输入错误!请重新输入:")
    name = str(input("请输入用户名:"))
    passwd = str(input("请输入密码:"))
print("欢迎光临")

17.py 两个直角三角形对接

# coding = utf-8


#n = int(input("Please input a integer above 4:"))
n = 5
j=1
while j<=2*n-1:
    i = 0
    while i<(n-abs(n-j)):
        print("*",end="")
        i+=1
    j+=1
    print()

18.py 猜拳游戏玩家要胜

#coding = utf-8


player = 0
computer = 0
import random
while (player==0 and computer!=1)or(player==1 and computer!=2)or(player==2 and computer!=0):
      player = int(input("石头(0),剪刀(1),布(2):"))
      computer = random.randint(0,2)
      print("player:%d computer:%d"%(player,computer))
print("玩家终于胜了")

19.py 计算个人所得税——升级为调用函数


def cal_tax():
    #coding=utf-8
    #输入工资
    salary = float(input("请输入工资:"))
    #定义应交税额变量
    tax = 0.0
    #           税率介绍
    #超过1500元4500的部分税率为10%
    #超过4500元9000的部分税率为20%
    #超过9000元35000的部分税率为25%
    #超过350004至55000的部分税率为30%
    #超过550004至80000的部分税率为35%
    #超过80000的部分税率为40%


    #若工资不超过1500元,应缴税为 工资×3%
    if salary <=1500:
       tax += salary*0.03
       print("工资:%f  税额:%f"%(salary,tax))


    #若工资在1500到4500之间,应缴税为 1500×3% + (工资-1500)×10%
    elif salary >1500 and salary <=4500:
        tax = 1500*0.03 + (salary-1500)*0.1
        print("工资:%f  税额:%f"%(salary,tax))


    #若工资在1500到9000之间,应缴税为 1500×3% + (4500-1500)×10% + (工资-4500)×20%
    elif salary >4500 and salary <=9000:
        tax = 1500*0.03 + 3000*0.1 + (salary-4500) *0.2
        print("工资:%f  税额:%f"%(salary,tax))


    #若工资在9000到35000之间,应缴税为 1500×3% + (4500-1500)×10% + (9000-4500)×20% + (工资-9000)×25%
    elif salary >9000 and salary <=35000:
        tax = 1500*0.03 + 3000*0.1 + (9000-4500)*0.2+(salary-9000)*0.25
        print("工资:%f  税额:%f"%(salary,tax))


    #若工资在35000到55000之间,应缴税为 1500×3% + (4500-1500)×10% + (9000-4500)*20% + (35000-9000)×25% + (工资-35000)*30%
    elif salary >35000 and salary <=55000:
        tax = 1500*0.03 + 3000*0.1 + (9000-4500)*0.2+(35000-9000)*0.25+(salary-35000)*0.3
        print("工资:%f  税额:%f"%(salary,tax))


    #若工资在55000到80000之间,应缴税为 1500×3% + (4500-1500)×10% + (9000-4500)*20% + (35000-9000)×25% + (550000-35000)*30% + (工资-55000)×35%
    elif salary >55000 and salary <=80000:
        tax = 1500*0.03 + 3000*0.1 + (9000-4500)*0.2+(35000-9000)*0.25+(55000-35000)*0.3 + (salary-55000)*0.35
        print("工资:%f  税额:%f"%(salary,tax))


    #若工资超过80000,应缴税为 1500×3% + (4500-1500)×10% + (9000-4500)*20% + (35000-9000)×25% + (550000-35000)*30% + (80000-55000)×35% + (工资-80000)×40%
    elif salary >80000:
        tax = 1500*0.03 + 3000*0.1 + (9000-4500)*0.2 + (35000-9000)*0.25+(55000-35000)*0.3 + (80000-55000)*0.35 + (salary-80000)*0.4
        print("工资:%f  税额:%f"%(salary,tax))




cal_tax()

20.py 过7游戏

#coding= utf-8


#定义变量i
i=1


#进入循环:i从1-100
while i<=100:
#判断i是否被7整除,若不整除,则打印出来
    if i%7!=0:
        print(i)
    i+=1

21.py  打印名片

#/usr/bin/python3
#coding = utf-8


name = str(input("Please input your name:" )) 
gender = str(input("Please input your gender:"))
age = int(input("Please input your age:" ))
Company = str(input("Please input your work unit:"))
Mobile = int(input("Please input your mobile phone number:")) 
E_mail = str(input("Please input your email:"))


print("====================")
print("姓名:%s    性别:%s    年龄:%d\n工作单位:%s\n手机号码:%d\n邮箱:%s"%(name,gender,age,Company,Mobile,E_mail))
print("====================")

22.py 判断闰年

#/usr/bin/python3
#coding = utf-8


year = int(input("Please input the year:"))
if (year % 4 == 0 and year % 100 != 0 ) or ( year % 400 == 0):
    print("%d is Run Nian"%year)
else: 
    print("%d is not Run Nian"%year)

23.py 判断三数字之和大小

#/usr/bin/python3
#coding = utf-8


a = float(input("Please input number1:"))
b = float(input("Please input number2:"))
c = float(input("Please input number3:"))
sum = a+b+c
print(sum)
'''if sum>100000.0:
   print("您输入的三个数的和忒大了")
if sum>10000.0 and sum<100000.0:
   print("您输入的三个数的和挺大")
if sum>1000.0 and sum<10000.0:
   print("您输入的三个数的和有点大")
if sum>100.0 and sum<1000.0:
   print("您输入的三个数的和不算大")
'''
if sum>100000.0:
   print("您输入的三个数的和忒大了")
elif sum>10000.0:
     print("您输入的三个数的和挺大")
elif sum>1000.0:
     print("您输入的三个数的和有点大")
elif sum>100.0:
   print("您输入的三个数的和不算大")
elif sum<=100:
   print("您输入的三个数的和有点小")

24.py 认证程序

#coding = utf-8


usrName = str(input("请输入用户名:"))
passwd = str(input("请输入密码:"))


if usrName == "fanfen" and passwd == "fanfen88":
    print("亲爱的fanfen,欢迎登陆爱学习管理系统")
else:
    print("用户名或密码不正确")



原创粉丝点击