Python 100练习题[1-10]

1.. 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?

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.items(myDict):
    print key, value
    time.sleep(1)

10.. 暂停一秒输出

import datetime
import time

print datetime.datetime.now()
time.sleep(1)
print datetime.datetime.now()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值