Python 100练习题[1-10]
2016-12-28 15:22
399 查看
1.. 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
2.. 企业发放的奖金根据利润提成。利润(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,求应发放奖金总数?
3.. 一个整数,它加上100和加上268后都是一个完全平方数,请问该数是多少?
4.. 输入某年某月某日,判断这一天是这一年的第几天?
5.. 输入三个整数x,y,z,请把这三个数由小到大输出
6.. 斐波那契数列
7.. 将一个列表的数据复制到另一个列表中
8.. 输出9*9乘法口诀表
9.. 暂停一秒输出
10.. 暂停一秒输出
import itertools def permutation12341(): result0= list(itertools.permutations('1234', 3)) result1 = [''.join(i) for i in result0] result2 = [int(i) for i in result1] result3 = len(result2) result = {'result':result2, 'length': result3} return result result = permutation12341() print result
2.. 企业发放的奖金根据利润提成。利润(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,求应发放奖金总数?
def bonusfun(x): if (x > 0) and (x <= 100000): return 0.1*x elif (x > 100000) and (x <= 200000): return 1 + 0.075*(x - 10) elif (x > 200000) and (x <= 400000): return 1 + 0.75 + 0.05*(x - 20) elif (x > 400000) and (x <= 600000): return 1 + 0.75 + 0.5 + 0.03*(x - 40) elif (x > 600000) and (x <= 1000000): return 1 + 0.75 + 0.5 + 0.3 + 0.015*(x - 60) else: return 1 + 0.75 + 0.5 + 0.3 + 0.15 + 0.01*(x - 100) result = bonusfun(120000) print result
3.. 一个整数,它加上100和加上268后都是一个完全平方数,请问该数是多少?
result = [] for i in xrange(168): for j in xrange(i, 168): if j*j - i*i == 168: result.append(i*i - 100) print result
4.. 输入某年某月某日,判断这一天是这一年的第几天?
Year = input('Please enter a year: ') Month = input('Please enter a month: ') Day = input('Please enter a day: ') months1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] months2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] if int(Year)%4 == 0 or int(Year)%100 != 0 and int(Year)%400 == 0: result = sum(months2[0:(Month - 1)]) + Day else: result = sum(months1[0:(Month - 1)]) + Day print '%d th day of the year'%result
5.. 输入三个整数x,y,z,请把这三个数由小到大输出
inputData = [] X = input('X(an integer): ') inputData.append(X) Y = input('Y(an integer): ') inputData.append(Y) Z = input('Z(an integer): ') inputData.append(Z) inputData.sort() print inputData
6.. 斐波那契数列
def fib(n): result = [0, 1] for i in xrange(2, n): result.append(result[-2]+result[-1]) return result print fib(10)
7.. 将一个列表的数据复制到另一个列表中
import copy x = [1, 2, 3] y = copy.deepcopy(x) print y
8.. 输出9*9乘法口诀表
for i in xrange(1, 10): for j in xrange(1, 10): print '%d * %d = %d'%(i, j, i*j)
9.. 暂停一秒输出
import time myDict = {1: 'a', 2: 'b'} for key, value in dict.< b829 span class="hljs-keyword">items(myDict): print key, value time.sleep(1)
10.. 暂停一秒输出
import datetime import time print datetime.datetime.now() time.sleep(1) print datetime.datetime.now()
相关文章推荐
- 用python读取cifar-10与cifar-100图像数据
- Numpy学习(2):将cifar10/100数据文件读入到python数据结构(字典)中
- #小练习 输出1到100的质数 分类: python 小练习 2013-10-08 17:45 319人阅读 评论(0) 收藏
- Python练习题 10-1 Python 学习笔记
- Python练习题 10-13 验证用户
- Python练习题 10-11~10-12喜欢的数字
- 10_python_练习题——兔子问题与斐波那契數列
- Python练习题 10-6~10-7乘法练习题
- 用python读取cifar-10与cifar-100图像数据
- python学习——练习题(10)
- Python基础教程(十三):JSON、练习题100题
- Python练习题 10-2 C语言学习笔记
- Python练习题 10-3~10-4 访客问题
- python练习题 1-10
- 10 行代码判定色*情*图片——Python
- (已加马赛克)10 行代码判定色*情*图片——Python 也可以系列之二
- Learning python 系列10
- Python核心编程中的一个游戏练习题,石头剪刀布
- python 核心编程 练习题
- WDS201 2串口RS-232转10/100Base-T(X) + 801.11 b/g无线设备服务器