Teach Jenn Tech

Learning Python: Functions and Getting Help

Published on August 1 2024 by Jenn Junod

Written by Jenn Junod

In a recent coding stream, Jenn Junod, Damien, and their guest Jay, dove into Python functions using Kaggle exercises. They encountered challenges while working through the concepts of defining functions, utilizing default arguments, and understanding how Python’s round function works in different scenarios. The group focused on understanding how Python requires indentation to structure code and how functions can be passed as arguments to other functions, although this concept seemed somewhat advanced for the session’s focus. Jenn faced some frustration, particularly with understanding how to apply what was being taught in a way that made sense to her, but persisted with guidance from Jay and Damien.

One of the key moments of the stream involved Jenn trying to get a function that rounds numbers to two decimal places to work correctly. She initially struggled with where to place the code within the function definition and how to use return statements effectively. With help, she was able to correct the syntax and better understand how Python functions handle variables and arguments. The discussion also highlighted the importance of understanding not just how to write Python code, but how to verbalize and think through what each part of the code is doing.

The stream concluded with Jenn successfully modifying a function to account for varying numbers of friends when dividing candies, illustrating the use of default arguments in Python. The team plans to continue these exercises, but with an eye toward improving how they approach teaching and learning Python, particularly around how to communicate coding concepts clearly and effectively.

Questions from the stream:

1. What happens if you pass a negative number as the second argument to Python’s round function?

  • Passing a negative number as the second argument to round moves the rounding to the left of the decimal point, effectively rounding to the nearest tens, hundreds, etc.

2. How can you define a Python function with an optional argument that defaults to a certain value?

  • You can define an optional argument by assigning a default value in the function definition, e.g., def function_name(arg1, arg2=default_value):.

3. Why is indentation crucial in Python?

  • Indentation is crucial in Python because it determines the structure of the code and which lines of code belong to specific functions or control statements.

Feel free to join the conversation or ask more questions on their next stream!

Enjoy learning with us?

We’re using Kaggle Learn - Python.

Follow us!

JennDamien
- Twitch- Instagram
- YouTube- LinkedIn
- Twitter
- LinkedIn
← Back to content