python练习题

本文介绍了使用Python实现的基础编程任务,包括打印直角三角形,判断质数,设计一个包含商品购买功能的程序,以及涉及整除运算、猜数游戏和石头剪刀布等互动环节。
摘要由CSDN通过智能技术生成

一、打印直角三角形

二、判断一个数是否是质数(素数)

三、设计一个程序,完成(英雄)商品的购买(界面就是第一天打印的界面) 展示商品信息(折扣)->输入商品价格->输入购买数量->提示付款 输入付款金额->打印购买小票(扩展)

print("""                    英雄商城英雄列表

~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~

编号  姓名     昵称     价格  库存  描述

1     纳尔   迷失之牙  3500  100  丛林不会原谅盲目与无知

2     锐雯   放逐之刃  4000  100  她是残忍高效的战士  

3     薇恩   暗夜猎手  3500  100  这个世界不想人们想象的那么美好

4     扎克   生化魔人  3000  100  即使你没有脊柱,你也必须站起来

5     杰斯  未来守护者 2500  100  武装着睿智与魅力,你的选择没有错

~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~""")

a = int(input("请输入英雄编号:"))

B = 0

name = 0

if a == 1:

    print( "纳尔   迷失之牙  3500  折扣0.9  100  ")

    B = 3500*0.9

    name = "纳尔"

elif a == 2:

    print("锐雯   放逐之刃  4000  折扣0.9  100")

    B = 4000*0.9

    name = "锐雯"

elif a == 3:

    print("薇恩   暗夜猎手  3500 折扣0.9  100")

    B = 3500*0.9

    name = "薇恩"

elif a == 4:

    print("扎克   生化魔人  3000 折扣0.9  100")

    B = 3000*0.9

    name = "扎克"

elif a == 5:

    print("杰斯  未来守护者 2500 折扣0.9  100")

    B = 2500*0.9

    name = "杰斯"

c = int(input("请输入购买数量:"))

if c > 100:

            print("库存不足")

else:

            print("给钱")

d = int(input("请输入支付金额:"))

if d >= B:

    print("支付成功")

else:

    print("支付失败")

print("感谢购买,这是你的小票")

print(f"""  英雄名称:{name}

  英雄编号:{a}

  英雄价格:{B}

  英雄数量:{c}

  支付金额:{d}

     找钱:{d-B}  """)

四、有一些四位数,百位数字都是3,十位数字都是6,并且它们既能被2整除,又能被3整除,求这样的四位数中最大的和最小的两数各是几?

in_num = 10
max_num = 100
for num in range (min_num,max_num + 1):
    if num % 6 == 0:
        break
print (f"最小二位数",num)
for num in range (max_num,min_num - 1,-1):
    if num % 6 == 0:
       break
print (f"最大二位数",num)
        

五、编程求一个四位自然数ABCD,它乘以A后变成DCBA

六、用户输入两个数a、b。如果a能被b整除或a加b大于1000,则输出a;否则输出b。

七、请输入一个数,判断这个数是偶数还是奇数,如果使用偶数,请判断从1到该数是3的倍数有哪些,如果是奇数,请判断从1到该数是5的倍数有哪些

八、某商店T恤的价格为35元/件(2件9折,3件以上8折),裤子的价格为120 元/条(2条以上9折).小明在该店买了3件T恤和2条裤子,请计算并显示小明应该付多少钱?

t_shirt = 35
trousers = 120
count = 0
def money(num1,num2): 
    if 3 > num1 >= 2:
        count = 0.9* t_shirt
    else:
        count = 0.8* t_shirt
    if num2 >= 2:
        count += 0.9* trousers
    return count
print(money(3,2))

九、鸡兔同笼,从上面看有35个头,从下面看有94只脚,请问鸡有几只,兔有几只?

import random 
 
compute = random.randint(0, 100)
while True:
    my = int(input("请输入一个0~100的整数:"))
 
    if my > compute:
        print("对不起,您猜大了")
    elif my < compute:
        print("对不起,您猜小了")
    else:
        print("恭喜您,猜对了,撒花~~~~~")
        choice = input("请是否继续猜(Y/y),其他任意符号退出:")
        if choice == "Y" or choice == "y":
            compute = random.randint(0, 100)
        else:
            print("see you~")
            break

十、:猜拳游戏:石头、剪刀、布的游戏

import random as r
 
compute = r.randint(0, 3)
while True:
    my = int(input("请输入您要出的拳(0:剪刀,1:石头,2:布)"))
 
    if my == 0 and compute == 0 or my == 1 and compute == 1 or my == 2 and compute == 2:
        print("平局")
        choice = input("请是否继续猜(Y/y),其他任意符号退出:")
        if choice == "Y" or choice == "y":
            compute = r.randint(0, 3)
        else:
            print("see you")
            break
    elif my == 0 and compute == 1:
        print("对不起,您输了")
        choice = input("请是否继续猜(Y/y),其他任意符号退出:")
        if choice == "Y" or choice == "y":
            compute = r.randint(0, 3)
        else:
            print("see you")
            break
    elif my == 0 and compute == 2:
        print("恭喜,您赢了")
        choice = input("请是否继续猜(Y/y),其他任意符号退出:")
        if choice == "Y" or choice == "y":
            compute = r.randint(0, 3)
        else:
            print("see you")
            break
    elif my == 1 and compute == 0:
        print("恭喜,您赢了")
        choice = input("请是否继续猜(Y/y),其他任意符号退出:")
        if choice == "Y" or choice == "y":
            compute = r.randint(0, 3)
        else:
            print("see you")
            break
    elif my == 1 and compute == 2:
        print("对不起,您输了")
        choice = input("请是否继续猜(Y/y),其他任意符号退出:")
        if choice == "Y" or choice == "y":
            compute = r.randint(0, 3)
        else:
            print("see you")
            break
    elif my == 2 and compute == 0:
        print("对不起,您输了")
        choice = input("请是否继续猜(Y/y),其他任意符号退出:")
        if choice == "Y" or choice == "y":
            compute = r.randint(0, 3)
        else:
            print("see you")
            break
    elif my == 2 and compute == 1:
        print("恭喜,您赢了")
        choice = input("请是否继续猜(Y/y),其他任意符号退出:")
        if choice == "Y" or choice == "y":
            compute = r.randint(0, 3)
        else:
            print("see you")
            break

  • 11
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值