python新手学习语法中,求解下面的错误错在哪。
classHotdog:def__init__(self):self.cooked_level=0self.cooked_string='raw'self.cooked_...
class Hotdog:
def __init__(self):
self.cooked_level=0
self.cooked_string='raw'
self.cooked_condiments=[]
def cook(self,time):
self.cooked_level=self.cooked_level+time
if self.cooked_level>8:
self.cooked_string='Charcoal'
elif self.cooked_level>5:
self.cooked_string='Well-done'
elif self.cooked_level>3:
self.cooked_string='Raw'
def __str__(self):
msg="Now the hot dog cooked level is "+str(self.cooked_level)
msg1="The hot dog cooked string is "+self.cooked_string
return msg,msg1
my_hotdog=Hotdog()
my_hotdog.cook(4)
print my_hotdog
运行以后返回的错误信息是
Traceback (most recent call last):
File "E:/python2.5/作业文件/烤热狗,对象问题", line 24, in <module>
print my_hotdog
TypeError: __str__ returned non-string (type tuple) 展开
def __init__(self):
self.cooked_level=0
self.cooked_string='raw'
self.cooked_condiments=[]
def cook(self,time):
self.cooked_level=self.cooked_level+time
if self.cooked_level>8:
self.cooked_string='Charcoal'
elif self.cooked_level>5:
self.cooked_string='Well-done'
elif self.cooked_level>3:
self.cooked_string='Raw'
def __str__(self):
msg="Now the hot dog cooked level is "+str(self.cooked_level)
msg1="The hot dog cooked string is "+self.cooked_string
return msg,msg1
my_hotdog=Hotdog()
my_hotdog.cook(4)
print my_hotdog
运行以后返回的错误信息是
Traceback (most recent call last):
File "E:/python2.5/作业文件/烤热狗,对象问题", line 24, in <module>
print my_hotdog
TypeError: __str__ returned non-string (type tuple) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询