Python100例 我的实现展示(1-5例)

这篇博客展示了Python编程的前5个实例,包括基础的列表和字符串操作。作者提供了详细的实现代码,并鼓励读者阅读其总结文章以获取全部100例,同时欢迎大家提出反馈和讨论。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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例代码,欢迎阅读,吐槽已经讨论谢谢各位。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿尔卑斯的畅想

欢迎打赏,一起每天进步一点点!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值