设为首页 加入收藏

TOP

Python 用(无脑 and 有脑)方式解决小练习
2019-07-25 14:21:13 】 浏览:56
Tags:Python 无脑 and 有脑 方式 解决 练习
 题目:企业发放的奖金根据利润提成。
利润(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))

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python进阶:GIL(全局解释器锁) 下一篇内置函数 Ⅰ

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目