猫史档案馆


【Python作品分享】五年级(上册)数学 2.0版本【作业帖】

用户:薄荷柠檬鱼薄荷柠檬鱼查看:0 回复:0 评论:0 创建时间:2019-12-29T16:16:36


【作品展示】

center_image

 

【作品介绍】

本次“升级”更新至可使用中文输入

新增“面积(仅五种基础图形)”这个模块

 

【作品源代码】

def prime(y):
    x = int(y)
    if x < 1:
        print('{}<1'.format(x))
    else:
        List = [1]
        for i in range(2, x // 2 + 1):
            if x % i == 0:
                List.append(i)
        List.append(x)
        if len(List) > 2:
            print('composite number')
            print(List)
            print("num {}'s factor nums {}".format(x, len(List)))
        elif x == 1:
            print('1 is not prime or composite number')
        else:
            print('prime')

def prime_list(y):
    x = int(y)
    if x < 2:
        print('{}<2'.format(x))
    else:
        prim = []
        cop = []
        for i in range(2, x + 1):
            List = [1]
            for j in range(2, i // 2 + 1):
                if i % j == 0:
                    List.append(i)
            List.append(x)
            if len(List) == 2:
                prim.append(i)
            else:
                cop.append(i)
        print(prim)
        print('prime nums(num){}'.format(len(prim)))
        time.sleep(len(prim//10))
        print(cop)
        print('composite number nums(num){}'.format(len(cop)))

def biggest_factor(a, b):
    x = int(a)
    y = int(b)
    v = 0
    for i in range(1,x // 2 + 1):
        if x % i == 0 and y % i == 0:
            v = max(v,i)
    print('The biggest factor of {} and {} is {}'.format(x,y,v))

def 喵allest_multiple(a, b):
    x = int(a)
    y = int(b)
    v = 0
    i = max(x,y)
    while v == 0:
        if i % x == 0 and i % y == 0:
            v = i
        else:
            i += 1
    print(v)

def area():
    shape = ['喵','rectangle','triangle','parallelogram','trapezoid',
    '正方形','长方形','三角形','平行四边形','梯形']
    print(shape)
    Type = input('five shapes(五种基础图形)     ')
    if Type == shape[0] or Type == shape[5]:
        a = int(input('side length(边长)  '))
        area = a*a
    elif Type == shape[1] or Type == shape[6]:
        a = int(input('rectangle length(长)  '))
        b = int(input('rectangle width(宽)  '))
        area = a*b
    elif Type == shape[2] or Type == shape[7]:
        a = int(input('height(高)  '))
        b = int(input('botton(底)  '))
        area = a*b/2
    elif Type == shape[3] or Type == shape[8]:
        a = int(input('height(高)  '))
        b = int(input('botton(底)  '))
        area = a*b
    elif Type == shape[4] or Type == shape[9]:
        a = int(input('height(高)  '))
        b = int(input('up botton(上底)  '))
        c = int(input('down botton(下底)  '))
        area = (c+b)*a/2
    else:
        print('no type {}.'.format(Type))
    print(area)
    
def use():
    print('multiple(最小公倍数)  area(图形面积)')
    x = input('prime(判断质数)  prime_list(质数列表)  factor(最大公因数)      ')
    if x == 'prime' or x == '判断质数':
        a = int(input())
        prime(a)
    elif x == 'prime_list' or x == 'prime list' or x == '质数列表':
        a = int(input())
        prime_list(a)
    elif x == 'factor' or x == '最大公因数':
        a = int(input())
        b = int(input())
        biggest_factor(a, b)
    elif x == 'multiple' or x == '最小公倍数':
        a = int(input())
        b = int(input())
        喵allest_multiple(a, b)
    elif x == 'area' or x == '图形面积':
        area()
    else:
        print('no case {}'.format(x))

# 实际操作,在此执行

use()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页