Revisiting Python After 4 Years: Now with AI at My Fingertips

Otgonzaya Battulga
CEU Threads
Published in
5 min readMar 1, 2024
Photo by ThisisEngineering RAEng on Unsplash

Beginning my undergraduate studies in Applied Economics, Python appeared as an enigma for me who had never experienced coding before. The absence of notes during in-class quizzes, the way the instructor taught the lessons as if it was a fast-paced marathon dimmed my early encounters with coding.

Fast forward to 4 years later, contrary to my undergraduate experience, my return to Python with the “Introduction to Python” course at CEU as a graduate student was a revelation. Encouraged to actively participate, to consult notes, AI, and my peers during assignments and quizzes, I found myself enjoying Python more than ever. The freedom to leverage resources and engage in discussions fostered a deeper understanding of coding with Python.

The learning landscape has also changed because of the emergence of AI in learning environments, making it more accessible for students less adept in coding.

Additionally, the structure of the “Introduction to Python” course provided a greater environment for developing coding skills in Python. Concepts, ranging from loops to conditionals, were meticulously explained one by one, expanding my understanding of coding. This approach broadened my horizons slowly, focusing on building a strong foundation rather than overwhelming me with complex concepts in one go.

The Modern Plumbers Case Study:

The assignments within the course, particularly the case of “Modern Plumbers” showcased the improvement of my coding skills. In the assignment, we were first asked to create a function calculating the total cost of a plumbing company. After defining the function, we were then presented with the additional task of the company implementing AI and robotics to simplify their procedures and workload. This task encouraged us to think about how to adapt their pricing strategy and whether the plumbers should worry about these advancements in technology. My solution was to add service_fee on top of the total_cost_of_job , since the plumbers would be providing the services with AI and robotics.

My initial solution was straightforward. I assigned an hourly_rate to each experience_level of the plumbers and used conditional statements to match the hourly_rate with the corresponding experience_level. Finally, I calculated the total_cost_of_job by multiplying the hours_worked by the hourly_rate and added the service_fee.

def total_cost_of_job(hours_worked, hourly_rate, experience_level, 
use_AI=False, use_Robotics=False, use_3D_printing=False,
use_nanocoating=False, use_sound_waves=False):
junior_rate = 10
senior_rate = 30
standard_rate = 12

if experience_level == "junior":
hourly_rate = junior_rate
elif experience_level == "senior":
hourly_rate = senior_rate
else:
print("Warning: Unknown experience level. Using standard hourly rate.")
hourly_rate = standard_rate

service_fee = 0
if use_AI:
service_fee += 5 # Add the AI service fee
if use_Robotics:
service_fee += 8 # Add the Robotics service fee
if use_3D_printing:
service_fee += 7 # Add the 3D printing service fee


if use_nanocoating:
service_fee += 10 # Add the nanocoating service fee
if use_sound_waves:
service_fee += 15 # Add the sound waves service fee

total_cost = (hours_worked * hourly_rate) + service_fee

return total_cost

My revised solution for the last assignment of the course for the same prompt was to incorporate safeguards to handle negative input for hours_worked. Additionally, I optimized the assignment of hourly_rate by creating a dictionary named rates, which stores the hourly rates corresponding to different experience levels. This approach not only simplifies the code but also ensures consistency and ease of maintenance. Furthermore, I introduced a technology_fees dictionary to efficiently manage the fees associated with various technologies. These enhancements significantly improve the clarity and robustness of the code.

def total_cost_of_job(hours_worked, hourly_rate, experience_level, 
use_AI=False, use_Robotics=False, use_3D_printing=False,
use_nanocoating=False, use_sound_waves=False):
if hours_worked < 0:
print("Warning: Hours worked cannot be negative. Using absolute value.")
hours_worked = abs(hours_worked)
if experience_level not in {"junior", "mid-level", "senior"}:
print("Warning: Unknown experience level. Using standard hourly rate.")

rates = {"junior": 10, "mid-level": 15, "senior": 30}
hourly_rate = rates.get(experience_level, 12)
total_cost = hours_worked * hourly_rate

technology_fees = {"AI": 5, "Robotics": 8, "3D_printing": 7,
"nanocoating": 10,"sound_waves": 15}

service_fee = sum(technology_fees[technology] for technology, used in
[("AI", use_AI), ("Robotics", use_Robotics),
("3D_printing", use_3D_printing),
("nanocoating", use_nanocoating),
("sound_waves", use_sound_waves)] if used)

total_cost += service_fee

return total_cost

Use of ChatGPT:

Photo by Andrew Neel on Unsplash

I found ChatGPT to be incredibly helpful for my coding journey, particularly when confronted with lengthy or intricate code. Despite having previous experience with coding, I occasionally opted for ChatGPT’s assistance, particularly for tasks that seemed easy or prone to error. This approach enabled me to avoid potential time-consuming mistakes.

Furthermore, I discovered the effectiveness of breaking down lengthy prompts and seeking specific guidance from ChatGPT on individual aspects of the code. Rather than requesting a full solution to a problem, I focused on areas where I found difficulty. This method not only aided a deeper understanding of the code but also enhanced my problem-solving skills. I realized that addressing smaller segments of the code yielded more effective results than attempting to tackle the entire problem at once.

However, I faced some challenges when utilizing ChatGPT for more intricate prompts. Occasionally, ChatGPT struggled to grasp the full scope of the prompt, resulting in code that did not function as intended. In such instances, I found it better to rely on my own analytical abilities or seek guidance from alternative sources.

Endless possibilities:

Although not covered in the course material, you can do so much more with functions that take another function as an argument in Python.

def calculate_discounted_cost(hours_worked, hourly_rate, experience_level, technology_fees, discount_function):
total_cost = total_cost_of_job(hours_worked, hourly_rate, experience_level, technology_fees)
discounted_cost = discount_function(total_cost)
return discounted_cost


def apply_discount(total_cost):
return total_cost * 0.9 # Applying a 10% discount

technology_fees = {"AI": 5, "Robotics": 8, "3D_printing": 7,
"nanocoating": 10,"sound_waves": 15}

discounted_cost = calculate_discounted_cost(hours_worked=8, hourly_rate=15,
experience_level="senior",
technology_fees=technology_fees,
discount_function=apply_discount)

print(f"Discounted cost of the job: ${discounted_cost}")

In this example, the calculate_discounted_cost function takes the total_cost_of_job function as an argument, along with the other required arguments. It then applies a discount function apply_discount to the total cost returned by total_cost_of_job. It shows how we can use a function as an argument to change the action of another function which creates more dynamic and adaptable code.

Photo by Hitesh Choudhary on Unsplash

Revisiting Python after four years was a transformative experience in a way that I no longer feel threatened by the task of coding. The endless possibilities that coding offers excite me as I continue to learn. This newfound confidence not only influences my choice of courses but also shapes my future career prospects.

--

--