[Tutor] Getting error on my code
Leam Hall
leamhall at gmail.com
Fri Jan 31 05:46:29 EST 2025
On 1/31/25 01:51, Dappy Jr via Tutor wrote:
> class Dog():
>
> def_init_(self , name , age):
> self.name = name
> self.age = age
> print(self.name.title() + self.age)
>
> my_dog = Dog('willie' , 6)
> print("My dog's name is " + my_dog.name.title() + '.')
> print("My dog is " + str(my_dog.age) + 'years old.')
I'm not sure if your mail client messed up the indentation but here are the changes I made to get it to work:
1. There are 2 underscores, both front and back, on init. __init__
2. Made the age a string in the __init__ print method.
3. Added a space in the __init__ print method, like you did in the last line.
class Dog():
def __init__(self , name , age):
self.name = name
self.age = age
print(self.name.title() + " " + str(self.age))
my_dog = Dog('willie' , 6)
print("My dog's name is " + my_dog.name.title() + '.')
print("My dog is " + str(my_dog.age) + 'years old.')
Leam
Linux Software Engineer (reuel.net/career)
Scribe: The Domici War (domiciwar.net)
Coding Ne'er-do-well (github.com/LeamHall)
Between "can" and "can't" is a gap of "I don't know", a place of discovery. For the passionate, much of "can't" falls into "yet". -- lh
Practice allows options and foresight. -- lh
More information about the Tutor
mailing list