Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 66

Stop, Code, and Understand! SCU 2.8 Using Functions in Modules

Оглавление

Download the two files “SCU 2_8.py” and “UserFunction.py” from the companion website and save them either on your computer or on a removable storage device. Open the file “SCU 2_8.py” in the Python IDLE editor and insert a line of code to import the UserFunction module so that the code will report the average of the two numbers entered by the user using the function my_function, which is in the file “UserFunction.py.” Execute the modified program after the change to verify that the revised code runs and produces the correct result.

Description

Lessons learned: In this section, we learned about how we can import Python code from different modules of code so our code can use their functions. As we will see throughout the book, this is an important mechanism for using Python code that is in packages.

Introduction to Python Programming for Business and Social Science Applications

Подняться наверх