-
0. Safe list printing
- 0-safe_print_list.py: Python function that prints
x
elements of a list on the same line, followed by a new line. - The parameter
x
represents the number of elements to print - can be bigger than the length ofmy_list
. - Returns the real number of elements printed.
- Without importing modules or using
len()
.
- 0-safe_print_list.py: Python function that prints
-
1. Safe printing of an integers list
- 1-safe_print_integer.py: Python function that prints an integer in
"{:d}".format()
format. - The parameter
value
can be any type. - Returns
True
ifvalue
was printed correctly (ie. was an integer),False
otherwise. - Without importing modules or using
type()
.
- 1-safe_print_integer.py: Python function that prints an integer in
-
2. Print and count integers
- 2-safe_print_list_integers.py: Python function that prints the first
x
elements of a list that are integers on the same line, followed by a new line. - The parameter
my_list
can contain any type. - The parameter
x
represents the number of elements to print - can be bigger than the length ofmy_list
. - Reutnrs the real number of integers printed.
- Without importing modules or using
len()
.
- 2-safe_print_list_integers.py: Python function that prints the first
-
3. Integers division with debug
- 3-safe_print_division.py: Python function that divides two integers and prints the result using
finally:
. - The function assumes that the arguments are integers.
- Upon success, returns the value of the division; otherwise - returns
None
. - Without importing modules.
- 3-safe_print_division.py: Python function that divides two integers and prints the result using
-
4. Divide a list
- 4-list_division.py: Python function that divides two lists element by element.
- Returns a new list of length
list_length
with all divisions. - The lists
my_list_1
andmy_list_2
can contain any type. - The parameter
list_length
can be larger than the lengths of either list. - If an element is not an integer or float, the function prints
wrong type
. - If the division cannot be done, the result of the division is
0
and the function prints:division by 0
. - If either of
my_list_1
ormy_list_2
are too short, the function prints:out of range
. - Without importing modules.
-
5. Raise exception
- 5-raise_exception.py: Python function that raises a type exception.
- Without importing modules.
-
6. Raise a message
- 6-raise_exception_msg.py: Python function that raises a name exception with a message.
- Without importing modules.
-
7. Safe integer print with error message
- 100-safe_print_integer_err.py: Python function that
prints an integer with type-checking in
"{:d}".format())
format. - The paramter
value
can be any type. - Returns
True
ifvalue
was printed correctly (ie. was an integer). - Otherwise, prints an exception error to
stderr
and returnsFalse
. - Without importing modules.
- 100-safe_print_integer_err.py: Python function that
prints an integer with type-checking in
-
8. Safe function
- 101-safe_function.py: Python function that executes a function safely.
- The function assumes that the paramter
fct
is always a pointer to a function. - Upon success, returns the result of the function.
- Otherwise, prints an en exception error to
stderr
and returnsNone
.
-
9. ByteCode -> Python #4
- 102-magic_calculation.py: Python function matching exactly a bytecode provided by Holberton School.
-
10. CPython #2: PyFloatObject
- 103-python.c: C functions that print basic information about Python lists, bytes, and float objects.
0x05-python-exceptions
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||