ejercicios básicos de Python (1)

Tabla de contenido

1. Dada una calificación, determine la calificación de la calificación.

 2. Determinar si un número es par o impar

3. Determinar si un año es bisiesto

 4. Determinar el IMC de una persona

5. Usa Hailun Company para encontrar el perímetro y el área de un triángulo.

 6. Símbolos de operación de dos números.

 7. Determinar si un número es exponente de 2

8. Calcule la cantidad de semanas en un mes según la cantidad de días.

 9. Recompensas por la puntuación del examen

 10. Proceso de compra de héroes de League of Legends


1. Dada una calificación, determine la calificación de la calificación.

score = int(input("输入你的成绩"))
if score == 100:
    print("满分")
elif 90 <= score < 100:
    print("优秀")
elif 80 <= score < 90:
    print("良好")
elif 70 <= score < 80:
    print("还可以,多多努力")
elif 60 <= score < 70:
    print("合格")
elif 0 <= score < 60:
    print("不合格")
elif score == 0:
    print("鸡蛋")

 2. Determinar si un número es par o impar

num = int(input("请输入一个数:"))
if (num % 2) == 0:
    print("{0}是偶数".format(num))
else:
    print("{0}是奇数".format(num))

3. Determinar si un año es bisiesto

year = int(input("输入一个年份"))
if (year % 4 != 0 and year % 100 != 100) and year % 400 == 0:
    print("闰年")
else:
    print('不是闰年')

 

 4. Determinar el IMC de una persona

tall = float(input("输入身高"))
weight = int(input("输入体重"))
BMI = weight / (tall * tall)
if 35 <= BMI:
    print("重度肥胖")
elif 30 <= BMI < 35:
    print("中度肥胖")
elif 27 <= BMI < 30:
    print("轻度肥胖")
elif 24 <= BMI < 27:
    print("过重")
elif 18.5 <= BMI < 24:
    print("正常")
else:
    print("过轻")

5. Usa Hailun Company para encontrar el perímetro y el área de un triángulo.

a = float(input('输入三角形第一边长: '))

b = float(input('输入三角形第二边长: '))

c = float(input('输入三角形第三边长: '))

while a+b<c or a+c<b or b+c<a:

print('输入的边构不成三角形,请重新输入!')

a =float(input ('输入三角形第一边长:'))

b =float(input ('输入三角形第二边长:'))

c =float(input ('输入三角形第三边长:'))

# 计算半周长

s = (a + b + c) / 2

# 计算面积

area = (s*(s-a)*(s-b)*(s-c)) ** 0.5

print('三角形面积为 %0.2f' %area)

 6. Símbolos de operación de dos números.

a = float(input("输入第一个数"))
b = float(input("输入第二个数"))
c = a + b
print("两数之和为%0.2f" % c)
d = a - b
print("两数之差为%0.2f" % d)
e = a / b
print("两数相除%0.2f" % e)
f = a % b
print("两数取模 %0.2f" % f)
g = a // b
print("两数相除取整数 % f" % g)
h = a ** b
print("两数乘方 % f" % h)

 7. Determinar si un número es exponente de 2


Índice de 2
0000 0010 0000 0001
0000 0100 0000 0011
0000 1000 0000 0111
0001 0000 0000 1111

num = int(input("请输入一个数字;"))
if (num - 1) == 0:
    print("这个数字是2的指数:%s" % num)
else:
    print("这个不是2的指数")

 

8. Calcule la cantidad de semanas en un mes según la cantidad de días.

days = int(input("请输入一个数:"))
week = days//7
if week == 0:
    print("这是第一周")
elif week == 1:
    print("这是第二周")
elif week == 2:
    print("这是第三周")
elif week == 3:
    print("这是第四周")
elif week == 4:
    print("这是第五周")
elif week == 5:
    print("这是第六周")
elif week == 6:
    print("这是第七周")
elif week == 7:
    print("这是第八周")
else:
    print("这是第**周")

 9. Recompensas por la puntuación del examen

grade = int(input("请输入成绩:"))
if 100 < grade or grade < 0:
    print("成绩输入错误,请重新输入")
elif grade == 100:
    print('爸爸要给你买车')
elif grade >= 90:
    print('你妈妈要给你买MP4')
elif 90 > grade >= 60:
    print('妈妈要给你买本参考书')
elif 60 > grade >= 0:
    print('什么都不买')

 10. Proceso de compra de héroes de League of Legends

import sys

choice = int(input())
# 若用户输入的为1,则进入商城首页
if choice == 1:
    username = input("请输入您的用户名:")
    password = input("请输入您的密码:")
    # 判断用户输入的正确性,后期可以用列表,字典来优化
    if username == "admin" and password == "123":
        print("登陆成功~ {},您好!欢迎回来".format(username))
        while True:
            print("\t商城首页\t\t\t")
            print("~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~")
            print("\t\t1.进入英雄超市\t\t\t")
            print("\t\t2.休闲小游戏\t\t\t")
            print("\t\t3.退出登录\t\t\t")
            print("~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~")
            choice = int(input("请输入您的选项: "))
            if choice == 1:
                print("欢迎来到英雄超市!做出你的选择吧~")
                # 商城的英雄选择
                print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
                print("编号  姓名     昵称     价格  库存  描述")
                print("1   纳尔   迷失之牙  3500  100  丛林不会原谅盲目与无知")
                print("2   锐雯   放逐之刃  4000  100  她是残忍高效的战士  ")
                print("3   薇恩   暗夜猎手  3500  100  这个世界不想人们想象的那么美好")
                print("4   扎克   生化魔人  3000  100  即使你没有脊柱,你也必须站起来")
                print("5   杰斯   未来守护者 2500  100  武装着睿智与魅力,你的选择没有错")
                print("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~\n")
                choice = int(input())

                # 判断选择的是哪个英雄
                if choice == 1:
                    print("您的选择是纳尔")
                elif choice == 2:
                    print("您的选择是瑞文")
                elif choice == 3:
                    print("你选择的是薇恩")
                elif choice == 4:
                    print("你选择的是扎克")
                elif choice == 5:
                    print("你选择是杰斯")
                else:
                    input("对不起,没有找到您选择的英雄!请重新选择,按任意键继续\n")
            elif choice == 2:
                pass
            elif choice == 3:
                sys.exit()

    else:
        input("对不起,找不到您的信息!请重新登录,按任意键继续\n")
print("\n\t\t英雄商城购买英雄")
print("英雄信息")
print("~ *"*14)
print("\n")
print("\t英雄联盟:盲僧(史诗)")
print("\t英雄属性:生命值(428)/能量值200(+0)/移动速度425/攻击力/55.8(+3.2)")
print("\t\t攻击速度0.651(+3.1%)/护甲值24(+1.25)/攻击距离125\n")
print("\t英雄座右铭:一人之行可灭世,众人之勤可救世!")
print("\t英雄价格:3000")
print("\t折扣价格:9.5\n")
print("插播广告:当风云变色,当流离失所,世界不再是旧日模样")
print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡 ")
print("~ *"*14)
a = int(input("请输入商品价格:"))
b = int(input("请输入购买数量:"))
c = int(input("(温馨提示)请付款:"))
m = a * b * 0.95
n = c-m
while n < 0:
    print("您的金额不够")
    break
else:
    print("购买成功")
    print("\n\t\t英雄商城购买英雄")
    print("英雄购买票据")
    print("~ *"*14)
    print("\n")
    print("\t英雄联盟:九尾妖狐(史诗)")
    print("\t英雄价格:3000")
    print("\t折扣价格:9.5\n")
    print("\t应付付款:{}".format(m))
    print("\t实际付款:{}".format(c))
    print("\t找零:{}".format(n))
    print("插播广告:当风云变色,当流离失所,世界不再是旧日模样")
    print("你是否会为了自己的梦想战斗,直至力战身亡,直至彼岸他乡 ")
    print("~ *"*14)
    input("(温馨提示)按任意键返回上一级菜单:")
# 执行结果

Supongo que te gusta

Origin blog.csdn.net/weixin_62304542/article/details/129473934
Recomendado
Clasificación