想用下面的代码实现如下输出:
(r:100.0, g:100.0, b:0.0)
(r:0.0, g:100.0, b:100.0)
(r:100.0, g:0.0, b:100.0)
(r:50.0, g:50.0, b:100.0)
但是出现报错undefined
mix的调用该怎么写才能实现如上的输出?
class Color:
def __init__(self,x,y,z):
self.x=x
self.y=y
self.z=z
def __str__(self):
return "(r:{}, g:{}, b:{})".format(self.x,self.y,self.z)
def mix(self,other):
self.x=(self.x+other.x)/2
self.y=(self.y+other.y)/2
self.z=(self.z+other.z)/2
red=Color(200,0,0)
green=Color(0,200,0)
blue=Color(0,0,200)
print (red.mix(green))
print (green.mix(blue))
print (blue.mix(red))
print (red.mix(green))
你把other.三个去掉就可以了
mix函数没有返回值的, 怎么print.
red.mix(green)
print(red)