Python Forum
Class code problem from CS Dojo YouTube
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class code problem from CS Dojo YouTube
#1
class Robot:
def introduce_self(self)
print("My name is " + self.name)

r1 = Robot()
r1.name = "Tom"
r1.color = "red"
r1.weight = 30

r2 = Robot()
r2.name = "Jerry"
r2.color = "blue"
r2.weight = 40

r1.introduce_self()
r2.introduce_self()
With the above code, copied from the YouTube channel of CS Dojo, I get a traceback
"name 'r1' is not defined.
Reply


Messages In This Thread
Class code problem from CS Dojo YouTube - by Dixon - Feb-04-2020, 07:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How does this code create a class? Pedroski55 6 445 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
  class definition and problem with a method HerrAyas 2 271 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Class function is not running at all even though it is clearly run in the code SheeppOSU 2 2,123 Sep-26-2020, 10:54 PM
Last Post: SheeppOSU
  Practice problem using lambda inside the class jagasrik 3 2,178 Sep-12-2020, 03:18 PM
Last Post: deanhystad
  [split] Python Class Problem astral_travel 12 5,025 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Python Class Problem JPCrosby 2 2,308 Apr-28-2020, 06:18 PM
Last Post: buran
  Class problem duckduck23 2 2,036 Feb-10-2020, 08:52 PM
Last Post: jefsummers
  Class Problem scratchmyhead 3 2,351 Nov-19-2019, 08:28 AM
Last Post: Larz60+
  problem with class method AmirAB 3 3,417 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  A problem with child class Truman 2 2,810 Jul-02-2018, 12:37 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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