When life gets fast… slow it down

Yeah, I’m dragging my butt through the #100daysofcode program. A warning signal is going off in my head, this is not how you create a new habit. But also, you should not kill yourself to force a new habit. You need it to be easy, otherwise if it becomes hard then you hit resistance, and resistance is a brutal killer of new habits. So if you need to take an extra day to continue on your habit that is okay, but be sure to do the minimum you can everyday. Lets look at what I’ve been working on over the last weekend.

Day 3 – Leap Year

Write a program that works out whether if a given year is a leap year. A normal year has 365 days, leap years have 366, with an extra day in February.

Dr Angela Yu. 100 Days of Code: The Complete Python Pro Bootcamp for 2022

I spent extra time to document the process of figuring this out. When the code gets topsy turvy like this I like to write it out in english, it helps tease out the flaws in my logic. I made Several bugs writing this, like not setting the flag false if it is not divisible by 4. I removed an extra if statement and moved the assumption statement to be prominent at the top.

The last line 25 is a bit of trick, rather than use if then else to print the statement I used the position in the array to print out the right statement. There are two results. False = 0 and True = 1. So I used the positions 0 and 1 in the Array to store the values. When I print the result I use the True/False variable to select which statement to use.

Day 3 – Pizza Shop

Another if else test. I didn’t use elif. I could have used elif for the pizza size, but didn’t feel it needed it to make it better.
What I like about code like this is I can simulate the process. And holy shit this is an epiphany! I should use this to document my processes at work! Let’s stay on task though, I’ll write about that next. Back to why I like this, the person who is taking an order needs to understand that additional pepperoni is a different charge for the size of pizza. So that logic needs to be trained to the new employee. But something like this is never mentioned during training. It’s always added when someone realizes the total is not right, then they go back and tell the new employee about the different rates of pepperoni charges.

I feel like coding is a way to document this better than with a flow chart. I find flow charts are cumbersome to illustrate.

# 🚨 Don't change the code below 👇
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M, or L ")
add_pepperoni = input("Do you want pepperoni? Y or N ")
extra_cheese = input("Do you want extra cheese? Y or N ")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇
price_small_pizza    = 15
price_medium_pizza   = 20
price_large_pizza    = 25
ad_pepperoni_small   = 2
ad_pepperoni_medplus = 3
ad_ex_cheese         = 1

total_price = 0
if size == 'S' or size == 's' :
    total_price += price_small_pizza
    if add_pepperoni == 'Y' :
        total_price += ad_pepperoni_small
if size == 'M' :
    total_price += price_medium_pizza
    if add_pepperoni == 'Y' :
        total_price += ad_pepperoni_medplus
if size == 'L' :
    total_price += price_large_pizza
    if add_pepperoni == 'Y' :
        total_price += ad_pepperoni_medplus
if extra_cheese == 'Y' :
    total_price += ad_ex_cheese

print(f'Your final bill is: ${total_price}.')

Code as documentation brain spill

I don’t like documentation to explain processes. The usual process is that I need to write documentation, then I share it around. People usually look it over but don’t take time to read it and process it. I end up having to verbally explain nuances in a meeting and people look at me weird, then agree it’s fine, and the documentation is never brought up again, until someone needs it. Then we may update it. The greater problem with this is it is not a suitable documentation method. If I wrote a simple javascript program in an HTML page then people could simulate the process.
I’m thinking the ticketing process for new laptops. I could create a text based adventure game for creating a new laptop request, and simulate it through to the end. I could write a simulator for the whole process. Cool!

So I tried to write a simple demo, but there is overhead of interacting with the end user. So I found a terminal emulator library here:
I’ll take a look at this to see if I can use it…

Day 3 Love Calculator

Another day IRL has passed. Meanwhile I’m still on day three of the python programming course. Aside from not feeling well, I enjoy taking the time to play with the code somewhat. For this lab I mixed up what I was supposed to be tallying. So I needed to add in some debug messages.

print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")

lower_names = [name1.lower(), name2.lower()]
test_words = ["true","love"]
match_res = []
total_score = 0
##### Test how many times each letter in the test word matches in a name
for aword in test_words:                           # Cycle through the test words
    letter_hits = 0                                # Reset the word hit counter
    for aname in lower_names:                      # Cycle through the names
        for wletter in aword:                      # Cycle through the letters of word
            countres = aname.count(wletter)        # Count instances of letter
            letter_hits += countres                # Add it to tally
            #print("{} finds {} of {}".format(aname,countres,wletter))  # Debug Print
    match_res.append(letter_hits)                  # Save count of the hits in names
    #print("{} tested with word {} result is {}".format(aname,aword,letter_hits))  # debug

#funky Love test rule combine the numbers as strings to makeup new number
match_score = int( str(match_res[0]) + str(match_res[1]) )

if match_score < 10 or match_score > 90:
    print("Your score is {}, you go together like coke and mentos.".format(match_score))
elif match_score < 50 and match_score > 40:
    print("Your score is {}, you are alright together.".format(match_score))
    print("Your score is {}.".format(match_score))

Tanya and I score 54. I take it that is good, otherwise…

Welcome to the Love Calculator!
What is your name? 
Billy Baker
What is their name? 
Tanya Baker

Python basics in 100 days of code

At work a funny thing happens. I love working with computers, I think I’m a lucky guy. At work though I have so many distractions that I can’t get work done. For every distraction it drains my attention on what I’m doing, and when it exceeds a certain level then I’m not very useful.

When I go home and rest for a while, I’m drained, I don’t want to do much, it would be so easy to turn on the TV. Sometimes I go for a walk, but I’ll drag along, it’s been a long day and I just want to rest.

The funny thing that happens, is that I go sit at the computer and do something as simple as work on some basic Python challenges and I find it rejuvenating. I find following along a good course like Dr Angela Yu’s 100 projects in Python is a perfect blend of guided meditation and problem solving that it gets me out of that slump. Weird.

Here are my notes from the day:

Day 2 – Data Types

June 22, 2022 – Coding Rooms Exercises Day 2 (Lessons 1,2,3) Day 3 (1,2)

We played around with strings. Numbers as strings. Typecasting strings to integers or floats.

To declare a variable as a data type use:

varname = int(5)
But this will be overwritten when a new assignment
varname = input("New Value:")
Will change the data type back to a string, even if a number is entered.
So I need to validate the data type after an input.
varname = int(varname)

Formatting strings

I thought I would be able to use printf style formatting, there is a Python way using the .format() method and there is a printf method. Kinda weird either way.

age = input("What is your current age?")
age = int(age)
years_till_90 = 90 - age
age_in_months = years_till_90 * 12
age_in_weeks  = years_till_90 * 52
age_in_days   = years_till_90 * 365

These next lines produce the same result. The python way and the old printf way. The Python way is a bit more friendly for type conversion.

print('You have {} days, {} weeks, and {} months left.'.format(age_in_days, age_in_weeks, age_in_months))

print('You have %d days, %d weeks, and %d months left.' % (age_in_days, age_in_weeks, age_in_months))

print(f'You have {age_in_days} days, {age_in_weeks} weeks, and {age_in_months} months left.')  
// this one is the most readable and likely the new standard.  (Note the 'f' )


The standard operators apply: + – / * == != < <= >= >
Logic operators are words: and, or


Standard operators built into python
rounding numbers round(23.2552, 2) will round two decimal places
modulo operator % 4 % 2 will result in 0. No remainder dividing 4 by 2. 5 % 2 will result 1
For more advanced commands like ceil, or floor, import the math module

Day 2 Assignment 3 – BMI Calculator 2

I struggled to pass the tests at first, due to my spelling of slightly vs slighty, and almost invisible difference in the code when you are looking for syntax differences.

Zen Huts – What happened

I was driving back from Tofino BC along the windy highway, my kids were quiet in the back of our Westfalia camperized 1986 VW Vanagon. We were well rested from a beautiful weekend retreat at a Long Beach Resort. My beautiful wife beside me as we sat listening to the drone of the engine. Across the dash, Vancouver Island rolled up before us, it was beautiful.

Something had been bothering me. What is the answer to it all. How am I supposed to raise a family, be successful at my job, keep the passion lit in my marriage, and be happy. Not only that, but the world was hurting. This was during the era of George W Bush as president, things looked bleak for world politics, and where we were going as a society.

A single word was bouncing around in my brain, and I wasn’t sure what it meant. Sustainable. At first the idea was a little cloudy, but as we rolled on, the idea got louder and louder in my head. It was as if all the VW driving hippies were all chanting a mantra, a single idea, and I was tuned in. Sustainable. Sustainable.

Then I had an epiphany… "Sustainable!" I proclaimed. My wife looked at me as if I was having a stroke. "That’s it!", I turned to my wife. "Sustainability is the answer!". Still the concerned puzzled look. I could read her eyes "what was the question?"

The key to life is sustainability. Modern society has given us all the illusion of sustainability. We get our food from the grocery store, we earn an income from our regular jobs, and we live in lovely over engineered homes. We have it all figured out.

That is until something upsets the balance. Perhaps a natural disaster, or economic meltdown, or any number of potentially mini catastrophes that could upset that balance. Then we find ourselves in trouble. The house that kept us warm is now a prison, unable to buy food, or pay for electricity, even water becomes scarce.

What will keep us alive, and even thrive in that situation? Sustainability…. and I was going to find it and grab a hold of it while life is good.

Thank you for visiting Zen Huts. This is a side project for me, Billy Baker. I live on Vancouver Island, Canada. I’m excited to share this adventure and all of it’s ups and downs. Please subscribe to get notified of my updates.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑