Skip to content

Instantly share code, notes, and snippets.

@germannp
Created January 29, 2026 08:21
Show Gist options
  • Select an option

  • Save germannp/73ee1d004241980b18e1e7fa9a1e5b04 to your computer and use it in GitHub Desktop.

Select an option

Save germannp/73ee1d004241980b18e1e7fa9a1e5b04 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "7ae178c0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"roaaaar\n"
]
}
],
"source": [
"class Animal:\n",
" def __init__(self, name, num_legs, noise):\n",
" self.name = name\n",
" self.num_legs = num_legs\n",
" self.noise = noise\n",
"\n",
" def make_some_noise(self):\n",
" print(self.noise)\n",
"\n",
"\n",
"tiger = Animal(\"Tiger\", 4, \"roaaaar\")\n",
"tiger.make_some_noise()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e0277399",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"muuuhhh\n"
]
}
],
"source": [
"cow = Animal(\"Cow\", 4, \"muuuhhh\")\n",
"cow.make_some_noise()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "381f7d97",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tiger.num_legs + cow.num_legs * 2"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1797c0e2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"muuuhhh\n",
"muuuhhh\n",
"muuuhhh\n",
"muuuhhh\n"
]
}
],
"source": [
"class Farm:\n",
" def __init__(self, num_cows):\n",
" self.cows = [cow] * num_cows\n",
"\n",
"\n",
"farm = Farm(4)\n",
"for cow in farm.cows:\n",
" cow.make_some_noise()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f55902e9",
"metadata": {},
"outputs": [],
"source": [
"class Mamal(Animal):\n",
" def __init__(self, name, num_legs, noise, pregnancy_time):\n",
" super().__init__(name, num_legs, noise)\n",
" self.pregnancy_time = pregnancy_time"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4380210f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"it's rainingf men halleluia\n"
]
}
],
"source": [
"woman = Mamal(\"woman\", 2, \"it's rainingf men halleluia\", \"9month\")\n",
"woman.make_some_noise()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f053c5e3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'9month'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"woman.pregnancy_time"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "3b9670b4",
"metadata": {},
"outputs": [],
"source": [
"def make_some_noise(animals):\n",
" for animal in animals:\n",
" animal.make_some_noise()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d390d426",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"muuuhhh\n",
"roaaaar\n",
"it's rainingf men halleluia\n"
]
}
],
"source": [
"make_some_noise([cow, tiger, woman])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment