程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2023-06(1)

Python 用(无脑 and 有脑)方式解决小练习

发布于2019-08-06 11:39     阅读(973)     评论(0)     点赞(3)     收藏(1)


 题目:企业发放的奖金根据利润提成。
利润(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,求应发放奖金总数?
第一种:
I = float(input("请输入你的利润(万元):"))
bonu = 0
if I <= 10:
    bonu = I * 10000 * 0.1
elif I > 10 and I <= 20:
    bonu = 100000 * 0.1 + (I - 10) * 100000 * 0.075
elif I > 20 and I <= 40:
    bonu = 100000 * 0.1 + 100000 * 0.075 + (I - 20) * 100000 * 0.05
elif I > 40 and I <= 60:
    bonu = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (I - 40) * 100000 * 0.03
elif I > 60 and I <= 100:
    bonu = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 60) * 100000 * 0.015
elif I > 100:
    bonu = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (I - 100) * 10000 * 0.01

print("你的奖金是:", bonu)

第二种:

i = int(input('净利润:'))
arr = [1000000,600000,400000,200000,100000,0]
rat = [0.01,0.015,0.03,0.05,0.075,0.1]
bonu = 0
for idx in range(0, 6):
    if i > arr[idx]:
        bonu += (i - arr[idx]) * rat[idx]
        # print((i - arr[idx]) * rat[idx])
        i = arr[idx]

print(bonu)

 

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

第一种直接破解:
import math
x = 0
while True:
    # if isinstance(math.sqrt(x + 100), int) and  isinstance(math.sqrt(x + 268), int):
    #     print(x)
    str1 = str(math.sqrt(x + 100))
    str2 = str(math.sqrt(x + 268))

    if str1.split('.')[1] == '0' and str2.split('.')[1] == '0':
        print(x)
 
    x += 1

本来想用isinstance来判断是否是整形,但是python3的计算出来的整数后面会带有.0所以还是一个float类型就不能区分了,所以就用了str里面的split函数。

虽然可以得出结果但是没有退出条件,会一直执行下去。

第二种温和解决:

x + 100 = n2

x + 268 = m2

m2 - n2 = 168

(m + n) * (m - n) = 168

i = m + n   

j = m - n

i * j = 168  i 和 j 至少有一个是偶数 

m = (i + j) / 2

n = (i - j) / 2

m 、i、j、 n 都是偶数 

for i in range(1, 85):
    if 168 % i == 0:
        j = 168 / i
        if i < j and (i + j) % 2 == 0 and (i - j) % 2 == 0:
            m = (i + j) / 2
            n = (i - j) / 2
            y = n * n - 100
            print(y)

 3、输入某年某月某日,判断这一天是这一年的第几天

year = int(input('请输入年份:'))
month = int(input('请输入月份:'))
day = int(input('请输入几号:'))
#days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days = [0, 31, 59, 90, 120, 151, 181, 212, 244, 274, 305, 335]
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0 :
    if month > 2:
        year_day = days[month - 1] + day + 1
    else:
        year_day = days[month - 1] + day
else:
    year_day = days[month - 1] + day

print('{}-{}-{}:是今年的第{}天'.format(year, month, day, year_day))

第二种用time模块

import time

year = int(input('请输入年份:'))
month = int(input('请输入月份:'))
day = int(input('请输入几号:'))
tuple_time = time.strptime('{}-{}-{}'.format(year, month, day), '%Y-%m-%d')
print('{}-{}-{}是今年的第{}天'.format(year, month, day, tuple_time.tm_yday))

 



所属网站分类: 技术文章 > 博客

作者:可以给我吃一口吗

链接:https://www.pythonheidong.com/blog/article/8467/1cce5797763c364a241e/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

3 0
收藏该文
已收藏

评论内容:(最多支持255个字符)