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.线程是一堆指令,是操作系统调度 ...
随机推荐
- polarssl rsa & aes 加密与解密<转>
上周折腾加密与解密,用了openssl, crypto++, polarssl, cyassl, 说起真的让人很沮丧,只有openssl & polarssl两个库的RSA & AES ...
- Spring boot+Vue全栈开发---Spring Boot文件上传
https://blog.csdn.net/Day_and_Night_2017/article/details/86980743 文件上传涉及到两个组件:CommonsMultipartResolv ...
- NAXSI means Nginx Anti XSS & SQL Injection. NAXSI is an open-source, high performance, low rules maintenance WAF for NGINX
nbs-system/naxsi: NAXSI is an open-source, high performance, low rules maintenance WAF for NGINXhttp ...
- 页面的Tab选项卡 简单实例
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- nginx多层反向代理获取客户端真实ip
访问路径: 用户 --> www.chinasoft.cn(nginx反向代理) --> www.chinasoft.com(nginx反向代理) --> python服务端程序 经 ...
- shell编程系列23--shell操作数据库实战之mysql命令参数详解
shell编程系列23--shell操作数据库实战之mysql命令参数详解 mysql命令参数详解 -u 用户名 -p 用户密码 -h 服务器ip地址 -D 连接的数据库 -N 不输出列信息 -B 使 ...
- Python“文件操作”Excel篇(上)
大家好,我们今天来一起探索一下用Python怎么操作Excel文件.与word文件的操作库python-docx类似,Python也有专门的库为Excel文件的操作提供支持,这些库包括xlrd.xlw ...
- EXCEL导入配置开发
1.登录infor 企业级 选择 配置 EXCEL导入配置 2.新增配置(设置模板名.说明.存储过程名称.应用仓库) 后保存 3.将excel模板放到服务器 路径:/opt/infor/sce/wil ...
- 【JAVA】java注解的自定义和使用
java注解概念 Java提供了一种原程序中的元素关联任何信息和任何数据的途径和方法 java注解介绍 常用注解 @Override:表示方法是重写的方法 @Deprecated:过时的方法 @Sup ...
- 【434】COMP9024 Exercises Revision
目录: Week01 Week02 Week03 Week04 Week05 Week06 Week07 Week08 Week09 Week10 01. Week01 数字通过 #define 来定 ...