Skip to main content

Posts

Showing posts from June, 2026

365 DAYS OF CODE - DAY 31

I am so glad we learned to use other's classes before attempting to create ours. I think it's a better approach to learning about it. You can use the keyword "pass" to create an empty class or function. To name a class, the first letter of every word should be capitalized (i.e., PascalCase) Another type is the camelCase.  And another is the snake_case. PascalCase is used for class names and snake_case for everything else in python programming. 

365 DAYS OF CODE - DAY 28

Final Coffee Machine Code: from menu import Menu from coffee_maker import CoffeeMaker from money_machine import MoneyMachine coffee_maker = CoffeeMaker() menu = Menu() money_machine = MoneyMachine() coffee_on = True def handle_prompt (prompt): global coffee_on if prompt == "off" : coffee_on = False return elif prompt == "report" : coffee_maker.report() print ( f"Money: { money_machine.profit } " ) elif menu.find_drink(prompt): drink = menu.find_drink(prompt) if not coffee_maker.is_resource_sufficient(drink): print ( f"Sorry there is not enough { drink.name } ." ) return successful_payment = money_machine.make_payment(drink.cost) if successful_payment: coffee_maker.make_coffee(drink) else : print ( f"Sorry there is not enough { prompt } ." ) while coffee_on: prompt = input ( "What would you like? (espr...

365 DAYS OF CODE - DAY 27

  Watched a friend write these: from menu import Menu, MenuItem from coffee_maker import CoffeeMaker from money_machine import MoneyMachine def what_to_do_next (): pass def handle_prompt (prompt): if prompt == "off" : coffee_on = False return elif prompt == "report" : report = coffee_maker.report() print (report) coffee_maker = CoffeeMaker() coffee_on = True while coffee_on == True : prompt = input ( "What would you like? (espresso/latte/cappuccino): " ) handle_prompt(prompt)

365 DAYS OF CODE - DAY 24

I have noticed that I am not grinding enough. I do not know how to put it. It does feel like I am not putting in enough work which I plan on fixing from today. Continuing from yesterday, A class is written with the first letter of each word capitalizes (i.e., in pascal case) to differentiate it from all the variables and function names where each word is separated by underscores. food = FoodBlueprint() where food is the object       FoodBlueprint() is the class You can find Python Packages at  pypi.org   To install a package into our project, On MacBook -> PyCharm - preferences -  project - project interpreter - click on the plus button to install any package that you find on PyPI - search for the package - click install For windows -> file - settings -  "project - project interpreter - click on the plus button to install any package that you find on PyPI - search for the package - click install" should follow but I could not find project ...

365 DAYS OF CODE - DAY 23

Today, on day 16, we looked at Object Oriented Programing (OOP), why it is needed and how it works. what an object has = attributes = variables associated to a moduled object what an object can do = methods = functions Essentially, an object is just a way of combining some piece of data and some functionality all together in the same thing. we can generate multiple versions of the same object from the same blueprint (i.e., a class)

365 DAYS OF CODE - DAY 22

Modified code from yesterday . MENU = { "espresso" : { "ingredients" : { "water" : 50 , "coffee" : 18 , }, "cost" : 1.5 , }, "latte" : { "ingredients" : { "water" : 200 , "milk" : 150 , "coffee" : 24 , }, "cost" : 2.5 , }, "cappuccino" : { "ingredients" : { "water" : 250 , "milk" : 100 , "coffee" : 24 , }, "cost" : 3.0 , } } resources = { "water" : 300 , "milk" : 200 , "coffee" : 100 , "money" : 0 , } coffee_price = 0 quarters = 0 dimes = 0 nickels = 0 pennies = 0 water_needed = 0 milk_needed = 0 coffee_needed = 0 def report (): """outputs a present state r...

365 DAYS OF CODE - DAY 21

I tried using functions for the coffee machine program, but it's just not working out well. Especially the fact that you cannot break out of it. My present code for today. MENU = { "espresso" : { "ingredients" : { "water" : 50 , "coffee" : 18 , }, "cost" : 1.5 , }, "latte" : { "ingredients" : { "water" : 200 , "milk" : 150 , "coffee" : 24 , }, "cost" : 2.5 , }, "cappuccino" : { "ingredients" : { "water" : 250 , "milk" : 100 , "coffee" : 24 , }, "cost" : 3.0 , } } resources = { "water" : 300 , "milk" : 200 , "coffee" : 100 , "money" : 0 , } coffee_price = 0 quarters = 0 di...

365 DAYS OF CODE - DAY 20

I am an intermediate student now. Today, we were tasked to create a coffee machine. Find PyCharm Keyboard Shortcuts here . Find Windows Keyboard Tips and Tricks here . Find How to Use Emoji and Symbols on Mac here . Emojipedia

365 DAYS OF CODE - DAY 19

I started coding today’s exercise from yesterday since we focused mainly on debugging. I am trying to become a good programmer by adding comments to my code. My Higher Lower Game Code: # import modules import random import art from game_data import data score = 0 A = [] while True : # print logo print (art.logo) # select 2 options from the game data if A == []: A = random.choice(data) B = random.choice(data) while B == A: B = random.choice(data) print ( f"Compare A: { A[ 'name' ] } , a { A[ 'description' ] } , from { A[ 'country' ] } ." ) print (art.vs) print ( f"Against B: { B[ 'name' ] } , a { B[ 'description' ] } , from { B[ 'country' ] } ." ) # get user input choice = input ( "Who has more followers? Type 'A' or 'B': " ).upper() if choice == "A" : chosen = A[ 'follower_count' ] not_chosen =...

365 DAYS OF CODE - DAY 18

The first documented bug was first found by Grace Hopper. Steps in Debugging (Tips and Techniques): Describe the Problem – If the problem is messy and it is not well understood in your head, it is almost impossible to debug it. You have to untangle the problem and try to make sense of what is going on. Reproduce the Bug – Bugs that show up occasionally are quite difficult to debug. Reproducing the bug helps you discover the problem. (Not too understandable but ok) Remember on day 2 when I said I was a computer sometimes?? The next technique is to Play Computer: The skill of pretending to be a computer, reading through your code and imagining what you are going to do each time is really useful especially when you are debugging. When the editor or console is giving you an error, fix them before you continue. On the console, copy the error message that is not specific to your code and google search adding python to it to be specific. Stack Overflow is a place that offers go...

365 DAYS OF CODE - DAY 17

I am starting today with a new attitude, like I stated yesterday. And it kind of feels different and exciting. I am excited to face the challenges ahead. Hopefully it lasts (my excitement not the challenges to be precise). But is there a way to rid ourselves of challenges?? I do not know. What I know is that it gets easier to solve them. Maybe. Hopefully. Without further ado, I wish Microsoft word gives word/sentence suggestions by the way (totally unrelated to today’s agenda). Today, continuing day 12 of the prestigious 100 days of python course on Udemy, I learned how to modify global variables in a local scope (i.e., a function) by calling it in the function (like so: global variable). It is advised to avoid modifying global scope because it makes your code prone to errors :( If you need to modify a global scope variable with a function, use the return statement instead. Like so: Code from class: enemies = 1 def increase_enemies (enemy):     print ( f"e...