猜數字小遊戲
首先我們要先import random這個指令
要運用while 迴圈
設x界在1-100數
y是你輸入的數,之後x和y比大小
import random
x = random.randint(1,100)
i = 0
while i < 100:
y = input("請輸入數字")
if x == y:
print "答對"
break
elif y < x:
print "太小"
else:
print "太大"
# 做一個遊戲好像有點太混了
#做個BMI
Height = input("輸入身高(公分)")
Weight = input("輸入體重(公斤)")
BMI = float(Weight) / (float(Height)/100)**2
if (BMI < 18.5):
print("BMI值為%.2f,難民需多吃" % BMI)
elif (18.6 <= BMI and BMI < 24):
print("BMI值為%.2f,不多不少剛剛好" % BMI)
elif (24 <= BMI and BMI < 27):
print("BMI值為%.2f,少吃點多運動" % BMI)
elif (27 <= BMI and BMI < 30):
print("BMI值為%.2f,該減肥了" % BMI)
elif (30 <= BMI and BMI < 36):
print("BMI值為%.2f,再這樣下去不太好" % BMI)
else:
print("BMI值為%.2f,這樣母湯太重" % BMI)