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] == '' and str2.split('.')[1] == '':
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 用(无脑 and 有脑)方式解决小练习的更多相关文章
- python读取hdfs上的parquet文件方式
在使用python做大数据和机器学习处理过程中,首先需要读取hdfs数据,对于常用格式数据一般比较容易读取,parquet略微特殊.从hdfs上使用python获取parquet格式数据的方法(当然也 ...
- python中逐行读取文件的最佳方式_Drupal_新浪博客
python中逐行读取文件的最佳方式_Drupal_新浪博客 python中逐行读取文件的最佳方式 (2010-08-18 15:59:28) 转载▼ 标签: python ...
- 【转】python之配置日志的几种方式
[转]python之配置日志的几种方式 作为开发者,我们可以通过以下3种方式来配置logging: 1)使用Python代码显式的创建loggers, handlers和formatters并分别调用 ...
- python中json格式数据输出实现方式
python中json格式数据输出实现方式 主要使用json模块,直接导入import json即可. 小例子如下: #coding=UTF-8 import json info={} info[&q ...
- python 另一种打开文章的方式——codecs
通常我们使用python打开文件都是 open(‘beijing.txt’)或者是 with open(‘beijing.txt’)as f 那么今天来给你带来一个新的文档打开方式 python的co ...
- Python的with语句(文件打开方式)
Python文件打开方式(with语句) python编程中对于文件的打开方式主要有以下两种: 1.利用直接性的open("","")函数:(举例说明) try ...
- JS杂技之无中间变量的值交换方式
从http://www.cnblogs.com/liuyitian/p/4081517.html#3074553看到一种无中间变量的值交换方式,具体如下: var a = 1;var b = 2;a ...
- Python调用API接口的几种方式 数据库 脚本
Python调用API接口的几种方式 2018-01-08 gaoeb97nd... 转自 one_day_day... 修改 微信分享: 相信做过自动化运维的同学都用过API接口来完成某些动作.AP ...
- Python进阶----线程基础,开启线程的方式(类和函数),线程VS进程,线程的方法,守护线程,详解互斥锁,递归锁,信号量
Python进阶----线程基础,开启线程的方式(类和函数),线程VS进程,线程的方法,守护线程,详解互斥锁,递归锁,信号量 一丶线程的理论知识 什么是线程: 1.线程是一堆指令,是操作系统调度 ...
随机推荐
- strace命令 二
让我们看一台高负载服务器的 top 结果: top 技巧:运行 top 时,按「1」打开 CPU 列表,按「shift+p」以 CPU 排序. 在本例中大家很容易发现 CPU 主要是被若干个 PHP ...
- vue入门|ElementUI使用指南
vue入门|ElementUI使用指南 1.开发前务必熟悉的文档: vue.js2.0中文,项目所使用的js框架 vue-router,vue.js配套路由 vuex 状态管理 Element UI框 ...
- python 处理geoJson to shp 互转
- 效率包括了代码的GC 大小与内存大小,执行速度等等。其中执行速度不是关注 的重点
效率包括了代码的GC 大小与内存大小,执行速度等等.其中执行速度不是关注的重点
- ubuntu二进制包安装openresty
date: 2019-08-01 17:59:59 author: headsen chen # 导入我们的 GPG 密钥: wget -qO - https://openresty.org/pack ...
- numpy linspace
https://www.cnblogs.com/antflow/p/7220798.html numpy.linspace(start, stop, num=50, endpoint=True, re ...
- leetcode 874. Walking Robot Simulation
874. Walking Robot Simulation https://www.cnblogs.com/grandyang/p/10800993.html 每走一步(不是没走commands里的一 ...
- OpenGL ES3使用MSAA(多重采样抗锯齿)的方法
昨晚花费了我2个多小时的时间终于把OpenGL ES3.0中的MSAA给搞定了.在OpenGL ES2.0中,Khronos官方没有引入标准的MSAA全屏抗锯齿的方法,而Apple则采用了自己的GL_ ...
- ASP将Table导出Excel
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><%if request("action") ...
- Opencv拉普拉斯算子做图像增强
Opencv拉普拉斯算子——图像增强 #include <iostream> #include <opencv2/opencv.hpp> using namespace std ...