Skip to content

Commit bf0047b

Browse files
3/31/25 01 functions skipped number guess
1 parent 170b168 commit bf0047b

4 files changed

Lines changed: 72 additions & 19 deletions

File tree

lessons/02_Loops/11_Iterable_Turtle.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 13,
5+
"execution_count": 2,
66
"metadata": {},
77
"outputs": [
88
{
@@ -11,7 +11,7 @@
1111
"<function turtle.exitonclick()>"
1212
]
1313
},
14-
"execution_count": 13,
14+
"execution_count": 2,
1515
"metadata": {},
1616
"output_type": "execute_result"
1717
}

lessons/02_Loops/12_More_Loops.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": 6,
53+
"execution_count": 1,
5454
"metadata": {},
5555
"outputs": [
5656
{
@@ -176,7 +176,7 @@
176176
},
177177
{
178178
"cell_type": "code",
179-
"execution_count": 9,
179+
"execution_count": 2,
180180
"metadata": {},
181181
"outputs": [
182182
{

lessons/02_Loops/13_Number_Guess.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,26 @@
3333
import random
3434
n = random.randint(1, 100)
3535
def ask_integer(prompt):
36-
"""Function to ask the user for an integer"""
3736
while True:
3837
try:
3938
return int(input(prompt))
4039
except ValueError:
4140
print("Please enter a valid number!")
4241

43-
44-
# Pick the random number
42+
while True:
43+
guess = ask_integer("Guess a number between 1 and 100: ")
44+
if guess <= n:
45+
print("Too low, guess again!")
46+
elif guess % 7 == 0:
47+
print("That is a very bad number, starting over")
48+
elif guess >= n:
49+
print("Too high, guess again!")
50+
elif guess == n:
51+
print("Correct, good job. Ending game!")
52+
break
53+
54+
# marked for review ask teacher oncampus
55+
# Pick the random number
4556

4657
# In your loop:
4758

lessons/03_Data_Structures_Func/01_Functions.ipynb

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": null,
41+
"execution_count": 1,
4242
"metadata": {},
43-
"outputs": [],
43+
"outputs": [
44+
{
45+
"name": "stdout",
46+
"output_type": "stream",
47+
"text": [
48+
"None\n"
49+
]
50+
}
51+
],
4452
"source": [
4553
"def do_nothing():\n",
4654
" pass\n",
@@ -83,17 +91,27 @@
8391
"cell_type": "code",
8492
"execution_count": null,
8593
"metadata": {},
86-
"outputs": [],
94+
"outputs": [
95+
{
96+
"name": "stdout",
97+
"output_type": "stream",
98+
"text": [
99+
"Bonjour, Alice!\n",
100+
"Hello, Alice!\n",
101+
"Hello, Bob!\n"
102+
]
103+
}
104+
],
87105
"source": [
88106
"# Demonstrate function arguments\n",
89107
"\n",
90108
"def greet_user(name, greeting):\n",
91109
" print(f\"{greeting}, {name}!\")\n",
92110
"\n",
93-
"# Call function with \"positional\" arguments. He first argument\n",
111+
"# Call function with \"positional\" arguments. The first argument\n",
94112
"# is assigned `name`, the second is assigned `greeting`.\n",
95113
"\n",
96-
"greet_user(\"Alice\", \"Bounjour\")\n",
114+
"greet_user(\"Alice\", \"Bonjour\")\n",
97115
"\n",
98116
"# We can also call the function with \"keyword\" arguments. This\n",
99117
"# allows us to specify the arguments in any order.\n",
@@ -133,9 +151,18 @@
133151
},
134152
{
135153
"cell_type": "code",
136-
"execution_count": null,
154+
"execution_count": 5,
137155
"metadata": {},
138-
"outputs": [],
156+
"outputs": [
157+
{
158+
"name": "stdout",
159+
"output_type": "stream",
160+
"text": [
161+
"Hello, Alice!\n",
162+
"Hello, Alice.\n"
163+
]
164+
}
165+
],
139166
"source": [
140167
"def greet_user(name, greeting='Hello', punct=\"!\"):\n",
141168
" print(f\"{greeting}, {name}{punct}\")\n",
@@ -160,9 +187,22 @@
160187
},
161188
{
162189
"cell_type": "code",
163-
"execution_count": null,
190+
"execution_count": 4,
164191
"metadata": {},
165-
"outputs": [],
192+
"outputs": [
193+
{
194+
"ename": "NameError",
195+
"evalue": "name 'punct' is not defined",
196+
"output_type": "error",
197+
"traceback": [
198+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
199+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
200+
"Cell \u001b[0;32mIn[4], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgreet_user\u001b[39m(name, greeting\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHello\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mgreeting\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m, \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mpunct\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 4\u001b[0m \u001b[43mgreet_user\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mAlice\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
201+
"Cell \u001b[0;32mIn[4], line 2\u001b[0m, in \u001b[0;36mgreet_user\u001b[0;34m(name, greeting)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgreet_user\u001b[39m(name, greeting\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHello\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mgreeting\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m, \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00m\u001b[43mpunct\u001b[49m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
202+
"\u001b[0;31mNameError\u001b[0m: name 'punct' is not defined"
203+
]
204+
}
205+
],
166206
"source": [
167207
"def greet_user(name, greeting='Hello'):\n",
168208
" print(f\"{greeting}, {name}{punct}\")\n",
@@ -216,7 +256,9 @@
216256
"\n",
217257
"assert find_char('x', 'My fox likes bricks') == 5\n",
218258
"assert find_char('z', 'There is a zebra in the garden') == 11\n",
219-
"assert find_char('w', \"I've lost my shoes\") == -1"
259+
"assert find_char('w', \"I've lost my shoes\") == -1\n",
260+
"\n",
261+
"find_char('')"
220262
]
221263
},
222264
{
@@ -513,7 +555,7 @@
513555
],
514556
"metadata": {
515557
"kernelspec": {
516-
"display_name": ".venv",
558+
"display_name": "Python 3",
517559
"language": "python",
518560
"name": "python3"
519561
},
@@ -527,7 +569,7 @@
527569
"name": "python",
528570
"nbconvert_exporter": "python",
529571
"pygments_lexer": "ipython3",
530-
"version": "3.11.9"
572+
"version": "3.12.4"
531573
}
532574
},
533575
"nbformat": 4,

0 commit comments

Comments
 (0)