我在用python实现OOP时遇到了挑战

2024-10-01 02:19:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我面临着在python中实现OOP以使我能够在任何时候调用函数的挑战,到目前为止,我没有语法错误,这对我来说是相当有挑战性的。运行ehich的代码的第一部分是接受数据,但函数部分不运行。你知道吗

我通过创建函数的实例尝试了调用函数的不同方法。你知道吗

  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语句的字符串。你知道吗


Tags: theto函数selfifdeftemplist
1条回答
网友
1楼 · 发布于 2024-10-01 02:19:51

我做对了,我找到了一个可以替代我的bug的方法,谢谢你的批评,不过欢迎你再加一点, 主要的目标是创建一个函数,该函数接受输入并将其传递给列表,以便以后使用。我猜这段代码不那么麻烦 完整代码的链接粘贴在下面

相关问题 更多 >