Open roberthsu2003 opened 4 months ago
import pyinputplus as pyip
class BMI():
def __init__(self, name: str, height: float, weight: float):
super().__init__()
self.name = name
self.height = height
self.weight = weight
def __repr__(self):
return f'\n{self.name}您好:'
@property
def bmi(self):
return self.weight / (self.height / 100) ** 2
def status(self) -> str:
if self.bmi < 18.5:
result = '過輕'
elif self.bmi < 24:
result = '正常'
elif self.bmi < 27:
result = '過重'
elif self.bmi < 30:
result = '輕度肥胖'
elif self.bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name = input('請輸入姓名: ')
height = pyip.inputFloat('請輸入身高(cm): ', min=0)
weight = pyip.inputFloat('請輸入體重(kg): ', min=0)
p1 = BMI(name, height, weight)
print(f'{p1}\n您的BMI值是: {p1.bmi:.2f}\n您的體重: {p1.status()}\n')
import pyinputplus as pyip
name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(cm):', min=1, max=300)
weight = pyip.inputFloat('請輸入體重(kg):', min=1, max=500)
class BMI():
def __init__(self, n: str, h: float, w: float):
super().__init__()
self.name = n #attribute
self.height = h #attribute
self.weight = w #attribute
def __repr__(self):
message = f"{self.name}您好:\n"
message += f"您的bmi值是{self.bmi:.2f}\n"
message += f"您的體重:{self.status()}\n"
return message
#建立property的語言
@property
def bmi(self):
return weight / (height / 100)**2
#建立實體方法
def status(self) -> str:
bmi_value = self.bmi
if bmi_value < 18.5:
result = '過輕'
elif bmi_value < 24:
result = '正常'
elif bmi_value < 27:
result = '過重'
elif bmi_value < 30:
result = '輕度肥胖'
elif bmi_value < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
user_bmi = BMI(name, height, weight)
print(user_bmi)
import pyinputplus as pyip
class BMI():
def __init__(self, name: str, height: float, weight: float):
super().__init__()
self.name = name
self.height = height
self.weight = weight
def __repr__(self):
return f'\n{self.name}您好'
@property
def bmi(self):
return self.weight / (self.height / 100) ** 2
def status(self) -> str:
if self.bmi < 18.5:
result = '過輕'
elif self.bmi < 24:
result = '正常'
elif self.bmi < 27:
result = '過重'
elif self.bmi < 30:
result = '輕度肥胖'
elif self.bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name = input('請輸入姓名: ')
height = pyip.inputFloat('請輸入身高(120~230)(cm): ', min=120, max=230)
weight = pyip.inputFloat('請輸入體重(40~170)(kg): ', min=40, max=170)
A1 = BMI(name, height, weight)
print(f'{A1}\n您的BMI值為:{A1.bmi:.2f}\n您的體重:{A1.status()}\n')
import pyinputplus as pyip
name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(cm):', min=1, max=300)
weight = pyip.inputFloat('請輸入體重(kg):', min=1, max=500)
class BMI():
def __init__(self, n: str, h: float, w: float):
super().__init__()
self.name = n #attribute
self.height = h #attribute
self.weight = w #attribute
def __repr__(self):
message = f"{self.name}您好:\n"
message += f"您的bmi值是{self.bmi:.2f}\n"
message += f"您的體重:{self.status()}\n"
return message
#建立property的語言
@property
def bmi(self):
return weight / (height / 100)**2
#建立實體方法
def status(self) -> str:
bmi_value = self.bmi
if bmi_value < 18.5:
result = '過輕'
elif bmi_value < 24:
result = '正常'
elif bmi_value < 27:
result = '過重'
elif bmi_value < 30:
result = '輕度肥胖'
elif bmi_value < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
user_bmi = BMI(name, height, weight)
print(user_bmi)
class BMI():
def __init__(self, n:str, h:int, w:int):
super().__init__()
self.name = n #attribute
self.height = h #attribute
self.weight = w #attribute
def __repr__(self):
message = f"請輸入姓名:{self.name}\n"
message += f"請輸入身高:{self.height}\n"
message += f"請輸入體重:{self.weight}\n"
return message
#建立property的語法
@property
def bmi(self):
return self.weight / (self.height / 100) ** 2
#以下還沒改
#建立實體方法
def status(self)->str:
if self.bmi < 18.5:
self.result = '過輕'
elif self.bmi < 24:
self.result = '正常'
elif self.bmi < 27:
self.result = '過重'
elif self.bmi < 30:
self.result = '輕度肥胖'
elif self.bmi < 35:
self.result = '中度肥胖'
else:
self.result = '重度肥胖'
return self.result
s1= BMI(n="王小明", h=175, w=68)
print(s1)
print(f"您的BMI值是:{s1.bmi:.2f}" )
print(f"您的體重:{s1.status()}")
print('============================')
s2= BMI(n="Tom Wang", h=167, w=80)
print(s2)
print(f"您的BMI值是:{s2.bmi:.2f}" )
print(f"您的體重:{s2.status()}")
import pyinputplus as pyip
name = input("請輸入姓名:")
height = pyip.inputFloat("請輸入身高(cm):")
weight = pyip.inputFloat("請輸入體重(kg):")
class BMI:
def __init__(self, n:str, h:float, w:float):
self.name = n # 姓名屬性
self.height = h # 身高屬性
self.weight = w # 體重屬性
def __repr__(self):
message = f"\n{self.name},您好\n"
message += f"您的bmi值是:{self.bmi:.2f}\n"
message += f"體況屬於:{self.status()}\n"
return message
@property
def bmi(self):
return self.weight / (self.height / 100) ** 2
def status(self)->str:
bmi_value = self.bmi
if bmi_value < 18.5:
result = "體重過輕"
elif bmi_value < 24:
result = "正常範圍"
elif bmi_value < 27:
result = "體重過重"
elif bmi_value < 30:
result = "輕度肥胖"
elif bmi_value < 35:
result = "中度肥胖"
else:
result = "重度肥胖"
return result
A1 = BMI(name, height, weight)
print(f"{A1}")
import pyinputplus as pyip
class BMI():
def __init__(self,name:str,high:float,weight:float):
super().__init__()
self.name = name
self.high = high
self.weight = weight
@property
def bmi(self):
return self.weight / (self.high/100) ** 2
def status(self)->str:
if self.bmi < 18.5:
result = '過輕'
elif self.bmi < 24:
result = '正常'
elif self.bmi < 27:
result = '過重'
elif self.bmi < 30:
result = '輕度肥胖'
elif self.bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
def __repr__(self): # __repr__只能有一個(?
data = f"\n{self.name}您好:,您的BMI值是{self.bmi:.2f},您屬於:{self.status()}\n"
return data
name = input("請輸入姓名: ")
high = pyip.inputFloat(f"請輸入身高(cm): ", min=1)
print(high)
weight = pyip.inputFloat(f"請輸入體重(kg):", min=1)
print(weight)
p1 = BMI(name,high,weight)
print(p1)
import pyinputplus as pyip
class BMI():
def __init__(self, name: str, height: float, weight: float) -> None:
super().__init__()
self.name = name
self.height = height
self.weight = weight
def __repr__(self) -> str:
message = f"{self.name}您好:\n"
message += f"您的bmi值是{self.bmi:.2f}\n"
message += f"您的體重:{self.status()}"
return message
@property
def bmi(self):
return self.weight / (self.height / 100) ** 2
def status(self):
if self.bmi < 18.5:
result = "過輕"
elif self.bmi < 24:
result = "正常範圍"
elif self.bmi < 27:
result = "過重"
elif self.bmi < 30:
result = "輕度肥胖"
elif self.bmi < 35:
result = "中度肥胖"
else:
result = "重度肥胖"
return result
name = input("請輸入姓名:")
print(f"請輸入姓名:{name}")
height = pyip.inputInt("請輸入身高(cm):")
print(height)
weight = pyip.inputInt("請輸入體重(kg):")
print(weight)
s1 = BMI(name, height, weight)
print(s1)
import pyinputplus as pyip
class BMI():
def __init__(self, name: str, height: float, weight: float):
super().__init__()
self.name = name
self.height = height
self.weight = weight
def __repr__(self):
return f'\n{self.name}您好'
@property
def bmi(self):
return self.weight / (self.height / 100) ** 2
def status(self) -> str:
if self.bmi < 18.5:
result = '過輕'
elif self.bmi < 24:
result = '正常'
elif self.bmi < 27:
result = '過重'
elif self.bmi < 30:
result = '輕度肥胖'
elif self.bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name = input('請輸入姓名: ')
height = pyip.inputFloat('請輸入身高(120~230)(cm): ', min=120, max=230)
weight = pyip.inputFloat('請輸入體重(40~170)(kg): ', min=40, max=170)
A1 = BMI(name, height, weight)
print(f'{A1}\n您的BMI值為:{A1.bmi:.2f}\n您的體重:{A1.status()}\n')
import pyinputplus as pyip
class BMI():
def __init__(self, name: str, height: float, weight: float):
super().__init__()
self.name = name
self.height = height
self.weight = weight
def __repr__(self):
return f'\n{self.name}您好:'
@property
def bmi(self):
return self.weight / (self.height / 100) ** 2
def status(self) -> str:
if self.bmi < 18.5:
result = '過輕'
elif self.bmi < 24:
result = '正常'
elif self.bmi < 27:
result = '過重'
elif self.bmi < 30:
result = '輕度肥胖'
elif self.bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name = input('請輸入姓名: ')
height = pyip.inputFloat('請輸入身高(cm): ', min=0)
weight = pyip.inputFloat('請輸入體重(kg): ', min=0)
p1 = BMI(name, height, weight)
print(f'{p1}\n您的BMI值是: {p1.bmi:.2f}\n您的體重: {p1.status()}\n')
import pyinputplus as pyip
name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(cm):', min=1, max=300)
weight = pyip.inputFloat('請輸入體重(kg):', min=1, max=500)
class BMI():
def __init__(self, n: str, h: float, w: float):
super().__init__()
self.name = n #attribute
self.height = h #attribute
self.weight = w #attribute
def __repr__(self):
message = f"{self.name}您好:\n"
message += f"您的bmi值是{self.bmi:.2f}\n"
message += f"您的體重:{self.status()}\n"
return message
#建立property的語言
@property
def bmi(self):
return weight / (height / 100)**2
#建立實體方法
def status(self) -> str:
bmi_value = self.bmi
if bmi_value < 18.5:
result = '過輕'
elif bmi_value < 24:
result = '正常'
elif bmi_value < 27:
result = '過重'
elif bmi_value < 30:
result = '輕度肥胖'
elif bmi_value < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
user_bmi = BMI(name, height, weight)
print(user_bmi)
建立class BMI
建立attribute->name,height,weight
建立property->bmi
建立實體方法def status(self) -> str
輸入
輸出