Python Forum
First Post/ Class Error Question
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First Post/ Class Error Question
#2
Please, repost your code with proper indentation. Most probably that's the problem, but the code in your post does not produce this error
class Dog(object):
   """A simple attempt to model a dog."""
   def __init__(self, name, age):
       """Initialize name and age attributes."""
       self.name = name
       self.age = age
   def sit(self):
       """Simulate a dog sitting in response to a command."""
       print(self.name.title() + " is now sitting.")
   def roll_over(self):
       """Simulate rolling over in response to acommand."""
       print(self.name.title() + " rolled over!")
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.")
Output:
My dog's name is Willie. My dog is 6 years old.
Reply


Messages In This Thread
First Post/ Class Error Question - by jvan1601 - Apr-30-2017, 08:30 PM
RE: First Post/ Class Error Question - by buran - Apr-30-2017, 08:41 PM
RE: First Post/ Class Error Question - by jvan1601 - May-01-2017, 04:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  question about __repr__ in a class akbarza 4 619 Jan-12-2024, 11:22 AM
Last Post: DeaD_EyE
  Initiating an attribute in a class __init__: question billykid999 8 1,361 May-02-2023, 09:09 PM
Last Post: billykid999
  Error on basic Post API, FastAPI marlonbown 1 2,191 Nov-10-2022, 10:02 AM
Last Post: Larz60+
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,324 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  [split] [split] New to the forum, how to post a question? karnik 2 1,282 Feb-12-2022, 03:45 PM
Last Post: deanhystad
  newbie question....importing a created class ridgerunnersjw 5 2,679 Oct-01-2020, 07:59 PM
Last Post: ridgerunnersjw
  error in class non_name092 1 1,948 Sep-02-2020, 05:42 PM
Last Post: bowlofred
  Class question robdineen 7 3,256 May-30-2020, 05:44 AM
Last Post: Calli
  Question about naming variables in class methods sShadowSerpent 1 2,024 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  class question jrauden 1 1,569 Feb-16-2020, 10:14 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020