Modern Plumbers: Exploring Python through Collaborative Efforts with Classmates and AI

Simon Mair
CEU Threads
Published in
5 min readMar 1, 2024
Photo by Desola Lanre-Ologun on Unsplash

The main task for our final assignment of Introduction to Python was to develop a function that calculates the total cost of plumbing jobs for a newly established business called Modern Plumbers. This Medium post will discuss my approach to this assignment, as well as the learning process I experienced.

Part 1:

The first function I created, calculate_total_cost, computes the total cost of a plumbing job based on the hours worked, hourly rate, and the plumber's experience level. Using conditional statements, it adjusts the cost multiplier according to the experience level: 1.4 for senior, 1.2 for mid-level, and 1.0 for junior plumbers. The last line of code ensures that the function prints the calculated cost.

Example Usage:

In this example, I’m showcasing the usage of the calculate_total_cost function to determine the total cost of a plumbing job for a senior plumber, who worked eight hours at an hourly base rate of $50. As the function tells us, a plumber of this profile would earn $560.

Next, we were given .txt files that summarized the work done by several plumbers over a six-month period. The task was to calculate the total earnings of each plumber and save them in a newly created .txt file. I tried to solve this problem with the following code:

Calculate the compensation for each plumber
Save the compensations in a new .txt

The code above iterates through the monthly work data files, extracts worker information, and accumulates compensation using the calculate_total_cost function. Finally, it prints the total compensation for each worker. The last line of code utilizes the compensations calculated above and stores them in a new .txt file called compensation.txt.

Part 2:

The second part of the assignment consisted of grading the code of some of my classmates. I very much enjoyed reviewing my classmates’ work, as I was highly interested to see their approach to the same questions. I realized many times that my classmates’ solutions were much more efficient than my own and therefore, learned a lot from reviewing their assignments and improved my own code with their help.

Part 3:

For this task, Modern Plumbers is considering adopting AI, robotics, and 3D printing for quicker diagnostics.

The code here displays the updated calculate_total_cost function. I think that this solution for the cost function is better than the previous one. The use of elif statements has made my code more concise. Moreover, I improved the code, so that it raises an error statement when it is provided with incorrect inputs. The code also reflects that optional modern technologies, like AI diagnostics, robotic snakes, and 3D printing, incur an additional fixed cost.

Example Usage:

In this example, I’m showcasing the usage of the updated calculate_total_cost function to determine the total cost of a plumbing job for a senior plumber, who worked eight hours at an hourly base rate of $50. The plumbing job includes AI assistance and robotic repair. As the function tells us, a job of this profile would earn $670.

The assignment also prompted me to explore an aspect of programming that was not covered in class. In order to do so, I looked at functions that take other functions as arguments.

Even though, this code still calculates the same cost as the other function, it implements a more modular approach to calculate the total cost of a plumbing job by using additional services as variable arguments passed as functions. Unlike the previous version, it calculates the cost of each additional service based on the base cost, which allows for greater flexibility.

Example Usage:

As we can see, the calculate_total_cost1 function returns the same result as the calculate_total_cost function, although its syntax and structure are different.

Final reflections:

I believe the assignment encouraged me to practice a wide variety of Python skills learned in class. In general, this exercise has given me a deeper understanding of how to use functions in Python effectively, how to deal with error messages, and how to use AI to improve my code effectively.

I certainly believe that my solutions have evolved over time. I usually do not like to change my initial ideas but this assignment really forced me to think creatively to improve my original solutions. For example, I think that my final solution for the cost function in part 3 of this assignment is much more effective than what I provided for the in-class assignment initially.

Lastly, I would like to mention that I believe that AI such as ChatGPT are very useful tools for students learning to code and that they should be actively used to do the same. However, one has to be very careful as one should not rely on those tools excessively. It is important to understand the ideas provided by AI tools, rather than just copy-pasting them. For this assignment, I tried to create my own ideas to solve the questions first and then used ChatGPT to improve upon them. Certainly, ChatGPT’s solutions are usually much better than my own but I believe that comparing these two approaches can be a very efficient way to improve your coding skills.

--

--

CEU Threads
CEU Threads

Published in CEU Threads

CEU Threads offers life experiences as well as insights at the intersection of economics, data science, and machine learning.

Simon Mair
Simon Mair

Written by Simon Mair

MS Finance Student @Central European University