【python】编程题小代码

空心题(平行四边形)

layer = int(input("请输入你要打印的行数:"))

for i in range(1,layer // 2 + 2):

    space_num = layer - i

    for j in range(0,space_num):

        print(" ",end = "")

    star_num = 2 * i - 1

    for j in range(0,star_num):

        if j == 0 or j == star_num-1:

            print("*" , end = "")

        else:

            print(" ",end = "")

    print("")

for i in range(layer//2,0,-1):

    space_num = layer - i

    for j in range(0,space_num):

        print(" ",end = "")

    star_num = 2 * i - 1

    for j in range(0,star_num):

        if j == 0 or j == star_num-1:

            print("*" , end = "")

        else:

            print(" ",end = "")

    print("")

质数的判断

num = int(input("请输入一个数:"))

i = 2

while i< num :

    if num % i == 0 :

        break

    i += 1

if i == num  :

    print("是质数")

else :

    print("不是质数")    

BMI体重分析

weight = 57.5

high = 1.65

BMI = weight /(high**2)

if BMI <= 18.5 :

    print("过轻")

elif  18.5 <= BMI <= 25 :

    print("正常")

elif  25 <= BMI <= 28 :

    print("过重")

elif  28 <= BMI <= 32 :

    print("肥胖")

elif  BMI >= 32 :

    print("严重肥胖")

六边形面积

import math

s = float(input("请输入正六边形的边长:"))

area = (3*math.sqrt(3))/2 * s**2

print("area=%f"%area)

三位整数各个数相加的和

a=int(input("请输入一个0~1000的三位整数"))

b=a%10

c=(a//10)%10

d=a//100

sum=b+c+d

print("各个数相加的和"%(sum))

圆柱的相关问题

radius=eval(input("请输入一个数:"))

length=eval(input("请输入一个数:"))

area=radius*radius*3.14

volume=area*length

print("低面积是:",(area))

print("体积是:",(volume))

你可能感兴趣的:(python编程小题型,python)