栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python实现计算e值,汇率转换与判断水仙花数

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python实现计算e值,汇率转换与判断水仙花数

def JudgeNum(num):
    for i in num:
        if ord(i) < 48 or ord(i) > 57:  # 数字对应的ASCII码
            print('请输入正确的数字!')
            return 0
    return 1


def Transformation():
    print('输入的货币类型是(美元/人民币):', end='')
    money_type = input()
    print(money_type)
    if money_type == '人民币':
        print('货币值为:¥', end='')
        money = input()
        while True:
            if JudgeNum(money):
                break
            else:
                print('货币值:¥', end='')
                money = input()
        print('人民币转换为美元后是:$', end='')
        print(float(money) / 6.7766, end='')
        print('美元')

    elif money_type == '美元':
        print('货币值为:$', end='')
        money = input()
        while True:
            if JudgeNum(money):
                break
            else:
                print('货币值:$', end='')
                money = input()
        print('美元转换为人民币后是:¥', end='')
        print(float(money) * 6.7766, end='')
        print('元')

    elif money_type == 'end':
        print('Over')

    else:
        print('unknown type or command ,please input it again ')
        new_money_type = input()
        Transformation(new_money_type)


def Cal_e():
    e = 1.0
    i = 1
    while True:
        temp = 1.0
        for j in range(i):
            temp *= (j + 1)
        e += 1 / temp
        i += 1
        if 1 / temp < 0.000001:
            break
    print('e is: ', end='')
    print(e)


def Judge_narcissistic_number():
    judge_num = input('输入要判断的数:')

    while True:
        if JudgeNum(judge_num):
            break
        else:
            judge_num = input('输入要判断的数:')

    print(judge_num, end='')
    if len(judge_num) != 3:
        print('不是水仙花数')
        return
    temp = 0

    for i in judge_num:
        temp += int(i) * int(i) * int(i)

    if int(temp) == int(judge_num):
        print('是水仙花数')
    else:
        print('不是水仙花数')


if __name__ == '__main__':
    while True:
        cho = -1
        print(' ____________')
        print('|1  汇率转换器 |')
        print('|2   计算e值  |')
        print('|3 判断水仙花数|')
        print('|4    退出    |')
        print('|___________ |')
        print('选择操作:', end='')
        cho = input()
        if int(cho) == 1:
            print('---人民币-美元汇率转换器---')
            Transformation()
        elif int(cho) == 2:
            print('---计算 e---')
            Cal_e()
        elif int(cho) == 3:
            print('---判断水仙花数---')
            Judge_narcissistic_number()
        elif int(cho) == 4:
            break
        else:
            print('不要乱输啊')

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1018890.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号