"## Warmup 1: Jupyter Notebook stuck in `[*]`?\n",
"\n",
"Press the Stop button! It's probably waiting for input. Otherwise, **restart** the kernel! (and run the cells)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = int(input(\"Type in a number: \"))\n",
"print(\"The number is \" + str(x), x + 1, x + 2, x + 3, x + 4, sep=\" then \", end=\"!\\n\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Warmup 2: Write a function that prints the factorial of parameter num"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def do_factorial(num):\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Warmup 3: Complete the code to print a treasure map\n",
"The map should be a grid of size `width` and `height` with `symbol` everywhere, expect at the location: `treasure_row`, `treasure_col`, where an `'X'` is placed."
"## Example 3: How many students are in Data Science or Statistics?\n",
"\n",
"**BONUS:** Can you express this as a percentage?\n",
"\n",
"**BONUS+:** ...rounded to 2 decimal places?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# write your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 4: How many early birds are there below the age of 21?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"early_birds = 0\n",
"for i in range(project.count()):\n",
" sleep_habit = project.get_sleep_habit(i)\n",
" age = project.get_age(i)\n",
" if ...: # TODO Complete this condition!\n",
" early_birds += 1\n",
" \n",
"print(\"There are\", early_birds, \"early birds below the age of 21.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 5: What percentage of 20-year-olds are early birds?\n",
"\n",
"**Bonus:** How can we generalize our code to 'What percentage of x-year-olds are early birds?'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# write your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 6: What is the age of the oldest student?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"max = 0\n",
"for i in range(project.count()):\n",
" student_age = int(project.get_age(i))\n",
" if student_age != \"\" and student_age > max:\n",
" max = student_age \n",
"print(\"The oldest student is\", max)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 7: What is the age of the youngest student?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# write your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Other tasks for you to try...\n",
"- What is the average age of the class?\n",
"- What is the class's favorite pizza topping?\n",
"- What is the most popular major?\n",
"- For all students that have another major, print out what it is.\n",
"- What zip code do the majority of pineapple-eating night owls live in?"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% Cell type:markdown id: tags:
## Warmup 1: Jupyter Notebook stuck in `[*]`?
Press the Stop button! It's probably waiting for input. Otherwise, **restart** the kernel! (and run the cells)
%% Cell type:code id: tags:
``` python
x=int(input("Type in a number: "))
print("The number is "+str(x),x+1,x+2,x+3,x+4,sep=" then ",end="!\n")
```
%% Cell type:markdown id: tags:
## Warmup 2: Write a function that prints the factorial of parameter num
%% Cell type:code id: tags:
``` python
defdo_factorial(num):
pass
```
%% Cell type:markdown id: tags:
## Warmup 3: Complete the code to print a treasure map
The map should be a grid of size `width` and `height` with `symbol` everywhere, expect at the location: `treasure_row`, `treasure_col`, where an `'X'` is placed.