Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final pull request #228

Open
wants to merge 24 commits into
base: clara_eminente
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
763 changes: 763 additions & 0 deletions .ipynb_checkpoints/01_Fundamentals-checkpoint.ipynb

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions .ipynb_checkpoints/01ex_Fundamentals-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1\\. Write the following as a list comprehension"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2\\. Converte the following function into a pure function with no global variables or side effects"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3\\. Write a `decorator` hello that makes every wrapped function print “Hello!”, i.e. something like:\n",
"\n",
"```python\n",
"@hello\n",
"def square(x):\n",
" return x*x\n",
"```\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4\\. Write the factorial function so that it a) does and b) does not use recursion."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"5\\. Edit the class defintion to add an instance attribute of is_hungry = True to the Dog class. Then add a method called eat() which changes the value of is_hungry to False when called. Figure out the best way to feed each dog and then output “My dogs are hungry.” if all are hungry or “My dogs are not hungry.” if all are not hungry. The final output should look like this:\n",
"\n",
"`I have 3 dogs. \n",
"Tom is 6. \n",
"Fletcher is 7. \n",
"Larry is 9. \n",
"And they're all mammals, of course. \n",
"My dogs are not hungry.\n",
"`\n",
"\n",
"```python\n",
"# Parent class\n",
"class Dog:\n",
"\n",
" # Class attribute\n",
" species = 'mammal'\n",
"\n",
" # Initializer / Instance attributes\n",
" def __init__(self, name, age):\n",
" self.name = name\n",
" self.age = age\n",
"\n",
" # instance method\n",
" def description(self):\n",
" return \"{} is {} years old\".format(self.name, self.age)\n",
"\n",
" # instance method\n",
" def speak(self, sound):\n",
" return \"{} says {}\".format(self.name, sound)\n",
"\n",
"# Child class (inherits from Dog class)\n",
"class RussellTerrier(Dog):\n",
" def run(self, speed):\n",
" return \"{} runs {}\".format(self.name, speed)\n",
"\n",
"# Child class (inherits from Dog class)\n",
"class Bulldog(Dog):\n",
" def run(self, speed):\n",
" return \"{} runs {}\".format(self.name, speed)\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading