Editor

Write a Module with __name__ Guard

Intermediate · Write the code · from Python Imports: How import Really Works (Modules, Packages, Paths)

From the lesson: Python Imports: How import Really Works (Modules, Packages, Paths)

Think of a library. Instead of buying every book in the world and keeping them in your house, you go to the library and check out only the books you need. When you're done, you return them.

Read the lesson

Write a small "module" that:

1. Defines a function celsius_to_fahrenheit(c) that returns c * 9/5 + 32

2. Defines a function fahrenheit_to_celsius(f) that returns (f - 32) * 5/9

3. Has an if __name__ == '__main__' guard that:

- Prints 'Running temperature converter'

- Prints celsius_to_fahrenheit(0)

- Prints celsius_to_fahrenheit(100)

- Prints fahrenheit_to_celsius(212)

# Define the functions and the __name__ guard

More Imports exercises

All Python exercises · 50 practice problems · Modules & Packaging quiz