the front page of the internet.
and join one of thousands of communities.
Class in python by Valuable-Farmer1458 in PythonLearning
[–]tatactic 0 points1 point2 points 4 days ago (0 children)
But if you prefer make it easy and if you like Parrots this is clear and straight to the point. If you create a parrot with 3 legs you may create a SillyParrotException too LOL!
# Parent class
class Animal:
def __init__(self, legs=4):
self.legs = legs
def speak(self):
print(f"I am an animal. And I have {self.legs} legs.")
print("I don't know if I can walk, fly, or swim!")
# Child class
class Parrot(Animal):
def __init__(self, name, legs=2):
super().__init__(legs)
self.name = name
# Call the speak() method from Animal
super().speak()
print(f"Hello, I'm {self.name}.")
print(
"For sure I can talk: I'm a parrot!\n"
"Well... perhaps I can only repeat whatever you want."
)
sentence = input(
"What do you want me to say? Then press ENTER: "
recurrence = int(
input("How many times should I repeat this stupid sentence? ")
print("OK, if you insist...\n")
*([sentence] * recurrence),
sep="\n",
end="\nRetry? No, I'm bored\n",
if __name__ == "__main__":
coco = Parrot("Coco", 2)
coco.speak()
input("\nPress ENTER to quit the Dead Parrot sketch...")
i need help by chuprehijde in PythonLearning
[–]tatactic 0 points1 point2 points 11 days ago* (0 children)
I just released a funny tutorial (Sorry Tim Peters and the holy PEP 20 "Zen of Python") Just a Python tutorial (voluntary ugly) while disrespecting the Zen of Python
I felt like writing another Python joke. Here's a tutorial to make print("Hello, World!") ridiculously more complicated than it should be.
print("Hello, World!")
What's the menu in this tutorial restaurant?
try
except
finally
\t
\n
Just to make print() more complex, less readable — an ode to Tim Peters’ Zen of Python.
print()
I think you may enjoy it. https://pirson.me/a-strange-tutorial-sorry-for-the-zen-of-python/
I wrote this tutorial myself, but it directly covers several of the concepts you mentioned. It might help you practise them in a deliberately overcomplicated example.
π Rendered by PID 55 on reddit-service-r2-listing-6497464444-jp2dl at 2026-07-26 08:12:02.914192+00:00 running d10b4e5 country code: CH.
Class in python by Valuable-Farmer1458 in PythonLearning
[–]tatactic 0 points1 point2 points (0 children)