欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

[python第五课]构造程序逻辑

程序员文章站 2022-06-27 20:09:45
#coding:utf-8import randomwhile True: xuanze=int(input("请输入您想进入的题目:\n1、水仙花数\n2、百钱百鸡\n4、退出\n(请输入您的数字)")) if xuanze == 1: print("水仙花数") while True: whil ......

#coding:utf-8
import random
while true:
    xuanze=int(input("请输入您想进入的题目:\n1、水仙花数\n2、百钱百鸡\n4、退出\n(请输入您的数字)"))

    if xuanze == 1:
        print("水仙花数")
        while true:
            while true:
                n=int(input("请输入一个三位数"))
                if n>100 and n<999:
                    break
                else:
                    print("您输入的数字不是三位数,请再次输入")
            print("输入成功\n下面数位分离")
            n_gewei=int(n%10)
            n_baiwei=int(n/100)
            n_shiwei=int(n_baiwei%10)
            print("百位:"+str(n_baiwei)+"\n十位:"+str(n_shiwei)+"\n个位:"+str(n_gewei))
            jisuan=n_gewei^3+n_shiwei^3+n_baiwei^3
            if jisuan==n:
                print(str(n)+"这个数是水仙花数")
            else:
                print(str(n)+"这个数不是水仙花数")
            tuichu=int(input("请问是否想退出:\n1、退出\n2、继续\n(输入数字):"))
            if tuichu==1:
                break
            if tuichu==2:
                continue

    if xuanze == 2:
        while true:
            print("百钱百鸡\n价格:\n公鸡:5元/只\n母鸡:3元/只\n小鸡:1元/只\n用n元买")
            n_money=int(input("请输入您的零钱:"))
            for i in range(int(n_money/5)):
                for j in range(int(n_money/3)):
                    for k in range(int(n_money/1)):
                        if 5*i + 3*j + 1*k ==n_money:
                            print("公鸡:"+str(i)+"母鸡"+str(j)+"小鸡"+str(k))
            tuichu_1=int(input("请问是否想退出:\n1、退出\n2、继续\n(输入数字):"))
            if tuichu_1 == 1:
                break
            if tuichu_1 == 2:
                continue

    if xuanze == 4:
        break

 

[python第五课]构造程序逻辑