How to solve (TypeError: must be a real number, not a tuple) error
class Vehicle:
name = ""
kind = "car"
color = ""
value = 100.00
def description(self):
desc_str = "%s is a %s %s worth $%.2f." % (self.name, self.color, self.kind, self.value)
return desc_str
car1 = Vehicle()
car1.name = "Fer"
car1.color = "Red"
car1.kind = "Convertible"
car1.value = 60,000.00
car2 = Vehicle()
car2.name = "Jump"
car2.color = "Blue"
car2.kind = "Van"
car2.value = 10,000.00
print(car1.description())
print(car2.description())
After running this code, I'm getting the error. I wanted the info of the cars.
CodePudding user response:
You have written 60,000.00
for the value of your car1.value
variable. In python a comma is used to separate parameters. You can't use it like you do when hand-writing numbers.
Having a comma there tells python that you have two parameters in the variable: 60
and 000.00
. If you remove the comma, it becomes one parameter. car1.value
will then store 60000.00
CodePudding user response:
For numeric data to be dumped in a variable, Python accepts integer and float only without the use of ',' in between. A ',' changes the type of the input to a tuple which means,
car1.value = 60,000
would be stored as (60,0) inside the variable.
Change the value of the below variables to,
car1.value = 60000
car2.value = 10000