Python练习题1-5整理

题目一

有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?

a=0
for i in range(1,5):
    for j in range(1,5):
        for k in range(1,5):
            if i != j and i != k and j != k:
                a+=1
                print(i,j,k)

题目二

企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?

l=float(input('请输入当月利润l(万元):'))
if l<=10:
    s=l*0.1
elif l<20:
    s=10 * 0.1 + (l-10) * 0.075
elif l<40:
    s=10 * 0.1 + 10 * 0.075 + (l-20) * 0.05
elif l<60:
    s=10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (l-40) * 0.03
elif l<100:
    s=10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + (l-60) * 0.015
else:
    s=10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + 40 * 0.015 + (l-100)*0.01
print(s)

题目三

一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

for a in range(1,85):
    if 168 % a == 0:
        b = 168 / a;
        if  a>b and (a+b) % 2 == 0 and (a-b) % 2 == 0:
            x = (a+b)/2
            y = (a-b)/2
            s = y **2-100
            print(s)

题目四

输入某年某月某日,判断这一天是这一年的第几天?
这道题出现了一些问题,最开始我将题目理解为按照大小月划分,结果代码确实成功运行了,但是答案是错误的。
错误代码:

year=int(input('请输入年份:'))
month=int(input('请输入月份:'))
day=int(input('请输入日:'))
if year%4==0 or year%400==0:
    f=29
else:
    f=28
range = [0, 31, f, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
s=0
for i in range:[0,month]
s=s+i
today=s+day
print('%d 月 %d 日是 %d 年的第 %d 天。' % (month,day,year,today))

改进后:

year=int(input('请输入年份:\n'))
month=int(input('请输入月份:\n'))
day=int(input('请输入日:\n'))
months = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334)
if 0<month<=12:
    s=months[month-1]
else:
    print('data error')
s+=day
stemp = 0
if year%400 == 0 or ((year % 4 == 0) and (year % 100 != 0)):
    stemp=1
if (stemp==1) and (month>2):
    s+=1
print('是这一年的第%d天。' % s)

这道题还可以用 datetime.date()方法
用法:targetDay = datetime.date(year, month, day)
采用date类型的对象的方法,并且date类型对象之间可以相减,返回值是俩者之间的间隔的天数

题目五

输入三个整数x,y,z,请把这三个数由小到大输出

a=[]
for i in range(3):
    b=int(input('输入一个数:\n'))
    a.append(b)
    a.sort()
print(a)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

被窝探险家104

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值