Python100例 我的实现展示(1-5例)
'''1、有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?'''
import math
def test_exam_01():
list_x = []
for a in range(1, 5):
for b in range(1, 5):
if a != b:
for c in range(1, 5):
if a != c and b != c:
list_x.append(a * 100 + b * 10 + c)
print("四个数字:1、2、3、4,能组成{0}个互不相同且无重复数字的三位数".format(str(len(list_x))))
print(list_x)
'''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 test_exam_02():
total = 0
s = int(input("请输入当月利润(单位:万元),将计算出发放奖金总数:"))
if s <= 10:
total += s * 0.1
elif s <= 20:
total += (s - 10) * 0.075 + 10 * 0.1
elif s <= 40:
total += (s - 40) * 0.05 + (20 - 10) * 0.075 + 10 * 0.1
elif s <= 60:
total += (s - 60) * 0.03 + (40 - 20) * 0.05 + (20 - 10) * 0.075 + 10 * 0.1
elif s <= 100:
total += (s - 60) * 0.015 + (60 - 40) * 0.03 + (40 - 20) * 0.05 + (20 - 10) * 0.075 + 10 * 0.1
else:
total += (s - 100) * 0.01 + + (100 - 60) * 0.015 + (60 - 40) * 0.03 + (40 - 20) * 0.05 + (
20 - 10) * 0.075 + 10 * 0.1
print("输入的当月利润是%.2f万元,计算出来的发放奖金总数为%.2f万元" % (s, total))
def test_exam_02x():
total = 0
s = int(input("请输入当月利润(单位:万元),将计算出发放奖金总数:"))
a = [10, 20, 40, 60, 100]
b = [0.1, 0.075, 0.05, 0.03, 0.015, 0.01]
for i in range(len(b)):
if i != len(a):
if s <= a[i]:
total += (s - a[i - 1]) * b[i]
break
else:
if i == 0:
total += a[i] * b[i]
elif i < len(a):
total += (a[i] - a[i - 1]) * b[i]
else:
total += (s - a[-1]) * b[i]
print("输入的当月利润是%.2f万元,计算出来的发放奖金总数为%.2f万元" % (s, total))
'''3、一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?'''
def test_exam_03():
for i in range(1000):
for h in range(1000):
if i + 100 == math.pow(h, 2):
for j in range(1000):
if i + 168 == math.pow(j, 2):
print(str(i) + " + 100 = " + str(h) + "^2")
print(str(i) + " + 168 = " + str(j) + "^2")
print(i)
break
'''4、输入某年某月某日,判断这一天是这一年的第几天?'''
def test_exam_04():
str1 = input("输入某年某月某日格式为{年-月-日},程序判断这一天是这一年的第几天?\n").split("-")
x = list(map(int, str1))
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
total = 0
if x[1] == 1:
total = x[2]
elif 1 < x[1] < 13:
total += x[2]
for i in range(x[1] - 1):
total += days[i]
if x[0] % 4 == 0 and x[0] % 100 != 0:
total += 1
else:
print("输入的月份不规范,请重新执行程序!")
print(total)
print("输入的日期为:{0}年{1}月{2}日,这一天是这一年的第{3}天。".format(str1[0], str1[1], str1[2], str(total)))
'''5、输入三个整数x,y,z,请把这三个数由小到大输出。'''
def test_exam_05():
str1 = input("输入三个整数x,y,z以空格隔开,程序将把这3个数有小到大输出。\n").split(" ")
x = list(map(int, str1))
x.sort()
print(x)
if __name__ == '__main__':
# test_exam_01()
# test_exam_02()
# test_exam_02x()
# test_exam_03()
# test_exam_04()
test_exam_05()
另有一篇总结文章(链接:https://blog.csdn.net/supassxu/article/details/112756398)包含所有的100例代码,欢迎阅读,吐槽已经讨论谢谢各位。