Welcome to the Treehouse Community
Looking to learn something new?
NumString challenge broken?
Can't get this challenge to work.
rmul () seems to always return an error, even when correct, based on testing inside and outside workspaces. Unable to see what results are expected, so unable to continue with this particular challenge task.
class NumString: def __init__(self, value): self.value = str(value) def __str__(self): return self.value def __int__(self): return int(self.value) def __float__(self): return float(self.value) def __add__(self, other): if '.' in self.value: return float(self) + other return int(self) + other def __radd__(self, other): return self + other def __iadd__(self, other): self.value = self + other return self.value def __mul__(self, num): self.value = int(self) * num return self.value def __rmul__(self, num): self.value = int(self) * num return self.value
Craig DennisTreehouse Teacher
Look at how
__radd__ are implemented for addition for task 1. Then for task 2 look at how
__iadd__ is implemented. Your solutions for multiplication should be very similar in implementations.
That hint help?
Michael Nichols4,827 Points
Might be wrong but I think it's because you're saving the new number to the variable when you're only supposed to be doing the multiplication. rmul just lets you multiply with the variable on the right side
Hi guys, only saw this now.
Still unable to successfully complete task 1, no matter what I try it always returns:
<number> * NumString gave the wrong value
The code definitely works, unless I'm really missing something obvious...