0x02. Python - import & modules
Name: Wendy Munyasi.
Email: wendymunyasi@gmail.com
Tel: +254707240068.
- Allowed editors:
vi
,vim
,emacs
. - All your files will be interpreted/compiled on Ubuntu 20.04 LTS using gcc, using python3 (version 3.8.5).
- All your files should end with a new line.
- The first line of all your files should be exactly
#!/usr/bin/python3
. - Your code should use the pycodestyle (version
2.8.*
). - All your files must be executable.
- The length of your files will be tested using
wc
.
Learn how to import functions from another file.
How to use imported functions.
How to create a module.
How to use the built-in function dir()
.
How to prevent code in your script from being executed when imported.
How to use command line arguments with your Python programs.
- 0. Import a simple function from a simple file - Write a program that imports the function
def add(a, b):
from the fileadd_0.py
and prints the result of the addition1 + 2 = 3
. -0-add.py
. - 1. My first toolbox! - Write a program that imports functions from the file
calculator_1.py
, does some Maths, and prints the result. -1-calculation.py
. - 2. How to make a script dynamic! - Write a program that prints the number of and the list of its arguments. -
2-args.py
. - 3. Infinite addition - Write a program that prints the result of the addition of all arguments. -
3-infinite_add.py
. - 4. Who are you? - Write a program that prints all the names defined by the compiled module hidden_4.pyc (please download it locally). -
4-hidden_discovery.py
. - 5. Everything can be imported - Write a program that imports the variable
a
from the filevariable_load_5.py
and prints its value. -5-variable_load.py
. - 6. Build my own calculator! - Write a program that imports all functions from the file
calculator_1.py
and handles basic operations. -100-my_calculator.py
. - 7. Easy print - Write a program that prints
#pythoniscool
, followed by a new line, in the standard output. -101-easy_print.py
. - 8. ByteCode -> Python #3 - Write the Python function
def magic_calculation(a, b):
that does exactly the same as the given Python bytecode. -102-magic_calculation.py
. - 9. Fast alphabet - Write a program that prints the alphabet in uppercase, followed by a new line. -
103-fast_alphabet.py
.
To collaborate, reach me through my email address wendymunyasi@gmail.com.