Angela’s project was somewhat heavier with its function usage. She used a function for every major (and repeatable) action in the game (dealing a card, calculating scores, comparing scores). I used a function for the overall game logic, which had two nested functions (game over and ace value changer).
Angela’s project handled the value changes of Aces by removing them from the hand as an 11 and appending them as a 1. I felt this was clunkier than my solution, which re-wrote the hand to a new variable by re-writing 11s as 1s. However, I realized that this creates a bug in scenarios where 2 Aces are drawn (both would be converted to a 1 value).
If I were to spend a significant amount of time on this project, I would do the following:
Use libraries to map the actual card names to their point values.
Implement a betting system.
Use lists called original_deck and dealt_cards to accurately represent which cards are remaining in the deck to be dealt. This would give a more accurate representation on the probability of the remaining cards being dealt.
Learned about scope
Local scope – elements created inside of a function are only accessible inside the function.
Global scope – elements created at the global (highest level) are accessible anywhere.
Namespace – An elements existence as a name in its respective scope in the code
Block scope does not exist in python (e.g. elements created in loops will exist at the scope of their enclosing function or global, depending on where they are located)
Identically-named variables existing in different scopes are completely different variables. (Re-using names is also discouraged)
Generally, you should not try to directly update global elements locally (instead make use of “return”
Try to use local scope as much as possible, but global is often useful for constants. (e.g. pi)
Global constants should be named in all caps
Mystery Number – Computer randomly chooses a number between 1 and 100. Depending on the difficulty selected, the user has either 5 or 10 attempts to guess the number. Wrong guesses trigger feedback as to whether the guess was too high or too low.
Describe the problem – Outline the errant code, including the expected behavior vs actual behavior.
Reproduce the bug – Try to intentionally recreate the failure condition so that remedial steps can be determined.
Play computer / evaluate each line – Step through the code and interpret the instructions as if you were the computer.
Fix the errors – Read errors on the console. Fix them if they are straightforward, google the errors if you do not understand. Remember, not all errors will produce a message on the console.
Use print() – Print variables from the code to get a peek into their values, which will help identify any issues.
Other Misc Tips:
Take a break if you are stumped
Ask a friend for an outside perspective / fresh eyes
Run often – Regularly test the code while you are writing it to catch bugs early
StackOverflow – Search existing answers, ask new ones.
None – debugged sabotaged code on three existing apps.
Project Day: Build “Higher / Lower” game
Game asks you to guess if a celebrity has more / less Twitter followers than a second celebrity.
Game comes with two pre-filled .py files. One file contains the game’s ASCII art, the other contains a list of libraries (each library representing a celebrity). No API is used for real-time data.
Emphasis of the assignment was on breaking the project into program requirements and TODO tasks.
Completed the project successfully. This project feels like a turning point in my coding approach. Using functions for repeatable tasks (instead of putting the code directly in the main logic) felt natural. Breaking the app development into smaller tasks seemed like random chaos at first, but it really made the overall process much quicker. By the end, I was mostly assembling large blocks of codes and only making minor tweaks.
Installed Python 3.10 locally.
Installed PyCharm IDE.
Reviewed benefits of PyCharm.
Built-in spell check.
Larger, more configurable UI
Built-in “linter” – identifies style-guide faux pas
Local history – see version history on the Python files.
View Structure – Provides outline-type navigation of the code for quick maneuvering.
Refactor / Rename = Update element names throughout the entire code simultaneously.
More robust debugging
Coffee Machine – Virtual coffee machine offers a limited menu of hot beverages. Machine contains a finite amount of resources (coffee, water, milk) to create the beverages. Coffee dispenses based on available resources and the user’s ability to pay. Reports are also run to determine remaining resources and money collected.