damsel in distress - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html) +--- Forum: Bar (https://python-forum.io/forum-27.html) +--- Thread: damsel in distress (/thread-10793.html) |
damsel in distress - martav - Jun-06-2018 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 I m 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. husband s 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 RE: damsel in distress - micseydel - Jun-07-2018 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()
RE: damsel in distress - martav - Jun-09-2018 Thanks, that looks great! RE: damsel in distress - Nwb - Jun-12-2018 I think you should write your name too! 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 RE: damsel in distress - martav - Jun-13-2018 (Jun-12-2018, 03:13 PM)Nwb Wrote: I think you should write your name too! I haven't even thought of adding my name haha good thinking! And thanks for the code! :) |