Python123:練習4: 程序的控制結構 (第2周)

在這裏插入圖片描述
在這裏插入圖片描述

height,weight = eval(input(""))
BIM = weight/(pow(height,2))
print("BMI數值爲:{:.2f}".format(BIM))
if BIM<=18.5:
    print("BMI指標爲:國際'偏瘦',國內'偏瘦'")
elif BIM>18.5and BIM<=24:
    print("BMI指標爲:國際'正常',國內'正常'")
elif BIM>24 and BIM<=25:
    print("BMI指標爲:國際'正常',國內'偏胖'")
elif BIM>25 and BIM<=28:
    print("BMI指標爲:國際'偏胖',國內'偏胖'")
elif BIM>28 and BIM<=30:
    print("BMI指標爲:國際'肥胖',國內'偏胖'")
else:
    print("BMI指標爲:國際'肥胖',國內'肥胖'")

在這裏插入圖片描述
在這裏插入圖片描述

from random import random, seed

DARTS = eval(input())
seed(123)
hits = 0.0
for i in range(DARTS):
    x, y = random(), random()
    dist = pow(x ** 2 + y ** 2, 0.5)
    if dist <= 1.0:
        hits = hits + 1
pi = 4 * (hits/DARTS)
print("{:.6f}".format(pi))

在這裏插入圖片描述

sum = 0
for i in range(967):
    if i%2==0:
        sum = sum - i
    else:
        sum = sum + i
print("{}".format(sum))

在這裏插入圖片描述

s=""
for i in range(100,1000):
    t=str(i)
    if pow(eval(t[0]),3)+pow(eval(t[1]),3)+pow(eval(t[2]),3)==i:
        s+="{},".format(i)
print(s[:-1])

在這裏插入圖片描述
在這裏插入圖片描述

a=0
for i in range(3):
    name=input()
    password=input()
    if name=="Kate" and password=="666666":
        a=1
        print("登錄成功!")
        break
if a==0:
    print("3次用戶名或者密碼均有誤!退出程序。")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章