Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
damsel in distress
#1
Hi everyone

Basically my husband is a developer and uses Python. With father`s day approaching I came up with an idea of a t shirt with child/parent classes printed on it, using my husbands and daughters names, I remembered my husband trying to explain it to me one day, hence the idea.
Now I spent best part of the day reading through forums and watching tutorials, and Im still baffled by what the code should look like. All I want is couple of simple lines of code, including first and last name, so e.g. husbands name is John Smith, daughter`s name is Jane Smith. From what I understood I start with
class Smith
def _init_(self and here I have no idea what follows but all i want is for this to print John Smith

then the child class is class Jane (Smith) and again all I want is to have Jane Smith printed under John

Hope that makes sense. I won`t be running that code anywhere, it will just be printed on a t shirt, still, I would like it to be correct lol

Hope someone can help!

Cheers, Marta
Reply
#2
Something perhaps like...
class Smith:
  lastname = "Smith"
  def say_hello(self):
    print(f"Hi, I'm {self.firstname} {self.lastname}!")

class John(Smith):
    firstname = "John"

class Jane(Smith):
    firstname = "Jane"


# not on the shirt but an example in action...
John().say_hello()
Jane().say_hello()
Output:
Hi, I'm John Smith! Hi, I'm Jane Smith!
Reply
#3
Thanks, that looks great!
Reply
#4
I think you should write your name too! Smile

Here's my idea:

def Smith(): #Basically the best family in the world.

    def John(): 
        Father = "A wizard" 
    def Mom's Name():
        Mother = "Owns rights to the family"
    
    def Jane():
        Daguhter = "Obeys."
Change the quotes to anything you find suitable and humorous. Anyways I think your idea is really very intelligent! :D
Reply
#5
(Jun-12-2018, 03:13 PM)Nwb Wrote: I think you should write your name too! Smile

I haven't even thought of adding my name haha good thinking! And thanks for the code! :)
Reply


Forum Jump:

User Panel Messages

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