我在 Python 中实现 OOP 时遇到挑战



我面临着在python中实现OOP的挑战,使我能够随时调用函数,到目前为止,我没有语法错误,这对我来说非常具有挑战性。代码运行的第一部分是接受数据,但函数部分不运行。

我已经尝试了通过创建函数实例来调用函数的不同方法。

print (list)
def tempcheck(self,newList): 
temp=newList[0]
if  temp==27:
print ("Bedroom has ideal temperature ")
elif temp>=28 or temp<=26:
print ("Bedroom Temperature is not ideal ,either too low or too cold. ")
print  ("Please to adjust the temperature to the optimum temperature which is 27 degree Celsuis")

# now to initialize args
def __init__(self,temp,puri1,bedwashroom,newList):
self.temp=temp
self.puri1=puri1
self.bedwashroom=bedwashroom
tempcheck(newList)


# now calling the functions 
newvalue=tempcheck(list)
# where list contains the values from the input function.

我希望该函数检查所提供列表中称为 list 的位置的特定值,并且该函数还根据if语句返回字符串。

我做对了,我想出了我的错误的替代方案,感谢您的批评,但欢迎任何进一步的补充, 主要目标是创建一个函数,该函数接受输入并将其传递给列表以供以后使用 我想这段代码不那么麻烦 完整代码的链接粘贴在下面

最新更新