代码展示
- #class1.py
class Person:
name="wangshuyu"
birthday={'年':int(input("请输入您的出生年份:")),'月':int(input("请输入您的出生月份")),'日':int(input("请输入您的出生日期"))}
hight=eval(input("请输入您的身高:"))
weight=eval(input("请输入您的体重:"))
def judge(self):
if self.birthday['年']<=2000 and self.birthday['年']>1972: #太难了,实例方法调用类属性的时候一定要都加上self.才行,因为这样系统才能去类属性中去寻找,否则系统会去类外去找全局变量
return"年龄合格!"
else:
return"年龄不合格!"
def judge1(self):
if self.hight>=170 and self.hight<=180:
return "身高达标!"
else:
return "身高不达标!"
def judge2(self):
if self.weight>=55 and self.weight<=70:
return "体重达标!"
else:
return "体重不达标!"
- #PythonApplication.py
import class1 as c1
judged=c1.Person()
print(judged.judge())
print(judged.judge1())
print(judged.judge2())
要点
全局/局部变量注意
退出登录?