Skip to content

Commit 9433d45

Browse files
polish up more things, add wordle challenge
1 parent 169fe0d commit 9433d45

File tree

6 files changed

+14989
-8
lines changed

6 files changed

+14989
-8
lines changed

File_Handling_and_Packages.ipynb

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,124 @@
261261
"# you can use example.txt for practice."
262262
],
263263
"id": "a03d6b6716f8ded8"
264+
},
265+
{
266+
"metadata": {},
267+
"cell_type": "markdown",
268+
"source": [
269+
"### practice challenge: word: le guessing game\n",
270+
"You have just stumbled upon a GENIUS game idea which has totally not been popularized by john wordle and bought by the new york times i PROMISE.\n",
271+
"So you've got six tries to guess a five letter word. The word will be randomly chosen from a list of five letter words contained in `words.txt`. If a user guesses a letter correctly, display it as green. If a user guesses a letter that is in the incorrect place, display it as yellow. If it's incorrect, display as gray.\n",
272+
"\n",
273+
"A few tips:\n",
274+
"- install the random package\n",
275+
"- use `string.split(seperator: string)` to split a string based on a seperator (maybe you could use this when reading this words file?)\n",
276+
"- treat the user input string as an array, so you can use array methods on it\n"
277+
],
278+
"id": "6eb5ccf5bb79fd95"
279+
},
280+
{
281+
"metadata": {
282+
"ExecuteTime": {
283+
"end_time": "2025-09-07T00:37:32.891846Z",
284+
"start_time": "2025-09-07T00:36:17.366945Z"
285+
}
286+
},
287+
"cell_type": "code",
288+
"source": [
289+
"#!pip install random\n",
290+
"import random\n",
291+
"import time\n",
292+
"\n",
293+
"with open(\"words.txt\", \"r\") as f:\n",
294+
" words = f.read()\n",
295+
" words = words.split(\"\\n\")\n",
296+
" the_word = random.choice(words)\n",
297+
" # the_word = \"apple\" # testing word\n",
298+
"\n",
299+
"def evaluate_word(word):\n",
300+
" status = [0,0,0,0,0] # 0 = incorrect, 1 = wrong place, 2 = correct\n",
301+
" word = list(word)\n",
302+
" checker = list(the_word)\n",
303+
" # check for correctness\n",
304+
" for i in range(len(word)): # always 5 but hardcoded constants are bad\n",
305+
" if word[i] == checker[i]:\n",
306+
" status[i] = 2\n",
307+
" checker[i] = \"_\" # placeholder to ensure no double-counting\n",
308+
" # check for wrong place\n",
309+
" for i in range(len(word)):\n",
310+
" if word[i] in checker:\n",
311+
" status[i] = 1\n",
312+
" checker[checker.index(word[i])] = \"_\"\n",
313+
"\n",
314+
" return status\n",
315+
"\n",
316+
"guess_amount = 0\n",
317+
"guesses_words = []\n",
318+
"while guess_amount < 6:\n",
319+
" guessed_word = input(\"Guess a word!\").strip()\n",
320+
" if len(guessed_word) > 5:\n",
321+
" print(\"Too many letters!\")\n",
322+
" continue\n",
323+
" elif len(guessed_word) < 5:\n",
324+
" print(\"Not enough letters!\")\n",
325+
" continue\n",
326+
" elif not guessed_word in words:\n",
327+
" print(\"That's not a valid word!\")\n",
328+
" continue\n",
329+
" guess_amount += 1\n",
330+
" status_list = evaluate_word(guessed_word)\n",
331+
" i = 0\n",
332+
" for code in status_list:\n",
333+
" if code == 2: # correct!\n",
334+
" print(\"\\033[97;102m\", flush = True, end = \"\")\n",
335+
" elif code == 1: # wrong place :/\n",
336+
" print(\"\\033[97;103m\", flush = True, end = \"\")\n",
337+
" else: # WRONG\n",
338+
" print(\"\\033[97;47m\", flush = True, end = \"\")\n",
339+
" print(guessed_word[i], end = \"\")\n",
340+
" i += 1\n",
341+
" time.sleep(0.25)\n",
342+
" print(\"\\033[0m\", flush = True, end = \"\") # reset colors!\n",
343+
" print()\n",
344+
" if guessed_word == the_word:\n",
345+
" print(\"That's Correct! It took you\", guess_amount, \" guesses to guess the word \", the_word)\n",
346+
" break\n",
347+
"\n"
348+
],
349+
"id": "e9ba521bbee23927",
350+
"outputs": [
351+
{
352+
"name": "stdout",
353+
"output_type": "stream",
354+
"text": [
355+
"\u001B[97;102ms\u001B[0m\u001B[97;103ml\u001B[0m\u001B[97;47ma\u001B[0m\u001B[97;47mt\u001B[0m\u001B[97;103me\u001B[0m\n",
356+
"\u001B[97;102ms\u001B[0m\u001B[97;103me\u001B[0m\u001B[97;103ml\u001B[0m\u001B[97;47ml\u001B[0m\u001B[97;47ms\u001B[0m\n"
357+
]
358+
},
359+
{
360+
"ename": "KeyboardInterrupt",
361+
"evalue": "Interrupted by user",
362+
"output_type": "error",
363+
"traceback": [
364+
"\u001B[31m---------------------------------------------------------------------------\u001B[39m",
365+
"\u001B[31mKeyboardInterrupt\u001B[39m Traceback (most recent call last)",
366+
"\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[14]\u001B[39m\u001B[32m, line 31\u001B[39m\n\u001B[32m 29\u001B[39m guesses_words = []\n\u001B[32m 30\u001B[39m \u001B[38;5;28;01mwhile\u001B[39;00m guess_amount < \u001B[32m6\u001B[39m:\n\u001B[32m---> \u001B[39m\u001B[32m31\u001B[39m guessed_word = \u001B[38;5;28;43minput\u001B[39;49m\u001B[43m(\u001B[49m\u001B[33;43m\"\u001B[39;49m\u001B[33;43mGuess a word!\u001B[39;49m\u001B[33;43m\"\u001B[39;49m\u001B[43m)\u001B[49m.strip()\n\u001B[32m 32\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mlen\u001B[39m(guessed_word) > \u001B[32m5\u001B[39m:\n\u001B[32m 33\u001B[39m \u001B[38;5;28mprint\u001B[39m(\u001B[33m\"\u001B[39m\u001B[33mToo many letters!\u001B[39m\u001B[33m\"\u001B[39m)\n",
367+
"\u001B[36mFile \u001B[39m\u001B[32m~/PycharmProjects/pythonlessons/.venv/lib/python3.13/site-packages/ipykernel/kernelbase.py:1275\u001B[39m, in \u001B[36mKernel.raw_input\u001B[39m\u001B[34m(self, prompt)\u001B[39m\n\u001B[32m 1273\u001B[39m msg = \u001B[33m\"\u001B[39m\u001B[33mraw_input was called, but this frontend does not support input requests.\u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m 1274\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m StdinNotImplementedError(msg)\n\u001B[32m-> \u001B[39m\u001B[32m1275\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_input_request\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m 1276\u001B[39m \u001B[43m \u001B[49m\u001B[38;5;28;43mstr\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mprompt\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1277\u001B[39m \u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_parent_ident\u001B[49m\u001B[43m[\u001B[49m\u001B[33;43m\"\u001B[39;49m\u001B[33;43mshell\u001B[39;49m\u001B[33;43m\"\u001B[39;49m\u001B[43m]\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1278\u001B[39m \u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mget_parent\u001B[49m\u001B[43m(\u001B[49m\u001B[33;43m\"\u001B[39;49m\u001B[33;43mshell\u001B[39;49m\u001B[33;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1279\u001B[39m \u001B[43m \u001B[49m\u001B[43mpassword\u001B[49m\u001B[43m=\u001B[49m\u001B[38;5;28;43;01mFalse\u001B[39;49;00m\u001B[43m,\u001B[49m\n\u001B[32m 1280\u001B[39m \u001B[43m\u001B[49m\u001B[43m)\u001B[49m\n",
368+
"\u001B[36mFile \u001B[39m\u001B[32m~/PycharmProjects/pythonlessons/.venv/lib/python3.13/site-packages/ipykernel/kernelbase.py:1320\u001B[39m, in \u001B[36mKernel._input_request\u001B[39m\u001B[34m(self, prompt, ident, parent, password)\u001B[39m\n\u001B[32m 1317\u001B[39m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mKeyboardInterrupt\u001B[39;00m:\n\u001B[32m 1318\u001B[39m \u001B[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001B[39;00m\n\u001B[32m 1319\u001B[39m msg = \u001B[33m\"\u001B[39m\u001B[33mInterrupted by user\u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m-> \u001B[39m\u001B[32m1320\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mKeyboardInterrupt\u001B[39;00m(msg) \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[32m 1321\u001B[39m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mException\u001B[39;00m:\n\u001B[32m 1322\u001B[39m \u001B[38;5;28mself\u001B[39m.log.warning(\u001B[33m\"\u001B[39m\u001B[33mInvalid Message:\u001B[39m\u001B[33m\"\u001B[39m, exc_info=\u001B[38;5;28;01mTrue\u001B[39;00m)\n",
369+
"\u001B[31mKeyboardInterrupt\u001B[39m: Interrupted by user"
370+
]
371+
}
372+
],
373+
"execution_count": 14
374+
},
375+
{
376+
"metadata": {},
377+
"cell_type": "code",
378+
"outputs": [],
379+
"execution_count": null,
380+
"source": "",
381+
"id": "ce2445f4923f7e21"
264382
}
265383
],
266384
"metadata": {

Intro_To_Python.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"\n",
2121
"sooo its almost 9pm as i right these words. my brain is slowly melting. i have spent the better part of an hour debugging my wifi drivers on my twinkpad. i have been grinding out these lessons over the past week and a half, and its been taking a toll. ive gone back to write this as an apology for any mistakes or lack of clarity. i write this as someone who has been programming for a handful of years, and i understand that some of the concept that i take for granted, you may have never heard of. i apologize if i do not explain something, please dont hesitate to ask me about it. ill do my best to explain.\n",
2222
"\n",
23-
"The other thing is that im not exactly the best writer. i barely passed english 2 sophomore year. my writing quality is proportional to the amount of sleep i got, and i didnt get much sleep last night. as the weeks go by, youll probably be able to tell that it starts out very professional like and slowly degrades into a casual conversation, please forgive me. i tend to write how i would speak to y'all, which explains the casual tone and constant comma splices lmao. i tried to write inside jokes and memes into the lessons to make them more fun so if you think its dry im sorry :sob: ill try to write more skibidi brainrot into the lessons or whatever yall like these days i dont keep up with the trends :pensive-wobble: my fyp is like not representative of anything thats actually popular on tiktok or insta anymore its just things i laugh at :p\n"
23+
"The other thing is that im not exactly the best writer. i barely passed english 2 sophomore year. my writing quality is proportional to the amount of sleep i got, and i didnt get much sleep last night. as the weeks go by, youll probably be able to tell that it starts out very professional like and slowly degrades into a casual conversation, please forgive me. i tend to write how i would speak to y'all, which explains the casual tone and constant comma splices lmao. i tried to write inside jokes and memes into the lessons to make them more fun so if you think its dry im sorry\n"
2424
],
2525
"id": "5cfc0bb57c4e4fb9"
2626
},

Loops_And_Logic.ipynb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,8 @@
499499
{
500500
"metadata": {},
501501
"cell_type": "markdown",
502-
"source": "",
502+
"source": "Timing your loops:",
503503
"id": "4422e8750229c1c6"
504-
},
505-
{
506-
"metadata": {},
507-
"cell_type": "markdown",
508-
"source": "",
509-
"id": "9e42641679a367c9"
510504
}
511505
],
512506
"metadata": {

solutions.ipynb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@
209209
"print(f\"We've repainted our car! {ol_reliable}\")"
210210
],
211211
"id": "9367f77632cbe6c6"
212+
},
213+
{
214+
"metadata": {},
215+
"cell_type": "markdown",
216+
"source": [
217+
"# File Handling And Packges Challenge problem - le word game\n",
218+
"this is just one possible implementation of le word game. there's likely so many other ways to do it, but this is what i cooked up."
219+
],
220+
"id": "cb5dcc1cfae15dc"
212221
}
213222
],
214223
"metadata": {

stubs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from time import sleep
2+
def printslowcolor(text):
3+
for char in text:
4+
print(char, end='', flush=True)
5+
sleep(0.05)

0 commit comments

Comments
 (0)