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

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

import calendar
import math
import random
import time
import turtle
from collections import Counter
from tkinter.ttk import Style

from click._compat import raw_input
from colorama import Back, Fore
from tkinter import *

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


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)


'''6、斐波那契数列。'''


def test_exam_06():
    x = int(input("请输入整数x,程序将输出长度为x的斐波那契数列。\n"))
    list_x = [0, 1]
    for i in range(2, x):
        list_x.append(list_x[i - 2] + list_x[i - 1])
    print("长度为{0}的斐波那切数列如下:".format(str(x)))
    print(list_x)


'''7、将一个列表的数据复制到另一个列表中。'''


def test_exam_07():
    x = int(input("请输入整数x,程序将输出长度为x的斐波那契数列。\n"))
    list_x = [0, 1]
    for i in range(2, x):
        list_x.append(list_x[i - 2] + list_x[i - 1])
    list_y = list_x[0:20:2]
    print(list_y)


'''8、输出 9*9 乘法口诀表。'''


def test_exam_08():
    for i in range(1, 10):
        for j in range(i, 10):
            print("{0}*{1}={2}".format(str(i), str(j), str(i * j)), end="\t")
        print()


'''9、暂停一秒输出。'''


def test_exam_09():
    for i in range(1, 10):
        for j in range(i, 10):
            print("{0}*{1}={2}".format(str(i), str(j), str(i * j)), end="\t")
        print()
        time.sleep(1)


'''10、暂停一秒输出,并格式化当前时间。'''


def test_exam_10():
    time.sleep(1)
    # 格式化成2016-03-20 11:45:39形式
    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    # 格式化成Sat Mar 28 22:24:24 2016形式
    print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))


'''11、古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?'''


def test_exam_11():
    x = int(input("请输入月份整数x,程序将输出第x月的兔子总数。\n"))
    list_x = [1, 1]
    total = list_x[0] + list_x[1]
    for i in range(2, x):
        list_x.append(list_x[i - 2] + list_x[i - 1])
        total += list_x[i]
    print("请输入月份整数为{0},第{1}月的兔子总数为{2}。".format(str(x), str(x), str(total)))
    print(list_x)


'''12、判断101-200之间有多少个素数,并输出所有素数。'''


def test_exam_12():
    list_x = []
    for i in range(101, 201):
        flag = True
        for j in range(2, int(math.pow(i, 1 / 2))):
            if i % j == 0:
                flag = False
        if flag:
            list_x.append(i)
    print("101-200之间有{0}个素数,所有素数如下所示:".format(len(list_x)))
    print(list_x)


'''13、打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。'''


def test_exam_13():
    list_x = []
    for i in range(101, 1000):
        if i == math.pow(int(i / 100), 3) + math.pow(int((i % 100) / 10), 3) + math.pow(i % 10, 3):
            list_x.append(i)
    print("所有的水仙花数如下所示:")
    print(list_x)


'''14、将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。'''


def test_exam_14():
    x = int(input("将一个正整数x,程序将分解质因数。\n"))
    list_x = []
    t = x
    i = 2
    flag = True
    print("输入的正整数为{0},程序将分解质因数如下:".format(str(x)))
    print(str(x), end="")
    while 2 <= i < int(x):
        if t % i == 0:
            list_x.append(i)
            if flag:
                print("=" + str(i), end="")
            else:
                print("*" + str(i), end="")
            t /= i
            i = 2
            flag = False
        else:
            i += 1
    if len(list_x) == 0:
        print(",该正整数为素数,不能被质因数分解。")


'''15、利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。'''


def test_exam_15():
    x = int(input("请输入学生成绩(正整数:0-100之间)x,程序将输出成绩类别。\n"))
    if 100 >= x >= 90:
        print("该生成绩:A")
    elif x > 60:
        print("该生成绩:B")
    elif x > 0:
        print("该生成绩:C")
    else:
        print("输入的成绩有误,不在0-100之间,请重新执行程序,重新输入正确范围内的学生成绩。")


'''16、输出指定格式的日期。(本题写的时候不太熟悉时间控件,所以基本为模仿编写。)'''


def test_exam_16():
    localtime1 = time.localtime(time.time())
    print("本地时间为:", localtime1)

    localtime2 = time.asctime(time.localtime(time.time()))
    print("本地时间为:", localtime2)
    # 格式化成2021-01-01 08:43:50形式"
    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    # 格式化成Mon Jun 01 08:43:50形式"
    print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
    # 将格式字符串转换为时间戳"
    a = "Fri Jan 01 08:49:15 2021"
    print(time.mktime(time.strptime(a, "%a %b %d %H:%M:%S %Y")))

    # 日历模块使用的方法
    cal = calendar.month(2020, 1)
    print("如下输出2020年1月份的日历:")
    print(cal)
    # 判断是否闰年的方法
    print(calendar.isleap(2020))
    print(calendar.isleap(2021))


'''17、输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。'''


def test_exam_17():
    s = input("请输入一行字符,程序将分别统计出其中英文字母、空格、数字和其他字符的个数。\n")
 
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

阿尔卑斯的畅想

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

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

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

打赏作者

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

抵扣说明:

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

余额充值