├── 0x00-python-hello_world ├── 0-run ├── 1-run_inline ├── 10-check_cycle.c ├── 10-linked_lists.c ├── 10-main.c ├── 100-write.py ├── 101-compile ├── 102-magic_calculation.py ├── 2-print.py ├── 3-print_number.py ├── 4-print_float.py ├── 5-print_string.py ├── 6-concat.py ├── 7-edges.py ├── 8-concat_edges.py ├── 9-easter_egg.py ├── README.md ├── cycle ├── lists.h ├── main.py └── main.pyc ├── 0x01-python-if_else_loops_functions ├── 0-positive_or_negative.py ├── 1-last_digit.py ├── 10-add.py ├── 10-main.py ├── 101-remove_char_at.py ├── 11-main.py ├── 11-pow.py ├── 12-fizzbuzz.py ├── 12-main.py ├── 13-insert_number.c ├── 13-main.c ├── 2-print_alphabet.py ├── 3-print_alphabt.py ├── 4-print_hexa.py ├── 5-print_comb2.py ├── 6-print_comb3.py ├── 7-islower.py ├── 7-main.py ├── 8-main.py ├── 8-uppercase.py ├── 9-main.py ├── 9-print_last_digit.py ├── README.md ├── __pycache__ │ ├── 10-add.cpython-38.pyc │ ├── 11-pow.cpython-38.pyc │ ├── 12-fizzbuzz.cpython-38.pyc │ ├── 7-islower.cpython-38.pyc │ ├── 8-uppercase.cpython-38.pyc │ └── 9-print_last_digit.cpython-38.pyc ├── insert ├── linked_lists.c └── lists.h ├── 0x02-python-import_modules ├── 0-add.py ├── 0-import_add.py ├── 1-calculation.py ├── 100-my_calculator.py ├── 101-easy_print.py ├── 102-magic_calculation.py ├── 103-fast_alphabet.py ├── 2-args.py ├── 3-infinite_add.py ├── 4-hidden_discovery.py ├── 5-variable_load.py ├── README.md ├── __pycache__ │ ├── 0-add.cpython-38.pyc │ ├── add_0.cpython-38.pyc │ ├── calculator_1.cpython-38.pyc │ └── variable_load_5.cpython-38.pyc ├── add_0.py ├── calculator_1.py ├── hidden_4.pyc └── variable_load_5.py ├── 0x03-python-data_structures ├── .100-print_python_list_info.c.swp ├── 0-main.py ├── 0-print_list_integer.py ├── 1-element_at.py ├── 1-main.py ├── 10-divisible_by_2.py ├── 10-main.py ├── 100-test_lists.py ├── 11-delete_at.py ├── 11-main.py ├── 12-switch.py ├── 13-is_palindrome.c ├── 13-main.c ├── 2-main.py ├── 2-replace_in_list.py ├── 3-main.py ├── 3-print_reversed_list_integer.py ├── 4-main.py ├── 4-new_in_list.py ├── 5-main.py ├── 5-no_c.py ├── 6-main.py ├── 6-print_matrix_integer.py ├── 7-add_tuple.py ├── 7-main.py ├── 8-main.py ├── 8-multiple_returns.py ├── 9-main.py ├── 9-max_integer.py ├── README.md ├── __pycache__ │ ├── 0-print_list_integer.cpython-38.pyc │ ├── 1-element_at.cpython-38.pyc │ ├── 10-divisible_by_2.cpython-38.pyc │ ├── 11-delete_at.cpython-38.pyc │ ├── 2-replace_in_list.cpython-38.pyc │ ├── 3-print_reversed_list_integer.cpython-38.pyc │ ├── 4-new_in_list.cpython-38.pyc │ ├── 5-no_c.cpython-38.pyc │ ├── 6-print_matrix_integer.cpython-38.pyc │ ├── 7-add_tuple.cpython-38.pyc │ ├── 8-multiple_returns.cpython-38.pyc │ └── 9-max_integer.cpython-38.pyc ├── libPyList.so ├── linked_lists.c ├── lists.h └── palindrome ├── 0x04-python-more_data_structures ├── 0-main.py ├── 0-square_matrix_simple.py ├── 1-main.py ├── 1-search_replace.py ├── 10-best_score.py ├── 10-main.py ├── 100-main.py ├── 100-weight_average.py ├── 101-main.py ├── 101-square_matrix_map.py ├── 102-complex_delete.py ├── 102-main.py ├── 11-main.py ├── 11-multiply_list_map.py ├── 12-main.py ├── 12-roman_to_int.py ├── 2-main.py ├── 2-uniq_add.py ├── 3-common_elements.py ├── 3-main.py ├── 4-main.py ├── 4-only_diff_elements.py ├── 5-main.py ├── 5-number_keys.py ├── 6-main.py ├── 6-print_sorted_dictionary.py ├── 7-main.py ├── 7-update_dictionary.py ├── 8-main.py ├── 8-simple_delete.py ├── 9-main.py ├── 9-multiply_by_2.py ├── README.md └── __pycache__ │ ├── 0-square_matrix_simple.cpython-38.pyc │ ├── 1-search_replace.cpython-38.pyc │ ├── 10-best_score.cpython-38.pyc │ ├── 100-weight_average.cpython-38.pyc │ ├── 101-square_matrix_map.cpython-38.pyc │ ├── 102-complex_delete.cpython-38.pyc │ ├── 11-multiply_list_map.cpython-38.pyc │ ├── 12-roman_to_int.cpython-38.pyc │ ├── 2-uniq_add.cpython-38.pyc │ ├── 3-common_elements.cpython-38.pyc │ ├── 4-only_diff_elements.cpython-38.pyc │ ├── 5-number_keys.cpython-38.pyc │ ├── 6-print_sorted_dictionary.cpython-38.pyc │ ├── 7-update_dictionary.cpython-38.pyc │ ├── 8-simple_delete.cpython-38.pyc │ └── 9-multiply_by_2.cpython-38.pyc ├── 0x05-python-exceptions ├── 0-main.py ├── 0-safe_print_list.py ├── 1-main.py ├── 1-safe_print_integer.py ├── 100-main.py ├── 100-safe_print_integer_err.py ├── 101-main.py ├── 101-safe_function.py ├── 102-magic_calculation.py ├── 2-main.py ├── 2-safe_print_list_integers.py ├── 3-main.py ├── 3-safe_print_division.py ├── 4-list_division.py ├── 4-main.py ├── 5-main.py ├── 5-raise_exception.py ├── 6-main.py ├── 6-raise_exception_msg.py ├── README.md └── __pycache__ │ ├── 0-safe_print_list.cpython-38.pyc │ ├── 1-safe_print_integer.cpython-38.pyc │ ├── 100-safe_print_integer_err.cpython-38.pyc │ ├── 101-safe_function.cpython-38.pyc │ ├── 2-safe_print_list_integers.cpython-38.pyc │ ├── 3-safe_print_division.cpython-38.pyc │ ├── 4-list_division.cpython-38.pyc │ ├── 5-raise_exception.cpython-38.pyc │ └── 6-raise_exception_msg.cpython-38.pyc ├── 0x06-python-classes ├── 0-main.py ├── 0-square.py ├── 1-main.py ├── 1-square.py ├── 100-main.py ├── 100-singly_linked_list.py ├── 101-main.py ├── 101-square.py ├── 102-main.py ├── 102-square.py ├── 103-magic_class.py ├── 2-main.py ├── 2-square.py ├── 3-main.py ├── 3-square.py ├── 4-main.py ├── 4-square.py ├── 5-main.py ├── 5-square.py ├── 6-main.py ├── 6-square.py ├── README.md └── __pycache__ │ ├── 0-square.cpython-38.pyc │ ├── 1-square.cpython-38.pyc │ ├── 100-singly_linked_list.cpython-38.pyc │ ├── 101-square.cpython-38.pyc │ ├── 102-square.cpython-38.pyc │ ├── 2-square.cpython-38.pyc │ ├── 3-square.cpython-38.pyc │ ├── 4-square.cpython-38.pyc │ ├── 5-square.cpython-38.pyc │ └── 6-square.cpython-38.pyc ├── 0x07-python-test_driven_development ├── 0-add_integer.py ├── 0-main.py ├── 2-main.py ├── 2-matrix_divided.py ├── README.md ├── __pycache__ │ ├── 0-add_integer.cpython-38.pyc │ └── 2-matrix_divided.cpython-38.pyc └── tests │ ├── 0-add_integer.txt │ └── 2-matrix_divided.txt ├── 0x08-python-more_classes ├── 0-main.py ├── 0-rectangle.py ├── 1-main.py ├── 1-rectangle.py ├── 101-nqueens.py ├── 2-main.py ├── 2-rectangle.py ├── 3-main.py ├── 3-rectangle.py ├── 4-main.py ├── 4-rectangle.py ├── 5-main.py ├── 5-rectangle.py ├── 6-main.py ├── 6-rectangle.py ├── 7-main.py ├── 7-rectangle.py ├── 8-main.py ├── 8-rectangle.py ├── 9-main.py ├── 9-rectangle.py ├── README.md └── __pycache__ │ ├── 0-rectangle.cpython-38.pyc │ ├── 1-rectangle.cpython-38.pyc │ ├── 2-rectangle.cpython-38.pyc │ ├── 3-rectangle.cpython-38.pyc │ ├── 4-rectangle.cpython-38.pyc │ ├── 5-rectangle.cpython-38.pyc │ ├── 6-rectangle.cpython-38.pyc │ ├── 7-rectangle.cpython-38.pyc │ ├── 8-rectangle.cpython-38.pyc │ └── 9-rectangle.cpython-38.pyc ├── 0x09-python-everything_is_object ├── 0-answer.txt ├── 1-answer.txt ├── 10-answer.txt ├── 100-magic_string.py ├── 100-main.py ├── 101-locked_class.py ├── 101-main.py ├── 103-line1.txt ├── 103-line2.txt ├── 105-line1.txt ├── 11-answer.txt ├── 12-answer.txt ├── 13-answer.txt ├── 14-answer.txt ├── 15-answer.txt ├── 16-answer.txt ├── 17-answer.txt ├── 18-answer.txt ├── 19-copy_list.py ├── 19-main.py ├── 2-answer.txt ├── 20-answer.txt ├── 21-answer.txt ├── 22-answer.txt ├── 23-answer.txt ├── 24-answer.txt ├── 25-answer.txt ├── 26-answer.txt ├── 27-answer.txt ├── 28-answer.txt ├── 3-answer.txt ├── 4-answer.txt ├── 5-answer.txt ├── 6-answer.txt ├── 7-answer.txt ├── 8-answer.txt ├── 9-answer.txt ├── README.md └── __pycache__ │ ├── 100-magic_string.cpython-38.pyc │ ├── 101-locked_class.cpython-38.pyc │ └── 19-copy_list.cpython-38.pyc ├── 0x0A-python-inheritance ├── 0-lookup.py ├── 0-main.py ├── 1-main.py ├── 1-my_list.py ├── 10-main.py ├── 10-square.py ├── 100-main.py ├── 100-my_int.py ├── 101-add_attribute.py ├── 101-main.py ├── 11-main.py ├── 11-square.py ├── 2-is_same_class.py ├── 2-main.py ├── 3-is_kind_of_class.py ├── 3-main.py ├── 4-inherits_from.py ├── 4-main.py ├── 5-base_geometry.py ├── 5-main.py ├── 6-base_geometry.py ├── 6-main.py ├── 7-base_geometry.py ├── 7-main.py ├── 8-main.py ├── 8-rectangle.py ├── 9-main.py ├── 9-rectangle.py ├── README.md ├── __pycache__ │ ├── 0-lookup.cpython-38.pyc │ ├── 1-my_list.cpython-38.pyc │ ├── 10-square.cpython-38.pyc │ ├── 100-my_int.cpython-38.pyc │ ├── 101-add_attribute.cpython-38.pyc │ ├── 11-square.cpython-38.pyc │ ├── 2-is_same_class.cpython-38.pyc │ ├── 3-is_kind_of_class.cpython-38.pyc │ ├── 4-inherits_from.cpython-38.pyc │ ├── 5-base_geometry.cpython-38.pyc │ ├── 6-base_geometry.cpython-38.pyc │ ├── 7-base_geometry.cpython-38.pyc │ ├── 8-rectangle.cpython-38.pyc │ └── 9-rectangle.cpython-38.pyc └── tests │ ├── 1-my_list.txt │ └── 7-base_geometry.txt ├── 0x0B-python-input_output ├── 0-main.py ├── 0-read_file.py ├── 1-main.py ├── 1-write_file.py ├── 10-main.py ├── 10-student.py ├── 100-append_after.py ├── 11-main.py ├── 11-student.py ├── 12-main.py ├── 12-pascal_triangle.py ├── 2-append_write.py ├── 2-main.py ├── 3-main.py ├── 3-to_json_string.py ├── 4-from_json_string.py ├── 4-main.py ├── 5-main.py ├── 5-save_to_json_file.py ├── 6-load_from_json_file.py ├── 7-add_item.py ├── 8-class_to_json.py ├── 8-main.py ├── 8-my_class.py ├── 9-main.py ├── 9-student.py ├── README.md ├── __pycache__ │ ├── 0-read_file.cpython-38.pyc │ ├── 1-write_file.cpython-38.pyc │ ├── 10-student.cpython-38.pyc │ ├── 11-student.cpython-38.pyc │ ├── 2-append_write.cpython-38.pyc │ ├── 3-to_json_string.cpython-38.pyc │ ├── 4-from_json_string.cpython-38.pyc │ ├── 5-save_to_json_file.cpython-38.pyc │ ├── 6-load_from_json_file.cpython-38.pyc │ ├── 8-class_to_json.cpython-38.pyc │ ├── 8-my_class.cpython-38.pyc │ └── 9-student.cpython-38.pyc ├── add_item.json ├── file_append.txt ├── my_dict.json ├── my_fake.json ├── my_file_0.txt ├── my_first_file.txt ├── my_list.json └── my_set.json ├── 0x0C-python-almost_a_circle ├── 0-main.py ├── 1-main.py ├── 10-main.py ├── 11-main.py ├── 12-main.py ├── 13-main.py ├── 14-main.py ├── 15-main.py ├── 16-main.py ├── 2-main.py ├── 3-main.py ├── 4-main.py ├── 5-main.py ├── 6-main.py ├── 7-main.py ├── 8-main.py ├── 9-main.py ├── README.md ├── models │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ ├── base.cpython-38.pyc │ │ ├── rectangle.cpython-38.pyc │ │ └── square.cpython-38.pyc │ ├── base.py │ ├── rectangle.py │ └── square.py └── tests │ ├── __init__.py │ ├── test_base.py │ ├── test_rectangle.py │ └── test_square.py ├── 0x0D-SQL_introduction ├── 0-list_databases.sql ├── 1-create_database_if_missing.sql ├── 10-top_score.sql ├── 100-move_to_utf8.sql ├── 101-avg_temperatures.sql ├── 11-best_score.sql ├── 12-no_cheating.sql ├── 13-change_class.sql ├── 14-average.sql ├── 15-groups.sql ├── 16-no_link.sql ├── 2-remove_database.sql ├── 3-list_tables.sql ├── 4-first_table.sql ├── 5-full_table.sql ├── 6-list_values.sql ├── 7-insert_value.sql ├── 8-count_89.sql ├── 9-full_creation.sql └── README.md ├── 0x0F-python-object_relational_mapping ├── 0-select_states.py ├── 0-select_states.sql ├── 1-filter_states.py ├── 10-model_state_my_get.py ├── 101-relationship_states_cities_list.py ├── 101-relationship_states_cities_list.sql ├── 11-model_state_insert.py ├── 12-model_state_update_id_2.py ├── 13-model_state_delete_a.py ├── 14-model_city_fetch_by_state.py ├── 14-model_city_fetch_by_state.sql ├── 2-my_filter_states.py ├── 3-my_safe_filter_states.py ├── 4-cities_by_state.py ├── 4-cities_by_state.sql ├── 5-filter_cities.py ├── 6-model_state.py ├── 6-model_state.sql ├── 7-model_state_fetch_all.py ├── 7-model_state_fetch_all.sql ├── 8-model_state_fetch_first.py ├── 9-model_state_filter_a.py ├── README.md ├── __pycache__ │ └── model_state.cpython-38.pyc ├── model_city.py └── model_state.py ├── 0x10-python-network_0 ├── 2 ├── 0-body_size.sh ├── 1-body.sh ├── 100-status_code.sh ├── 2-delete.sh ├── 3-methods.sh ├── 4-header.sh ├── 5-post_params.sh ├── 6-main.py ├── 6-peak.py ├── 6-peak.txt └── README.md ├── 0x11-python-network_1 ├── 0-hbtn_status.py ├── 1-hbtn_header.py ├── 10-my_github.py ├── 100-github_commits.py ├── 2-post_email.py ├── 3-error_code.py ├── 4-hbtn_status.py ├── 5-hbtn_header.py ├── 6-post_email.py ├── 7-error_code.py ├── 8-json_api.py └── README.md ├── 0x12-javascript-warm_up ├── 0-javascript_is_amazing.js ├── 1-multi_languages.js ├── 10-factorial.js ├── 100-let_me_const.js ├── 101-call_me_moby.js ├── 102-add_me_maybe.js ├── 103-object_fct.js ├── 11-second_biggest.js ├── 12-object.js ├── 13-add.js ├── 2-arguments.js ├── 3-value_argument.js ├── 4-concat.js ├── 5-to_integer.js ├── 6-multi_languages_loop.js ├── 7-multi_c.js ├── 8-square.js ├── 9-add.js └── README.md ├── 0x13-javascript_objects_scopes_closures ├── 0-main.js ├── 0-rectangle.js ├── 1-main.js ├── 1-rectangle.js ├── 10-converter.js ├── 10-main.js ├── 100-data.js ├── 100-map.js ├── 101-data.js ├── 101-sorted.js ├── 1010-data.js ├── 102-concat.js ├── 2-main.js ├── 2-rectangle.js ├── 3-main.js ├── 3-rectangle.js ├── 4-main.js ├── 4-rectangle.js ├── 5-main.js ├── 5-square.js ├── 6-main.js ├── 6-square.js ├── 7-main.js ├── 7-occurrences.js ├── 8-esrever.js ├── 8-main.js ├── 9-logme.js ├── 9-main.js └── README.md ├── 0x14-javascript-web_scraping ├── 0-readme.js ├── 1-writeme.js ├── 2-statuscode.js ├── 3-starwars_title.js ├── 4-starwars_count.js ├── 5-request_store.js ├── 6-completed_tasks.js ├── README.md ├── cisfun ├── loripsum └── my_file.txt ├── 0x15-javascript-web_jquery ├── 0-main.html ├── 0-script.js ├── 1-main.html ├── 1-script.js ├── 100-main.html ├── 2-main.html ├── 2-script.js ├── 3-main.html ├── 3-script.js ├── 4-main.html ├── 4-script.js ├── 5-main.html ├── 5-script.js ├── 6-main.html ├── 6-script.js ├── 7-main.html ├── 7-script.js ├── 8-main.html ├── 8-script.js ├── 9-main.html ├── 9-script.js └── README.md └── README.md /0x00-python-hello_world/0-run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python3 "$PYFILE" 3 | -------------------------------------------------------------------------------- /0x00-python-hello_world/1-run_inline: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python3 -c "$PYCODE" 3 | -------------------------------------------------------------------------------- /0x00-python-hello_world/100-write.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys 3 | sys.stderr.write("and that piece of art is useful - Dora Korpar, 2015-10-19\n") 4 | sys.exit(1) 5 | -------------------------------------------------------------------------------- /0x00-python-hello_world/101-compile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python3 -m compileall -b "$PYFILE" 3 | -------------------------------------------------------------------------------- /0x00-python-hello_world/102-magic_calculation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def magic_calculation(a, b): 3 | return (98 + a ** b) 4 | -------------------------------------------------------------------------------- /0x00-python-hello_world/2-print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | print("\"Programming is like building a multilingual puzzle") 3 | -------------------------------------------------------------------------------- /0x00-python-hello_world/3-print_number.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | number = 98 3 | print(f"{number:d} Battery street") 4 | -------------------------------------------------------------------------------- /0x00-python-hello_world/4-print_float.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | number = 3.14159 3 | print(f"Float: {number:.2f}") 4 | -------------------------------------------------------------------------------- /0x00-python-hello_world/5-print_string.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | str = "Holberton School" 3 | print(str*3) 4 | print(str[:9]) 5 | -------------------------------------------------------------------------------- /0x00-python-hello_world/6-concat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | str1 = "Holberton" 3 | str2 = "School" 4 | str1 += " " + str2 5 | print(f"Welcome to {str1}!") 6 | -------------------------------------------------------------------------------- /0x00-python-hello_world/7-edges.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | word = "Holberton" 3 | word_first_3 = word[:3] 4 | word_last_2 = word[-2:] 5 | middle_word = word[1:-1] 6 | print(f"First 3 letters: {word_first_3}") 7 | print(f"Last 2 letters: {word_last_2}") 8 | print(f"Middle word: {middle_word}") 9 | -------------------------------------------------------------------------------- /0x00-python-hello_world/8-concat_edges.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | str = "Python is an interpreted, interactive, object-oriented programming\ 3 | language that combines remarkable power with very clear syntax" 4 | str = str[39:66] + str[106:112] + str[:6] 5 | print(str) 6 | -------------------------------------------------------------------------------- /0x00-python-hello_world/9-easter_egg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import this 3 | -------------------------------------------------------------------------------- /0x00-python-hello_world/README.md: -------------------------------------------------------------------------------- 1 | python hello world project 2 | 3 | -------------------------------------------------------------------------------- /0x00-python-hello_world/cycle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x00-python-hello_world/cycle -------------------------------------------------------------------------------- /0x00-python-hello_world/lists.h: -------------------------------------------------------------------------------- 1 | #ifndef LISTS_H 2 | #define LISTS_H 3 | 4 | #include 5 | 6 | /** 7 | * struct listint_s - singly linked list 8 | * @n: integer 9 | * @next: points to the next node 10 | * 11 | * Description: singly linked list node structure 12 | * for Holberton project 13 | */ 14 | typedef struct listint_s 15 | { 16 | int n; 17 | struct listint_s *next; 18 | } listint_t; 19 | 20 | size_t print_listint(const listint_t *h); 21 | listint_t *add_nodeint(listint_t **head, const int n); 22 | void free_listint(listint_t *head); 23 | int check_cycle(listint_t *list); 24 | 25 | #endif /* LISTS_H */ 26 | -------------------------------------------------------------------------------- /0x00-python-hello_world/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | print("Best School") 3 | -------------------------------------------------------------------------------- /0x00-python-hello_world/main.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x00-python-hello_world/main.pyc -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/0-positive_or_negative.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import random 3 | number = random.randint(-10, 10) 4 | if number > 0: 5 | print("{0:d} is positive".format(number)) 6 | elif number == 0: 7 | print("{0:d} is zero".format(number)) 8 | else: 9 | print("{0:d} is negative".format(number)) 10 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/1-last_digit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import random 3 | number = random.randint(-10000, 10000) 4 | if number >= 0: 5 | last_digit = number % 10 6 | else: 7 | last_digit = ((-number % 10) * -1) 8 | 9 | message = f"Last digit of {number} is {last_digit}" 10 | 11 | if last_digit == 0: 12 | print(f"{message} and is 0") 13 | elif last_digit > 5 and last_digit % 10 != 0: 14 | print(f"{message} and is greater than 5") 15 | else: 16 | print(f"{message} and is less than 6 and not 0") 17 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/10-add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def add(a, b): 4 | return (a + b) 5 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/10-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | add = __import__('10-add').add 3 | 4 | print(add(1, 2)) 5 | print(add(98, 0)) 6 | print(add(100, -2)) 7 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/101-remove_char_at.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def remove_char_at(str, n): 3 | i = 0 4 | new_str = "" 5 | for ch in str: 6 | if i != n: 7 | new_str += ch 8 | i += 1 9 | return 10 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/11-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | pow = __import__('11-pow').pow 3 | 4 | print(pow(2, 2)) 5 | print(pow(98, 2)) 6 | print(pow(98, 0)) 7 | print(pow(100, -2)) 8 | print(pow(-4, 5)) 9 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/11-pow.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def pow(a, b): 3 | return a ** b 4 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/12-fizzbuzz.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def fizzbuzz(): 3 | for num in range(1, 101): 4 | if num % 3 == 0 and num % 5 == 0: 5 | print("FizzBuzz ", end="") 6 | elif num % 5 == 0: 7 | print("Buzz ", end="") 8 | elif num % 3 == 0: 9 | print("Fizz ", end="") 10 | else: 11 | print(f"{num} ", end="") 12 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/12-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | fizzbuzz = __import__('12-fizzbuzz').fizzbuzz 3 | 4 | fizzbuzz() 5 | print("") 6 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/2-print_alphabet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for char in range(97, 123): 3 | print("{:c}".format(char), end='') 4 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/3-print_alphabt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for char in range(97, 123): 3 | if (char != 101 and char != 113): 4 | print("{:c}".format(char), end='') 5 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/4-print_hexa.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for num in range(0, 99): 3 | print("{:d} = 0x{:x}".format(num, num)) 4 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/5-print_comb2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for num in range(0, 100): 3 | print("{:02d}".format(num), end='\n' if num == 99 else ", ") 4 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/6-print_comb3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | number = 0 3 | while number <= 89: 4 | if number % 10 == 0: 5 | number += 1 + number // 10 6 | print("{:02d}".format(number), end='\n' if number == 89 else ", ") 7 | number += 1 8 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/7-islower.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def islower(c): 3 | if ord(c) > 96: 4 | return True 5 | else: 6 | return False 7 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/7-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | islower = __import__('7-islower').islower 3 | 4 | print("a is {}".format("lower" if islower("a") else "upper")) 5 | print("H is {}".format("lower" if islower("H") else "upper")) 6 | print("A is {}".format("lower" if islower("A") else "upper")) 7 | print("3 is {}".format("lower" if islower("3") else "upper")) 8 | print("g is {}".format("lower" if islower("g") else "upper")) 9 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/8-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | uppercase = __import__('8-uppercase').uppercase 3 | 4 | uppercase("best") 5 | uppercase("Best School 98 Battery street") 6 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/8-uppercase.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def to_uper(character): 3 | if ord(character) >= 97 and ord(character) <= 122: 4 | return (ord(character) - 32) 5 | else: 6 | return ord(character) 7 | 8 | 9 | def uppercase(str): 10 | new = "" 11 | for character in str: 12 | new += "%c" % to_uper(character) 13 | print("{:s}".format(new)) 14 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/9-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | print_last_digit = __import__('9-print_last_digit').print_last_digit 3 | 4 | print_last_digit(98) 5 | print_last_digit(0) 6 | r = print_last_digit(-1024) 7 | print(r) 8 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/9-print_last_digit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def print_last_digit(number): 3 | if number >= 0: 4 | l_digit = number % 10 5 | else: 6 | l_digit = number % -10 7 | l_digit *= -1 8 | 9 | print("{:d}".format(l_digit), end='') 10 | return (l_digit) 11 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/README.md: -------------------------------------------------------------------------------- 1 | ## python if else loop and function 2 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/__pycache__/10-add.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x01-python-if_else_loops_functions/__pycache__/10-add.cpython-38.pyc -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/__pycache__/11-pow.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x01-python-if_else_loops_functions/__pycache__/11-pow.cpython-38.pyc -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/__pycache__/12-fizzbuzz.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x01-python-if_else_loops_functions/__pycache__/12-fizzbuzz.cpython-38.pyc -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/__pycache__/7-islower.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x01-python-if_else_loops_functions/__pycache__/7-islower.cpython-38.pyc -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/__pycache__/8-uppercase.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x01-python-if_else_loops_functions/__pycache__/8-uppercase.cpython-38.pyc -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/__pycache__/9-print_last_digit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x01-python-if_else_loops_functions/__pycache__/9-print_last_digit.cpython-38.pyc -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/insert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x01-python-if_else_loops_functions/insert -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/lists.h: -------------------------------------------------------------------------------- 1 | #ifndef LISTS_H 2 | #define LISTS_H 3 | 4 | /** 5 | * struct listint_s - singly linked list 6 | * @n: integer 7 | * @next: points to the next node 8 | * 9 | * Description: singly linked list node structure 10 | * 11 | */ 12 | typedef struct listint_s 13 | { 14 | int n; 15 | struct listint_s *next; 16 | } listint_t; 17 | 18 | size_t print_listint(const listint_t *h); 19 | listint_t *add_nodeint_end(listint_t **head, const int n); 20 | void free_listint(listint_t *head); 21 | 22 | listint_t *insert_node(listint_t **head, int number); 23 | 24 | #endif /* LISTS_H */ 25 | -------------------------------------------------------------------------------- /0x02-python-import_modules/0-add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | from add_0 import add 4 | a = 1 5 | b = 2 6 | print("{} + {} = {}".format(a, b, add(a, b))) 7 | -------------------------------------------------------------------------------- /0x02-python-import_modules/0-import_add.py: -------------------------------------------------------------------------------- 1 | __import__("0-add") 2 | -------------------------------------------------------------------------------- /0x02-python-import_modules/1-calculation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | from calculator_1 import add, sub, mul, div 4 | a = 10 5 | b = 5 6 | print("{} + {} = {}".format(a, b, add(a, b))) 7 | print("{} - {} = {}".format(a, b, sub(a, b))) 8 | print("{} * {} = {}".format(a, b, mul(a, b))) 9 | print("{} / {} = {}".format(a, b, div(a, b))) 10 | -------------------------------------------------------------------------------- /0x02-python-import_modules/101-easy_print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | __import__('sys').stdout.write("#pythoniscool\n") 3 | -------------------------------------------------------------------------------- /0x02-python-import_modules/102-magic_calculation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def magic_calculation(a, b): 4 | from magic_calculation_102 import add, sub 5 | if a < b: 6 | c = add(a, b) 7 | for i in range(4, 6): 8 | c = add(c, i) 9 | return c 10 | else: 11 | return sub(a, b) 12 | -------------------------------------------------------------------------------- /0x02-python-import_modules/103-fast_alphabet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import string 3 | print(string.ascii_uppercase) 4 | -------------------------------------------------------------------------------- /0x02-python-import_modules/2-args.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | import sys 4 | i = len(sys.argv) - 1 5 | 6 | if i == 0: 7 | print("{} arguments.".format(i)) 8 | elif i == 1: 9 | print("{} argument:".format(i)) 10 | else: 11 | print("{} arguments:".format(i)) 12 | 13 | if i >= 1: 14 | i = 0 15 | for arg in sys.argv: 16 | if i != 0: 17 | print("{}: {}".format(i, arg)) 18 | i += 1 19 | -------------------------------------------------------------------------------- /0x02-python-import_modules/3-infinite_add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | import sys 4 | result = 0 5 | for arg in sys.argv: 6 | if arg != sys.argv[0]: 7 | result += int(arg) 8 | print(result) 9 | -------------------------------------------------------------------------------- /0x02-python-import_modules/4-hidden_discovery.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | import hidden_4 4 | for name in dir(hidden_4): 5 | if name[0] != '_' and name[1] != '_': 6 | print(name) 7 | -------------------------------------------------------------------------------- /0x02-python-import_modules/5-variable_load.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | from variable_load_5 import a 4 | print(a) 5 | -------------------------------------------------------------------------------- /0x02-python-import_modules/README.md: -------------------------------------------------------------------------------- 1 | ## Python Module Project 2 | -------------------------------------------------------------------------------- /0x02-python-import_modules/__pycache__/0-add.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x02-python-import_modules/__pycache__/0-add.cpython-38.pyc -------------------------------------------------------------------------------- /0x02-python-import_modules/__pycache__/add_0.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x02-python-import_modules/__pycache__/add_0.cpython-38.pyc -------------------------------------------------------------------------------- /0x02-python-import_modules/__pycache__/calculator_1.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x02-python-import_modules/__pycache__/calculator_1.cpython-38.pyc -------------------------------------------------------------------------------- /0x02-python-import_modules/__pycache__/variable_load_5.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x02-python-import_modules/__pycache__/variable_load_5.cpython-38.pyc -------------------------------------------------------------------------------- /0x02-python-import_modules/add_0.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def add(a, b): 3 | """My addition function 4 | 5 | Args: 6 | a: first integer 7 | b: second integer 8 | 9 | Returns: 10 | The return value. a + b 11 | """ 12 | return (a + b) 13 | -------------------------------------------------------------------------------- /0x02-python-import_modules/hidden_4.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x02-python-import_modules/hidden_4.pyc -------------------------------------------------------------------------------- /0x02-python-import_modules/variable_load_5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | a = 98 3 | """Simple variable 4 | """ 5 | -------------------------------------------------------------------------------- /0x03-python-data_structures/.100-print_python_list_info.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/.100-print_python_list_info.c.swp -------------------------------------------------------------------------------- /0x03-python-data_structures/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | print_list_integer = __import__('0-print_list_integer').print_list_integer 3 | 4 | my_list = [1, 2, 3, 4, 5] 5 | print_list_integer(my_list) 6 | -------------------------------------------------------------------------------- /0x03-python-data_structures/0-print_list_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def print_list_integer(my_list=[]): 3 | for num in range(len(my_list)): 4 | print("{:d}".format(my_list[num])) 5 | -------------------------------------------------------------------------------- /0x03-python-data_structures/1-element_at.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def element_at(my_list, idx): 4 | if (idx < 0) or (idx > len(my_list) - 1): 5 | return None 6 | return(my_list[idx]) 7 | -------------------------------------------------------------------------------- /0x03-python-data_structures/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | element_at = __import__('1-element_at').element_at 3 | 4 | my_list = [1, 2, 3, 4, 5] 5 | idx = 3 6 | print("Element at index {:d} is {}".format(idx, element_at(my_list, idx))) 7 | -------------------------------------------------------------------------------- /0x03-python-data_structures/10-divisible_by_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def divisible_by_2(my_list=[]): 4 | 5 | multiples = [] 6 | for i in range(len(my_list)): 7 | if my_list[i] % 2 == 0: 8 | multiples.append(True) 9 | else: 10 | multiples.append(False) 11 | 12 | return (multiples) 13 | -------------------------------------------------------------------------------- /0x03-python-data_structures/10-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | divisible_by_2 = __import__('10-divisible_by_2').divisible_by_2 3 | 4 | my_list = [0, 1, 2, 3, 4, 5, 6] 5 | list_result = divisible_by_2(my_list) 6 | 7 | i = 0 8 | while i < len(list_result): 9 | print("{:d} {:s} divisible by 2".format(my_list[i], "is" if list_result[i] else "is not")) 10 | i += 1 11 | -------------------------------------------------------------------------------- /0x03-python-data_structures/11-delete_at.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def delete_at(my_list=[], idx=0): 5 | """Delete an item at a specific position in a list.""" 6 | if idx >= 0 and idx < len(my_list): 7 | del my_list[idx] 8 | return (my_list) 9 | -------------------------------------------------------------------------------- /0x03-python-data_structures/11-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | delete_at = __import__('11-delete_at').delete_at 3 | 4 | my_list = [1, 2, 3, 4, 5] 5 | idx = 3 6 | new_list = delete_at(my_list, idx) 7 | print(new_list) 8 | print(my_list) 9 | -------------------------------------------------------------------------------- /0x03-python-data_structures/12-switch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | a = 89 3 | b = 10 4 | a, b = b, a 5 | print("a={:d} - b={:d}".format(a, b)) 6 | -------------------------------------------------------------------------------- /0x03-python-data_structures/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | replace_in_list = __import__('2-replace_in_list').replace_in_list 3 | 4 | my_list = [1, 2, 3, 4, 5] 5 | idx = 3 6 | new_element = 9 7 | new_list = replace_in_list(my_list, idx, new_element) 8 | 9 | print(new_list) 10 | print(my_list) 11 | -------------------------------------------------------------------------------- /0x03-python-data_structures/2-replace_in_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def replace_in_list(my_list, idx, element): 4 | if (idx < 0) or (idx > len(my_list) - 1): 5 | return my_list 6 | else: 7 | my_list[idx] = element 8 | return my_list 9 | -------------------------------------------------------------------------------- /0x03-python-data_structures/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | print_reversed_list_integer = __import__('3-print_reversed_list_integer').print_reversed_list_integer 3 | 4 | my_list = [1, 2, 3, 4, 5] 5 | print_reversed_list_integer(my_list) 6 | -------------------------------------------------------------------------------- /0x03-python-data_structures/3-print_reversed_list_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def print_reversed_list_integer(my_list=[]): 4 | if isinstance(my_list, list): 5 | my_list.reverse() 6 | for i in my_list: 7 | print("{:d}".format(i)) 8 | -------------------------------------------------------------------------------- /0x03-python-data_structures/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | new_in_list = __import__('4-new_in_list').new_in_list 3 | 4 | my_list = [1, 2, 3, 4, 5] 5 | idx = 3 6 | new_element = 9 7 | new_list = new_in_list(my_list, idx, new_element) 8 | 9 | print(new_list) 10 | print(my_list) 11 | -------------------------------------------------------------------------------- /0x03-python-data_structures/4-new_in_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def new_in_list(my_list, idx, element): 5 | 6 | if (idx < 0) or (idx > (len(my_list)-1)): 7 | return my_list 8 | 9 | copy = [x for x in my_list] 10 | copy[idx] = element 11 | return copy 12 | -------------------------------------------------------------------------------- /0x03-python-data_structures/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | no_c = __import__('5-no_c').no_c 3 | 4 | print(no_c("Best School")) 5 | print(no_c("Chicago")) 6 | print(no_c("C is fun!")) 7 | -------------------------------------------------------------------------------- /0x03-python-data_structures/5-no_c.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def no_c(my_string): 4 | new_str = '' 5 | for char in my_string: 6 | if char != 'c' and char != 'C': 7 | new_str += char 8 | return (new_str) 9 | -------------------------------------------------------------------------------- /0x03-python-data_structures/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | print_matrix_integer = __import__('6-print_matrix_integer').print_matrix_integer 3 | 4 | matrix = [ 5 | [1, 2, 3], 6 | [4, 5, 6], 7 | [7, 8, 9] 8 | ] 9 | 10 | print_matrix_integer(matrix) 11 | print("--") 12 | print_matrix_integer() 13 | -------------------------------------------------------------------------------- /0x03-python-data_structures/6-print_matrix_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def print_matrix_integer(matrix=[[]]): 4 | for i in range(len(matrix)): 5 | for j in range(len(matrix[i])): 6 | print("{:d}".format(matrix[i][j]), end="") 7 | if j != (len(matrix[i]) - 1): 8 | print(" ", end="") 9 | 10 | print("") 11 | -------------------------------------------------------------------------------- /0x03-python-data_structures/7-add_tuple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def add_tuple(tuple_a=(), tuple_b=()): 3 | len_a = len(tuple_a) 4 | len_b = len(tuple_b) 5 | 6 | if len_a == 0: 7 | a1 = 0 8 | a2 = 0 9 | elif len_a == 1: 10 | a1 = tuple_a[0] 11 | a2 = 0 12 | else: 13 | a1 = tuple_a[0] 14 | a2 = tuple_a[1] 15 | 16 | if len_b == 0: 17 | b1 = 0 18 | b2 = 0 19 | elif len_b == 1: 20 | b1 = tuple_b[0] 21 | b2 = 0 22 | else: 23 | b1 = tuple_b[0] 24 | b2 = tuple_b[1] 25 | 26 | new_tuple = (a1 + b1, a2 + b2) 27 | 28 | return (new_tuple) 29 | -------------------------------------------------------------------------------- /0x03-python-data_structures/7-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | add_tuple = __import__('7-add_tuple').add_tuple 3 | 4 | tuple_a = (1, 89) 5 | tuple_b = (88, 11) 6 | new_tuple = add_tuple(tuple_a, tuple_b) 7 | print(new_tuple) 8 | 9 | print(add_tuple(tuple_a, (1, ))) 10 | print(add_tuple(tuple_a, ())) 11 | -------------------------------------------------------------------------------- /0x03-python-data_structures/8-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | multiple_returns = __import__('8-multiple_returns').multiple_returns 3 | 4 | sentence = "At school, I learnt C!" 5 | length, first = multiple_returns(sentence) 6 | print("Length: {:d} - First character: {}".format(length, first)) 7 | -------------------------------------------------------------------------------- /0x03-python-data_structures/8-multiple_returns.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def multiple_returns(sentence): 4 | if sentence == "": 5 | return (0, None) 6 | return (len(sentence), sentence[0]) 7 | -------------------------------------------------------------------------------- /0x03-python-data_structures/9-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | max_integer = __import__('9-max_integer').max_integer 3 | 4 | my_list = [1, 90, 2, 13, 34, 5, -13, 3] 5 | max_value = max_integer(my_list) 6 | print("Max: {}".format(max_value)) 7 | -------------------------------------------------------------------------------- /0x03-python-data_structures/9-max_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def max_integer(my_list): 4 | if len(my_list) == 0: 5 | return (None) 6 | 7 | max_num = my_list[0] 8 | for i in range(len(my_list)): 9 | if my_list[i] > max_num: 10 | max_num = my_list[i] 11 | 12 | return (max_num) 13 | -------------------------------------------------------------------------------- /0x03-python-data_structures/README.md: -------------------------------------------------------------------------------- 1 | # Python data structures 2 | -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/0-print_list_integer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/0-print_list_integer.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/1-element_at.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/1-element_at.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/10-divisible_by_2.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/10-divisible_by_2.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/11-delete_at.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/11-delete_at.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/2-replace_in_list.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/2-replace_in_list.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/3-print_reversed_list_integer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/3-print_reversed_list_integer.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/4-new_in_list.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/4-new_in_list.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/5-no_c.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/5-no_c.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/6-print_matrix_integer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/6-print_matrix_integer.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/7-add_tuple.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/7-add_tuple.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/8-multiple_returns.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/8-multiple_returns.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/__pycache__/9-max_integer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/__pycache__/9-max_integer.cpython-38.pyc -------------------------------------------------------------------------------- /0x03-python-data_structures/libPyList.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/libPyList.so -------------------------------------------------------------------------------- /0x03-python-data_structures/lists.h: -------------------------------------------------------------------------------- 1 | #ifndef LISTS_H 2 | #define LISTS_H 3 | 4 | #include 5 | 6 | /** 7 | * struct listint_s - singly linked list 8 | * @n: integer 9 | * @next: points to the next node 10 | * 11 | * Description: singly linked list node structure 12 | * for Holberton project 13 | */ 14 | typedef struct listint_s 15 | { 16 | int n; 17 | struct listint_s *next; 18 | } listint_t; 19 | 20 | size_t print_listint(const listint_t *h); 21 | listint_t *add_nodeint_end(listint_t **head, const int n); 22 | void free_listint(listint_t *head); 23 | 24 | int is_palindrome(listint_t **head); 25 | 26 | #endif /* LISTS_H */ 27 | -------------------------------------------------------------------------------- /0x03-python-data_structures/palindrome: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x03-python-data_structures/palindrome -------------------------------------------------------------------------------- /0x04-python-more_data_structures/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | square_matrix_simple = __import__('0-square_matrix_simple').square_matrix_simple 3 | 4 | matrix = [ 5 | [1, 2, 3], 6 | [4, 5, 6], 7 | [7, 8, 9] 8 | ] 9 | 10 | new_matrix = square_matrix_simple(matrix) 11 | print(new_matrix) 12 | print(matrix) 13 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/0-square_matrix_simple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def square_matrix_simple(matrix=[]): 4 | new_matrix = [row[:] for row in matrix] 5 | for idx, row in enumerate(new_matrix): 6 | for idx2, col in enumerate(new_matrix): 7 | new_matrix[idx][idx2] = row[idx2] ** 2 8 | return new_matrix 9 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | search_replace = __import__('1-search_replace').search_replace 3 | 4 | my_list = [1, 2, 3, 4, 5, 4, 2, 1, 1, 4, 89] 5 | new_list = search_replace(my_list, 2, 89) 6 | 7 | print(new_list) 8 | print(my_list) 9 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/1-search_replace.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def search_replace(my_list, search, replace): 5 | if my_list is None: 6 | return 7 | new_list = my_list[:] 8 | for idx, c in enumerate(new_list): 9 | if c == search: 10 | new_list[idx] = replace 11 | return new_list 12 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/10-best_score.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def best_score(a_dictionary): 3 | return max(a_dictionary, key=a_dictionary.get) if a_dictionary else None 4 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/10-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | best_score = __import__('10-best_score').best_score 3 | 4 | a_dictionary = {'John': 12, 'Bob': 14, 'Mike': 14, 'Molly': 16, 'Adam': 10} 5 | best_key = best_score(a_dictionary) 6 | print("Best score: {}".format(best_key)) 7 | 8 | best_key = best_score(None) 9 | print("Best score: {}".format(best_key)) 10 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | weight_average = __import__('100-weight_average').weight_average 3 | 4 | my_list = [(1, 2), (2, 1), (3, 10), (4, 2)] 5 | # = ((1 * 2) + (2 * 1) + (3 * 10) + (4 * 2)) / (2 + 1 + 10 + 2) 6 | result = weight_average(my_list) 7 | print("Average: {:0.2f}".format(result)) 8 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/100-weight_average.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def weight_average(my_list=[]): 3 | if not my_list: 4 | return 0 5 | average = 0 6 | div = 0 7 | for tup in my_list: 8 | average += tup[0] * tup[1] 9 | div += tup[1] 10 | return float(average / div) 11 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/101-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | square_matrix_map = \ 3 | __import__('101-square_matrix_map').square_matrix_map 4 | 5 | matrix = [ 6 | [1, 2, 3], 7 | [4, 5, 6], 8 | [7, 8, 9] 9 | ] 10 | 11 | new_matrix = square_matrix_map(matrix) 12 | print(new_matrix) 13 | print(matrix) 14 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/101-square_matrix_map.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def square_matrix_map(matrix=[]): 3 | return list(map(lambda x: list(map(lambda i: i ** 2, x)), matrix)) 4 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/102-complex_delete.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def complex_delete(a_dictionary, value): 3 | for key in list(a_dictionary): 4 | if a_dictionary[key] == value: 5 | del a_dictionary[key] 6 | return a_dictionary 7 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/102-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | complex_delete = __import__('102-complex_delete').complex_delete 3 | print_sorted_dictionary = \ 4 | __import__('6-print_sorted_dictionary').print_sorted_dictionary 5 | 6 | a_dictionary = {'lang': "C", 'track': "Low", 'pref': "C", 'ids': [1, 2, 3]} 7 | new_dict = complex_delete(a_dictionary, 'C') 8 | print_sorted_dictionary(a_dictionary) 9 | print("--") 10 | print_sorted_dictionary(new_dict) 11 | 12 | print("--") 13 | print("--") 14 | new_dict = complex_delete(a_dictionary, 'c_is_fun') 15 | print_sorted_dictionary(a_dictionary) 16 | print("--") 17 | print_sorted_dictionary(new_dict) 18 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/11-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | multiply_list_map = __import__('11-multiply_list_map').multiply_list_map 3 | 4 | my_list = [1, 2, 3, 4, 6] 5 | new_list = multiply_list_map(my_list, 4) 6 | print(new_list) 7 | print(my_list) 8 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/11-multiply_list_map.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def multiply_list_map(my_list=[], number=0): 3 | return list(map(lambda x: x * number, my_list)) 4 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/12-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Roman to Integer test file 3 | """ 4 | roman_to_int = __import__('12-roman_to_int').roman_to_int 5 | 6 | roman_number = "X" 7 | print("{} = {}".format(roman_number, roman_to_int(roman_number))) 8 | 9 | roman_number = "VII" 10 | print("{} = {}".format(roman_number, roman_to_int(roman_number))) 11 | 12 | roman_number = "IX" 13 | print("{} = {}".format(roman_number, roman_to_int(roman_number))) 14 | 15 | roman_number = "LXXXVII" 16 | print("{} = {}".format(roman_number, roman_to_int(roman_number))) 17 | 18 | roman_number = "DCCVII" 19 | print("{} = {}".format(roman_number, roman_to_int(roman_number))) 20 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/12-roman_to_int.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def roman_to_int(roman_string): 3 | if not roman_string or type(roman_string) != str: 4 | return 0 5 | roman_d = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} 6 | roman_n = 0 7 | for j in range(len(roman_string)): 8 | if j > 0 and roman_d[roman_string[j]] > roman_d[roman_string[j - 1]]: 9 | roman_n += roman_d[roman_string[j]] - 2 * \ 10 | roman_d[roman_string[j - 1]] 11 | else: 12 | roman_n += roman_d[roman_string[j]] 13 | return roman_n 14 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | uniq_add = __import__('2-uniq_add').uniq_add 3 | 4 | my_list = [1, 2, 3, 1, 4, 2, 5] 5 | result = uniq_add(my_list) 6 | print("Result: {:d}".format(result)) 7 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/2-uniq_add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def uniq_add(my_list=[]): 3 | return(sum(set(my_list))) 4 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/3-common_elements.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def common_elements(set_1, set_2): 4 | return set_1.intersection(set_2) 5 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | common_elements = __import__('3-common_elements').common_elements 3 | 4 | set_1 = { "Python", "C", "Javascript" } 5 | set_2 = { "Bash", "C", "Ruby", "Perl" } 6 | c_set = common_elements(set_1, set_2) 7 | print(sorted(list(c_set))) 8 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | only_diff_elements = __import__('4-only_diff_elements').only_diff_elements 3 | 4 | set_1 = { "Python", "C", "Javascript" } 5 | set_2 = { "Bash", "C", "Ruby", "Perl" } 6 | od_set = only_diff_elements(set_1, set_2) 7 | print(sorted(list(od_set))) 8 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/4-only_diff_elements.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def only_diff_elements(set_1, set_2): 5 | return set_1.symmetric_difference(set_2) 6 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | number_keys = __import__('5-number_keys').number_keys 3 | 4 | a_dictionary = { 'language': "C", 'number': 13, 'track': "Low level" } 5 | nb_keys = number_keys(a_dictionary) 6 | print("Number of keys: {:d}".format(nb_keys)) 7 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/5-number_keys.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def number_keys(a_dictionary): 4 | return len(a_dictionary.keys()) 5 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | print_sorted_dictionary = __import__('6-print_sorted_dictionary').print_sorted_dictionary 3 | 4 | a_dictionary = { 'language': "C", 'Number': 89, 'track': "Low level", 'ids': [1, 2, 3] } 5 | print_sorted_dictionary(a_dictionary) 6 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/6-print_sorted_dictionary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def print_sorted_dictionary(a_dictionary): 4 | if a_dictionary is None: 5 | return 6 | for k in sorted(a_dictionary.keys()): 7 | print("{}: {}".format(k, a_dictionary.get(k))) 8 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/7-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | update_dictionary = __import__('7-update_dictionary').update_dictionary 3 | print_sorted_dictionary = __import__('6-print_sorted_dictionary').print_sorted_dictionary 4 | 5 | a_dictionary = { 'language': "C", 'number': 89, 'track': "Low level" } 6 | new_dict = update_dictionary(a_dictionary, 'language', "Python") 7 | print_sorted_dictionary(new_dict) 8 | print("--") 9 | print_sorted_dictionary(a_dictionary) 10 | 11 | print("--") 12 | print("--") 13 | 14 | new_dict = update_dictionary(a_dictionary, 'city', "San Francisco") 15 | print_sorted_dictionary(new_dict) 16 | print("--") 17 | print_sorted_dictionary(a_dictionary) 18 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/7-update_dictionary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def update_dictionary(a_dictionary, key, value): 5 | n_dic = {key: value} 6 | a_dictionary.update(n_dic) 7 | return a_dictionary 8 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/8-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | simple_delete = __import__('8-simple_delete').simple_delete 3 | print_sorted_dictionary = \ 4 | __import__('6-print_sorted_dictionary').print_sorted_dictionary 5 | 6 | a_dictionary = { 'language': "C", 'Number': 89, 'track': "Low", 'ids': [1, 2, 3] } 7 | new_dict = simple_delete(a_dictionary, 'track') 8 | print_sorted_dictionary(a_dictionary) 9 | print("--") 10 | print_sorted_dictionary(new_dict) 11 | 12 | print("--") 13 | print("--") 14 | new_dict = simple_delete(a_dictionary, 'c_is_fun') 15 | print_sorted_dictionary(a_dictionary) 16 | print("--") 17 | print_sorted_dictionary(new_dict) 18 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/8-simple_delete.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def simple_delete(a_dictionary, key=""): 4 | if a_dictionary is None: 5 | return 6 | if key in a_dictionary: 7 | del a_dictionary[key] 8 | return a_dictionary 9 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/9-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | multiply_by_2 = __import__('9-multiply_by_2').multiply_by_2 3 | print_sorted_dictionary = \ 4 | __import__('6-print_sorted_dictionary').print_sorted_dictionary 5 | 6 | a_dictionary = {'John': 12, 'Alex': 8, 'Bob': 14, 'Mike': 14, 'Molly': 16} 7 | new_dict = multiply_by_2(a_dictionary) 8 | print_sorted_dictionary(a_dictionary) 9 | print("--") 10 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/9-multiply_by_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def multiply_by_2(a_dictionary): 3 | new_dic = {} 4 | for i in a_dictionary: 5 | new_dic[i] = a_dictionary[i] * 2 6 | return new_dic 7 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/README.md: -------------------------------------------------------------------------------- 1 | ## python more data structure 2 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/0-square_matrix_simple.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/0-square_matrix_simple.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/1-search_replace.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/1-search_replace.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/10-best_score.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/10-best_score.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/100-weight_average.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/100-weight_average.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/101-square_matrix_map.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/101-square_matrix_map.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/102-complex_delete.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/102-complex_delete.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/11-multiply_list_map.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/11-multiply_list_map.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/12-roman_to_int.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/12-roman_to_int.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/2-uniq_add.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/2-uniq_add.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/3-common_elements.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/3-common_elements.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/4-only_diff_elements.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/4-only_diff_elements.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/5-number_keys.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/5-number_keys.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/6-print_sorted_dictionary.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/6-print_sorted_dictionary.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/7-update_dictionary.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/7-update_dictionary.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/8-simple_delete.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/8-simple_delete.cpython-38.pyc -------------------------------------------------------------------------------- /0x04-python-more_data_structures/__pycache__/9-multiply_by_2.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x04-python-more_data_structures/__pycache__/9-multiply_by_2.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | safe_print_list = __import__('0-safe_print_list').safe_print_list 3 | 4 | my_list = [1, 2, 3, 4, 5] 5 | 6 | nb_print = safe_print_list(my_list, 2) 7 | print("nb_print: {:d}".format(nb_print)) 8 | nb_print = safe_print_list(my_list, len(my_list)) 9 | print("nb_print: {:d}".format(nb_print)) 10 | nb_print = safe_print_list(my_list, len(my_list) + 2) 11 | print("nb_print: {:d}".format(nb_print)) 12 | -------------------------------------------------------------------------------- /0x05-python-exceptions/0-safe_print_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def safe_print_list(my_list=[], x=0): 4 | sum_total = 0 5 | for i in range(x): 6 | try: 7 | print(f"{my_list[i]}", end="") 8 | sum_total += 1 9 | except IndexError: 10 | break 11 | print() 12 | return(sum_total) 13 | -------------------------------------------------------------------------------- /0x05-python-exceptions/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | safe_print_integer = __import__('1-safe_print_integer').safe_print_integer 3 | 4 | value = 89 5 | has_been_print = safe_print_integer(value) 6 | if not has_been_print: 7 | print("{} is not an integer".format(value)) 8 | 9 | value = -89 10 | has_been_print = safe_print_integer(value) 11 | if not has_been_print: 12 | print("{} is not an integer".format(value)) 13 | 14 | value = "School" 15 | has_been_print = safe_print_integer(value) 16 | if not has_been_print: 17 | print("{} is not an integer".format(value)) 18 | -------------------------------------------------------------------------------- /0x05-python-exceptions/1-safe_print_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def safe_print_integer(value): 5 | try: 6 | print("{:d}".format(value)) 7 | return True 8 | except (ValueError, TypeError): 9 | return False 10 | -------------------------------------------------------------------------------- /0x05-python-exceptions/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | safe_print_integer_err = \ 3 | __import__('100-safe_print_integer_err').safe_print_integer_err 4 | 5 | value = 89 6 | has_been_print = safe_print_integer_err(value) 7 | if not has_been_print: 8 | print("{} is not an integer".format(value)) 9 | 10 | value = -89 11 | has_been_print = safe_print_integer_err(value) 12 | if not has_been_print: 13 | print("{} is not an integer".format(value)) 14 | 15 | value = "School" 16 | has_been_print = safe_print_integer_err(value) 17 | if not has_been_print: 18 | print("{} is not an integer".format(value)) 19 | -------------------------------------------------------------------------------- /0x05-python-exceptions/100-safe_print_integer_err.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def safe_print_integer_err(value): 3 | import sys 4 | try: 5 | print("{:d}".format(value)) 6 | return True 7 | except Exception as e: 8 | print("Exception: {}".format(e), file=sys.stderr) 9 | return False 10 | -------------------------------------------------------------------------------- /0x05-python-exceptions/101-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | safe_function = __import__('101-safe_function').safe_function 3 | 4 | 5 | def my_div(a, b): 6 | return a / b 7 | 8 | result = safe_function(my_div, 10, 2) 9 | print("result of my_div: {}".format(result)) 10 | 11 | result = safe_function(my_div, 10, 0) 12 | print("result of my_div: {}".format(result)) 13 | 14 | 15 | def print_list(my_list, len): 16 | i = 0 17 | while i < len: 18 | print(my_list[i]) 19 | i += 1 20 | return len 21 | 22 | result = safe_function(print_list, [1, 2, 3, 4], 10) 23 | print("result of print_list: {}".format(result)) 24 | -------------------------------------------------------------------------------- /0x05-python-exceptions/101-safe_function.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def safe_function(fct, *args): 3 | import sys 4 | try: 5 | result = fct(*args) 6 | return result 7 | except Exception as e: 8 | print("Exception: {}".format(e), file=sys.stderr) 9 | return None 10 | -------------------------------------------------------------------------------- /0x05-python-exceptions/102-magic_calculation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def magic_calculation(a, b): 3 | result = 0 4 | for i in range(1, 3): 5 | try: 6 | if i > a: 7 | raise Exception('Too far') 8 | else: 9 | result += a ** b / i 10 | except Exception: 11 | result = b + a 12 | break 13 | return result 14 | -------------------------------------------------------------------------------- /0x05-python-exceptions/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | safe_print_list_integers = \ 3 | __import__('2-safe_print_list_integers').safe_print_list_integers 4 | 5 | my_list = [1, 2, 3, 4, 5] 6 | 7 | nb_print = safe_print_list_integers(my_list, 2) 8 | print("nb_print: {:d}".format(nb_print)) 9 | 10 | my_list = [1, 2, 3, "School", 4, 5, [1, 2, 3]] 11 | nb_print = safe_print_list_integers(my_list, len(my_list)) 12 | print("nb_print: {:d}".format(nb_print)) 13 | 14 | nb_print = safe_print_list_integers(my_list, len(my_list) + 2) 15 | print("nb_print: {:d}".format(nb_print)) 16 | -------------------------------------------------------------------------------- /0x05-python-exceptions/2-safe_print_list_integers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def safe_print_list_integers(my_list=[], x=0): 3 | total = 0 4 | for i in range(0, x): 5 | try: 6 | print("{:d}".format(my_list[i]), end="") 7 | total += 1 8 | except (ValueError, TypeError): 9 | pass 10 | print() 11 | return total 12 | -------------------------------------------------------------------------------- /0x05-python-exceptions/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | safe_print_division = __import__('3-safe_print_division').safe_print_division 3 | 4 | a = 12 5 | b = 2 6 | result = safe_print_division(a, b) 7 | print("{:d} / {:d} = {}".format(a, b, result)) 8 | 9 | a = 12 10 | b = 0 11 | result = safe_print_division(a, b) 12 | print("{:d} / {:d} = {}".format(a, b, result)) 13 | -------------------------------------------------------------------------------- /0x05-python-exceptions/3-safe_print_division.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def safe_print_division(a, b): 3 | try: 4 | answer = a / b 5 | except (ZeroDivisionError, FloatingPointError): 6 | answer = None 7 | finally: 8 | print("Inside result: {}".format(answer)) 9 | return answer 10 | -------------------------------------------------------------------------------- /0x05-python-exceptions/4-list_division.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def list_division(my_list_1, my_list_2, list_length): 3 | new_list = [] 4 | temp_result = 0 5 | for i in range(0, list_length): 6 | try: 7 | temp_result = my_list_1[i] / my_list_2[i] 8 | except TypeError: 9 | temp_result = 0 10 | print("wrong type") 11 | except ZeroDivisionError: 12 | temp_result = 0 13 | print("division by 0") 14 | except IndexError: 15 | temp_result = 0 16 | print("out of range") 17 | finally: 18 | pass 19 | new_list.append(temp_result) 20 | return new_list 21 | -------------------------------------------------------------------------------- /0x05-python-exceptions/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | list_division = __import__('4-list_division').list_division 3 | 4 | my_l_1 = [10, 8, 4] 5 | my_l_2 = [2, 4, 4] 6 | result = list_division(my_l_1, my_l_2, max(len(my_l_1), len(my_l_2))) 7 | print(result) 8 | 9 | print("--") 10 | 11 | my_l_1 = [10, 8, 4, 4] 12 | my_l_2 = [2, 0, "H", 2, 7] 13 | result = list_division(my_l_1, my_l_2, max(len(my_l_1), len(my_l_2))) 14 | print(result) 15 | -------------------------------------------------------------------------------- /0x05-python-exceptions/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | raise_exception = __import__('5-raise_exception').raise_exception 3 | 4 | try: 5 | raise_exception() 6 | except TypeError as te: 7 | print("Exception raised") 8 | -------------------------------------------------------------------------------- /0x05-python-exceptions/5-raise_exception.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def raise_exception(): 3 | raise TypeError 4 | -------------------------------------------------------------------------------- /0x05-python-exceptions/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | raise_exception_msg = __import__('6-raise_exception_msg').raise_exception_msg 3 | 4 | try: 5 | raise_exception_msg("C is fun") 6 | except NameError as ne: 7 | print(ne) 8 | -------------------------------------------------------------------------------- /0x05-python-exceptions/6-raise_exception_msg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def raise_exception_msg(message=""): 3 | raise NameError(message) 4 | -------------------------------------------------------------------------------- /0x05-python-exceptions/README.md: -------------------------------------------------------------------------------- 1 | #0x05. Python - Exceptions 2 | -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/0-safe_print_list.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/0-safe_print_list.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/1-safe_print_integer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/1-safe_print_integer.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/100-safe_print_integer_err.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/100-safe_print_integer_err.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/101-safe_function.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/101-safe_function.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/2-safe_print_list_integers.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/2-safe_print_list_integers.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/3-safe_print_division.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/3-safe_print_division.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/4-list_division.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/4-list_division.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/5-raise_exception.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/5-raise_exception.cpython-38.pyc -------------------------------------------------------------------------------- /0x05-python-exceptions/__pycache__/6-raise_exception_msg.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x05-python-exceptions/__pycache__/6-raise_exception_msg.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('0-square').Square 3 | 4 | my_square = Square() 5 | print(type(my_square)) 6 | print(my_square.__dict__) 7 | -------------------------------------------------------------------------------- /0x06-python-classes/0-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Square class defination""" 3 | 4 | 5 | class Square: 6 | """Square class body""" 7 | pass 8 | -------------------------------------------------------------------------------- /0x06-python-classes/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('1-square').Square 3 | 4 | my_square = Square(3) 5 | print(type(my_square)) 6 | print(my_square.__dict__) 7 | 8 | try: 9 | print(my_square.size) 10 | except Exception as e: 11 | print(e) 12 | 13 | try: 14 | print(my_square.__size) 15 | except Exception as e: 16 | print(e) 17 | -------------------------------------------------------------------------------- /0x06-python-classes/1-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Define a class Square.""" 4 | 5 | 6 | class Square: 7 | """Represent a square.""" 8 | 9 | def __init__(self, size): 10 | """Initialize a new Square. 11 | Args: 12 | size (int): The size of the new square. 13 | """ 14 | self.__size = size 15 | -------------------------------------------------------------------------------- /0x06-python-classes/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | SinglyLinkedList = __import__('100-singly_linked_list').SinglyLinkedList 3 | 4 | sll = SinglyLinkedList() 5 | sll.sorted_insert(2) 6 | sll.sorted_insert(5) 7 | sll.sorted_insert(3) 8 | sll.sorted_insert(10) 9 | sll.sorted_insert(1) 10 | sll.sorted_insert(-4) 11 | sll.sorted_insert(-3) 12 | sll.sorted_insert(4) 13 | sll.sorted_insert(5) 14 | sll.sorted_insert(12) 15 | sll.sorted_insert(3) 16 | print(sll) 17 | -------------------------------------------------------------------------------- /0x06-python-classes/101-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('101-square').Square 3 | 4 | my_square = Square(5, (0, 0)) 5 | print(my_square) 6 | 7 | print("--") 8 | 9 | my_square = Square(5, (4, 1)) 10 | print(my_square) 11 | -------------------------------------------------------------------------------- /0x06-python-classes/102-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('102-square').Square 3 | 4 | s_5 = Square(5) 5 | s_6 = Square(6) 6 | 7 | if s_5 < s_6: 8 | print("Square 5 < Square 6") 9 | if s_5 <= s_6: 10 | print("Square 5 <= Square 6") 11 | if s_5 == s_6: 12 | print("Square 5 == Square 6") 13 | if s_5 != s_6: 14 | print("Square 5 != Square 6") 15 | if s_5 > s_6: 16 | print("Square 5 > Square 6") 17 | if s_5 >= s_6: 18 | print("Square 5 >= Square 6") 19 | -------------------------------------------------------------------------------- /0x06-python-classes/2-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # 2-square.py 3 | """Square class defination.""" 4 | 5 | 6 | class Square: 7 | """Square class body""" 8 | 9 | def __init__(self, size=0): 10 | """Square class contructor 11 | Args: 12 | size (int): The size of the new square. 13 | """ 14 | if not isinstance(size, int): 15 | raise TypeError("size must be an integer") 16 | elif size < 0: 17 | raise ValueError("size must be >= 0") 18 | self.__size = size 19 | -------------------------------------------------------------------------------- /0x06-python-classes/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('3-square').Square 3 | 4 | my_square_1 = Square(3) 5 | print("Area: {}".format(my_square_1.area())) 6 | 7 | try: 8 | print(my_square_1.size) 9 | except Exception as e: 10 | print(e) 11 | 12 | try: 13 | print(my_square_1.__size) 14 | except Exception as e: 15 | print(e) 16 | 17 | my_square_2 = Square(5) 18 | print("Area: {}".format(my_square_2.area())) 19 | -------------------------------------------------------------------------------- /0x06-python-classes/3-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Square class defination.""" 3 | 4 | 5 | class Square: 6 | """Square class body.""" 7 | 8 | def __init__(self, size=0): 9 | """Square contructor. 10 | Args: 11 | size (int): The size of the new square. 12 | """ 13 | if not isinstance(size, int): 14 | raise TypeError("size must be an integer") 15 | elif size < 0: 16 | raise ValueError("size must be >= 0") 17 | self.__size = size 18 | 19 | def area(self): 20 | """Return the new area of the square.""" 21 | return (self.__size * self.__size) 22 | -------------------------------------------------------------------------------- /0x06-python-classes/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('4-square').Square 3 | 4 | my_square = Square(89) 5 | print("Area: {} for size: {}".format(my_square.area(), my_square.size)) 6 | 7 | my_square.size = 3 8 | print("Area: {} for size: {}".format(my_square.area(), my_square.size)) 9 | 10 | try: 11 | my_square.size = "5 feet" 12 | print("Area: {} for size: {}".format(my_square.area(), my_square.size)) 13 | except Exception as e: 14 | print(e) 15 | -------------------------------------------------------------------------------- /0x06-python-classes/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('5-square').Square 3 | 4 | my_square = Square(3) 5 | my_square.my_print() 6 | 7 | print("--") 8 | 9 | my_square.size = 10 10 | my_square.my_print() 11 | 12 | print("--") 13 | 14 | my_square.size = 0 15 | my_square.my_print() 16 | 17 | print("--") 18 | -------------------------------------------------------------------------------- /0x06-python-classes/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('6-square').Square 3 | 4 | my_square_1 = Square(3) 5 | my_square_1.my_print() 6 | 7 | print("--") 8 | 9 | my_square_2 = Square(3, (1, 1)) 10 | my_square_2.my_print() 11 | 12 | print("--") 13 | 14 | my_square_3 = Square(3, (3, 0)) 15 | my_square_3.my_print() 16 | 17 | print("--") 18 | -------------------------------------------------------------------------------- /0x06-python-classes/README.md: -------------------------------------------------------------------------------- 1 | #0x06-python-classes 2 | -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/0-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/0-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/1-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/1-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/100-singly_linked_list.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/100-singly_linked_list.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/101-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/101-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/102-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/102-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/2-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/2-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/3-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/3-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/4-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/4-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/5-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/5-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x06-python-classes/__pycache__/6-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x06-python-classes/__pycache__/6-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x07-python-test_driven_development/0-add_integer.py: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/python3 3 | 4 | """0-add_integer 5 | The function "add_integer" returns the sum of two integers. 6 | """ 7 | def add_integer(a, b=98): 8 | """adds two integers function body""" 9 | 10 | if type(a) not in [int, float]: 11 | raise TypeError("a must be an integer") 12 | if type(b) not in [int, float]: 13 | raise TypeError("b must be an integer") 14 | 15 | return int(a) + int(b) 16 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | add_integer = __import__('0-add_integer').add_integer 3 | 4 | print(add_integer(1, 2)) 5 | print(add_integer(100, -2)) 6 | print(add_integer(2)) 7 | print(add_integer(100.3, -2)) 8 | try: 9 | print(add_integer(4, "School")) 10 | except Exception as e: 11 | print(e) 12 | try: 13 | print(add_integer(None)) 14 | except Exception as e: 15 | print(e) 16 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | matrix_divided = __import__('2-matrix_divided').matrix_divided 3 | 4 | matrix = [ 5 | [1, 2, 3], 6 | [4, 5, 6] 7 | ] 8 | print(matrix_divided(matrix, 3)) 9 | print(matrix) 10 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/README.md: -------------------------------------------------------------------------------- 1 | #0x07-python-test_driven_development 2 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/__pycache__/0-add_integer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x07-python-test_driven_development/__pycache__/0-add_integer.cpython-38.pyc -------------------------------------------------------------------------------- /0x07-python-test_driven_development/__pycache__/2-matrix_divided.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x07-python-test_driven_development/__pycache__/2-matrix_divided.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('0-rectangle').Rectangle 3 | 4 | my_rectangle = Rectangle() 5 | print(type(my_rectangle)) 6 | print(my_rectangle.__dict__) 7 | -------------------------------------------------------------------------------- /0x08-python-more_classes/0-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Defines an empty Rectangle class. 4 | """ 5 | 6 | 7 | class Rectangle: 8 | """Empty Rectangle class.""" 9 | pass 10 | -------------------------------------------------------------------------------- /0x08-python-more_classes/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('1-rectangle').Rectangle 3 | 4 | my_rectangle = Rectangle(2, 4) 5 | print(my_rectangle.__dict__) 6 | 7 | my_rectangle.width = 10 8 | my_rectangle.height = 3 9 | print(my_rectangle.__dict__) 10 | -------------------------------------------------------------------------------- /0x08-python-more_classes/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('2-rectangle').Rectangle 3 | 4 | my_rectangle = Rectangle(2, 4) 5 | print("Area: {} - Perimeter: {}".format(my_rectangle.area(), my_rectangle.perimeter())) 6 | 7 | print("--") 8 | 9 | my_rectangle.width = 10 10 | my_rectangle.height = 3 11 | print("Area: {} - Perimeter: {}".format(my_rectangle.area(), my_rectangle.perimeter())) 12 | -------------------------------------------------------------------------------- /0x08-python-more_classes/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('3-rectangle').Rectangle 3 | 4 | my_rectangle = Rectangle(2, 4) 5 | print("Area: {} - Perimeter: {}".format(my_rectangle.area(), my_rectangle.perimeter())) 6 | 7 | print(str(my_rectangle)) 8 | print(repr(my_rectangle)) 9 | 10 | print("--") 11 | 12 | my_rectangle.width = 10 13 | my_rectangle.height = 3 14 | print(my_rectangle) 15 | print(repr(my_rectangle)) 16 | -------------------------------------------------------------------------------- /0x08-python-more_classes/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('4-rectangle').Rectangle 3 | 4 | my_rectangle = Rectangle(2, 4) 5 | print(str(my_rectangle)) 6 | print("--") 7 | print(my_rectangle) 8 | print("--") 9 | print(repr(my_rectangle)) 10 | print("--") 11 | print(hex(id(my_rectangle))) 12 | print("--") 13 | 14 | # create new instance based on representation 15 | new_rectangle = eval(repr(my_rectangle)) 16 | print(str(new_rectangle)) 17 | print("--") 18 | print(new_rectangle) 19 | print("--") 20 | print(repr(new_rectangle)) 21 | print("--") 22 | print(hex(id(new_rectangle))) 23 | print("--") 24 | 25 | print(new_rectangle is my_rectangle) 26 | print(type(new_rectangle) is type(my_rectangle)) 27 | -------------------------------------------------------------------------------- /0x08-python-more_classes/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('5-rectangle').Rectangle 3 | 4 | my_rectangle = Rectangle(2, 4) 5 | print("Area: {} - Perimeter: {}".format(my_rectangle.area(), my_rectangle.perimeter())) 6 | 7 | del my_rectangle 8 | 9 | try: 10 | print(my_rectangle) 11 | except Exception as e: 12 | print("[{}] {}".format(e.__class__.__name__, e)) 13 | -------------------------------------------------------------------------------- /0x08-python-more_classes/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('6-rectangle').Rectangle 3 | 4 | my_rectangle_1 = Rectangle(2, 4) 5 | my_rectangle_2 = Rectangle(2, 4) 6 | print("{:d} instances of Rectangle".format(Rectangle.number_of_instances)) 7 | del my_rectangle_1 8 | print("{:d} instances of Rectangle".format(Rectangle.number_of_instances)) 9 | del my_rectangle_2 10 | print("{:d} instances of Rectangle".format(Rectangle.number_of_instances)) 11 | -------------------------------------------------------------------------------- /0x08-python-more_classes/7-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('7-rectangle').Rectangle 3 | 4 | my_rectangle_1 = Rectangle(8, 4) 5 | print(my_rectangle_1) 6 | print("--") 7 | my_rectangle_1.print_symbol = "&" 8 | print(my_rectangle_1) 9 | print("--") 10 | 11 | my_rectangle_2 = Rectangle(2, 1) 12 | print(my_rectangle_2) 13 | print("--") 14 | Rectangle.print_symbol = "C" 15 | print(my_rectangle_2) 16 | print("--") 17 | 18 | my_rectangle_3 = Rectangle(7, 3) 19 | print(my_rectangle_3) 20 | 21 | print("--") 22 | 23 | my_rectangle_3.print_symbol = ["C", "is", "fun!"] 24 | print(my_rectangle_3) 25 | 26 | print("--") 27 | -------------------------------------------------------------------------------- /0x08-python-more_classes/8-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('8-rectangle').Rectangle 3 | 4 | my_rectangle_1 = Rectangle(8, 4) 5 | my_rectangle_2 = Rectangle(2, 3) 6 | 7 | if my_rectangle_1 is Rectangle.bigger_or_equal(my_rectangle_1, my_rectangle_2): 8 | print("my_rectangle_1 is bigger or equal to my_rectangle_2") 9 | else: 10 | print("my_rectangle_2 is bigger than my_rectangle_1") 11 | 12 | 13 | my_rectangle_2.width = 10 14 | my_rectangle_2.height = 5 15 | if my_rectangle_1 is Rectangle.bigger_or_equal(my_rectangle_1, my_rectangle_2): 16 | print("my_rectangle_1 is bigger or equal to my_rectangle_2") 17 | else: 18 | print("my_rectangle_2 is bigger than my_rectangle_1") 19 | -------------------------------------------------------------------------------- /0x08-python-more_classes/9-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('9-rectangle').Rectangle 3 | 4 | my_square = Rectangle.square(5) 5 | print("Area: {} - Perimeter: {}".format(my_square.area(), my_square.perimeter())) 6 | print(my_square) 7 | -------------------------------------------------------------------------------- /0x08-python-more_classes/README.md: -------------------------------------------------------------------------------- 1 | #0x08-python-more_classes 2 | -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/0-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/0-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/1-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/1-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/2-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/2-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/3-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/3-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/4-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/4-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/5-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/5-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/6-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/6-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/7-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/7-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/8-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/8-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/__pycache__/9-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x08-python-more_classes/__pycache__/9-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x09-python-everything_is_object/0-answer.txt: -------------------------------------------------------------------------------- 1 | type 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/1-answer.txt: -------------------------------------------------------------------------------- 1 | id 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/10-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/100-magic_string.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def magic_string(times=[0]): 3 | times[0] = times[0] + 1 4 | return "BestSchool" + (", BestSchool" * (times[0] - 1)) 5 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | magic_string = __import__('100-magic_string').magic_string 3 | 4 | for i in range(10): 5 | print(magic_string()) 6 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/101-locked_class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ LockedClass class Module""" 3 | 4 | 5 | class LockedClass(): 6 | """ variables declarations """ 7 | __slots__ = ('first_name') 8 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/101-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | LockedClass = __import__('101-locked_class').LockedClass 3 | 4 | lc = LockedClass() 5 | lc.first_name = "John" 6 | try: 7 | lc.last_name = "Snow" 8 | except Exception as e: 9 | print("[{}] {}".format(e.__class__.__name__, e)) 10 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/103-line1.txt: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/103-line2.txt: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/105-line1.txt: -------------------------------------------------------------------------------- 1 | 263 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/11-answer.txt: -------------------------------------------------------------------------------- 1 | False 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/12-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/13-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/14-answer.txt: -------------------------------------------------------------------------------- 1 | [1, 2, 3, 4] 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/15-answer.txt: -------------------------------------------------------------------------------- 1 | [1, 2, 3] 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/16-answer.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/17-answer.txt: -------------------------------------------------------------------------------- 1 | [1, 2, 3, 4] 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/18-answer.txt: -------------------------------------------------------------------------------- 1 | [1, 2, 3] 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/19-copy_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def copy_list(my_list): 3 | return my_list[:] 4 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/19-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | copy_list = __import__('19-copy_list').copy_list 3 | 4 | my_list = [1, 2, 3] 5 | print(my_list) 6 | 7 | new_list = copy_list(my_list) 8 | 9 | print(my_list) 10 | print(new_list) 11 | 12 | print(new_list == my_list) 13 | print(new_list is my_list) 14 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/2-answer.txt: -------------------------------------------------------------------------------- 1 | No 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/20-answer.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/21-answer.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/22-answer.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/23-answer.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/24-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/25-answer.txt: -------------------------------------------------------------------------------- 1 | False 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/26-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/27-answer.txt: -------------------------------------------------------------------------------- 1 | No 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/28-answer.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/3-answer.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/4-answer.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/5-answer.txt: -------------------------------------------------------------------------------- 1 | NO 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/6-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/7-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/8-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/9-answer.txt: -------------------------------------------------------------------------------- 1 | True 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/README.md: -------------------------------------------------------------------------------- 1 | 0x09-python-everything_is_object 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/__pycache__/100-magic_string.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x09-python-everything_is_object/__pycache__/100-magic_string.cpython-38.pyc -------------------------------------------------------------------------------- /0x09-python-everything_is_object/__pycache__/101-locked_class.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x09-python-everything_is_object/__pycache__/101-locked_class.cpython-38.pyc -------------------------------------------------------------------------------- /0x09-python-everything_is_object/__pycache__/19-copy_list.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x09-python-everything_is_object/__pycache__/19-copy_list.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/0-lookup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines available attributes/methods of an object.""" 3 | 4 | 5 | def lookup(obj): 6 | """Return a list of available attributes.""" 7 | return (dir(obj)) 8 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | lookup = __import__('0-lookup').lookup 3 | 4 | class MyClass1(object): 5 | pass 6 | 7 | class MyClass2(object): 8 | my_attr1 = 3 9 | def my_meth(self): 10 | pass 11 | 12 | print(lookup(MyClass1)) 13 | print(lookup(MyClass2)) 14 | print(lookup(int)) 15 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | MyList = __import__('1-my_list').MyList 3 | 4 | my_list = MyList() 5 | my_list.append(1) 6 | my_list.append(4) 7 | my_list.append(2) 8 | my_list.append(3) 9 | my_list.append(5) 10 | print(my_list) 11 | my_list.print_sorted() 12 | print(my_list) 13 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/1-my_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """MyList inherits from the list class""" 3 | 4 | 5 | class MyList(list): 6 | """A class that inherits from list""" 7 | def print_sorted(self): 8 | """prints a sorted list""" 9 | print(sorted(self)) 10 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/10-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('10-square').Square 3 | 4 | s = Square(13) 5 | 6 | print(s) 7 | print(s.area()) 8 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/10-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """ Define square module """ 4 | Rectangle = __import__('9-rectangle').Rectangle 5 | 6 | 7 | class Square(Rectangle): 8 | """ Square class body """ 9 | 10 | def __init__(self, size): 11 | super().integer_validator("size", size) 12 | self.__size = size 13 | Rectangle.__init__(self, size, size) 14 | 15 | def area(self): 16 | return self.__size * self.__size 17 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | MyInt = __import__('100-my_int').MyInt 3 | 4 | my_i = MyInt(3) 5 | print(my_i) 6 | print(my_i == 3) 7 | print(my_i != 3) 8 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/100-my_int.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class MyInt that inherits from int.""" 3 | 4 | 5 | class MyInt(int): 6 | """MyInt class body""" 7 | 8 | def __eq__(self, value): 9 | """Override == opeartor with !=.""" 10 | return self.real != value 11 | 12 | def __ne__(self, value): 13 | """Override != operator with ==.""" 14 | return self.real == value 15 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/101-add_attribute.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Define a function attributes.""" 3 | 4 | 5 | def add_attribute(obj, att, value): 6 | """Add a new attribute to an object if possible. 7 | Raises: 8 | TypeError: If the attribute cannot be added. 9 | """ 10 | if not hasattr(obj, "__dict__"): 11 | raise TypeError("can't add new attribute") 12 | setattr(obj, att, value) 13 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/101-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | add_attribute = __import__('101-add_attribute').add_attribute 3 | 4 | class MyClass(): 5 | pass 6 | 7 | mc = MyClass() 8 | add_attribute(mc, "name", "John") 9 | print(mc.name) 10 | 11 | try: 12 | a = "My String" 13 | add_attribute(a, "name", "Bob") 14 | print(a.name) 15 | except Exception as e: 16 | print("[{}] {}".format(e.__class__.__name__, e)) 17 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/11-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('11-square').Square 3 | 4 | s = Square(13) 5 | 6 | print(s) 7 | print(s.area()) 8 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/11-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines Rectangle module.""" 3 | Rectangle = __import__('9-rectangle').Rectangle 4 | 5 | 6 | class Square(Rectangle): 7 | """class body.""" 8 | 9 | def __init__(self, size): 10 | 11 | self.integer_validator("size", size) 12 | super().__init__(size, size) 13 | self.__size = size 14 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/2-is_same_class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Return instance of a specific class.""" 3 | 4 | 5 | def is_same_class(obj, a_class): 6 | """Check if an object is an instance of a given class. 7 | Args: 8 | obj (any): The object to check. 9 | a_class (type): The class to compare the type of obj to. 10 | Returns: 11 | Boolean of an instance of a_class. 12 | """ 13 | if type(obj) == a_class: 14 | return True 15 | return False 16 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | is_same_class = __import__('2-is_same_class').is_same_class 3 | 4 | a = 1 5 | if is_same_class(a, int): 6 | print("{} is an instance of the class {}".format(a, int.__name__)) 7 | if is_same_class(a, float): 8 | print("{} is an instance of the class {}".format(a, float.__name__)) 9 | if is_same_class(a, object): 10 | print("{} is an instance of the class {}".format(a, object.__name__)) 11 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/3-is_kind_of_class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """A class and inherited class-checking function.""" 3 | 4 | 5 | def is_kind_of_class(obj, a_class): 6 | """Check if an object is an instance or inherited instance of a class. 7 | Args: 8 | obj (any): The object to check. 9 | a_class (type): The class to compare the type of obj to. 10 | Returns: 11 | Boolean of an instance. 12 | """ 13 | if isinstance(obj, a_class): 14 | return True 15 | return False 16 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | is_kind_of_class = __import__('3-is_kind_of_class').is_kind_of_class 3 | 4 | a = 1 5 | if is_kind_of_class(a, int): 6 | print("{} comes from {}".format(a, int.__name__)) 7 | if is_kind_of_class(a, float): 8 | print("{} comes from {}".format(a, float.__name__)) 9 | if is_kind_of_class(a, object): 10 | print("{} comes from {}".format(a, object.__name__)) 11 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/4-inherits_from.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines an inherited class-checking method.""" 3 | 4 | 5 | def inherits_from(obj, a_class): 6 | """Checks if an object is an inherited instance of a class. 7 | Args: 8 | obj (any): The object to check. 9 | a_class (type): The class to compare. 10 | Returns: 11 | A boolean of inheritance. 12 | """ 13 | if issubclass(type(obj), a_class) and type(obj) != a_class: 14 | return True 15 | return False 16 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | inherits_from = __import__('4-inherits_from').inherits_from 3 | 4 | a = True 5 | if inherits_from(a, int): 6 | print("{} inherited from class {}".format(a, int.__name__)) 7 | if inherits_from(a, bool): 8 | print("{} inherited from class {}".format(a, bool.__name__)) 9 | if inherits_from(a, object): 10 | print("{} inherited from class {}".format(a, object.__name__)) 11 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/5-base_geometry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Empty class BaseGeometry.""" 3 | 4 | 5 | class BaseGeometry: 6 | """BaseGeometry class body.""" 7 | pass 8 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | BaseGeometry = __import__('5-base_geometry').BaseGeometry 3 | 4 | bg = BaseGeometry() 5 | 6 | print(bg) 7 | print(dir(bg)) 8 | print(dir(BaseGeometry)) 9 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/6-base_geometry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines class BaseGeometry.""" 3 | 4 | 5 | class BaseGeometry: 6 | """Class body.""" 7 | 8 | def area(self): 9 | """Not implemented.""" 10 | raise Exception("area() is not implemented") 11 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | BaseGeometry = __import__('6-base_geometry').BaseGeometry 3 | 4 | bg = BaseGeometry() 5 | 6 | try: 7 | print(bg.area()) 8 | except Exception as e: 9 | print("[{}] {}".format(e.__class__.__name__, e)) 10 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/7-base_geometry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines class BaseGeometry.""" 3 | 4 | 5 | class BaseGeometry: 6 | """Class body.""" 7 | 8 | def area(self): 9 | """Not implemented.""" 10 | raise Exception("area() is not implemented") 11 | 12 | def integer_validator(self, name, value): 13 | """Validate a parameter format. 14 | TypeError: If value is not an integer. 15 | ValueError: If value is <= 0. 16 | """ 17 | if type(value) != int: 18 | raise TypeError("{} must be an integer".format(name)) 19 | if value <= 0: 20 | raise ValueError("{} must be greater than 0".format(name)) 21 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/7-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | BaseGeometry = __import__('7-base_geometry').BaseGeometry 3 | 4 | bg = BaseGeometry() 5 | 6 | bg.integer_validator("my_int", 12) 7 | bg.integer_validator("width", 89) 8 | 9 | try: 10 | bg.integer_validator("name", "John") 11 | except Exception as e: 12 | print("[{}] {}".format(e.__class__.__name__, e)) 13 | 14 | try: 15 | bg.integer_validator("age", 0) 16 | except Exception as e: 17 | print("[{}] {}".format(e.__class__.__name__, e)) 18 | 19 | try: 20 | bg.integer_validator("distance", -4) 21 | except Exception as e: 22 | print("[{}] {}".format(e.__class__.__name__, e)) 23 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/8-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('8-rectangle').Rectangle 3 | 4 | r = Rectangle(3, 5) 5 | 6 | print(r) 7 | print(dir(r)) 8 | 9 | try: 10 | print("Rectangle: {} - {}".format(r.width, r.height)) 11 | except Exception as e: 12 | print("[{}] {}".format(e.__class__.__name__, e)) 13 | 14 | try: 15 | r2 = Rectangle(4, True) 16 | except Exception as e: 17 | print("[{}] {}".format(e.__class__.__name__, e)) 18 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/8-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """ Define Geometry module """ 4 | BaseGeometry = __import__('7-base_geometry').BaseGeometry 5 | 6 | 7 | class Rectangle(BaseGeometry): 8 | """ Rectangle body """ 9 | 10 | def __init__(self, width, height): 11 | super().integer_validator("width", width) 12 | super().integer_validator("height", height) 13 | self.__width = width 14 | self.__height = height 15 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/9-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Rectangle = __import__('9-rectangle').Rectangle 3 | 4 | r = Rectangle(3, 5) 5 | 6 | print(r) 7 | print(r.area()) 8 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/9-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """ Define base_geometry module """ 4 | BaseGeometry = __import__('7-base_geometry').BaseGeometry 5 | 6 | 7 | class Rectangle(BaseGeometry): 8 | """ Rectangle class body """ 9 | 10 | def __init__(self, width, height): 11 | super().integer_validator("width", width) 12 | super().integer_validator("height", height) 13 | self.__width = width 14 | self.__height = height 15 | 16 | def area(self): 17 | return self.__width * self.__height 18 | 19 | def __str__(self): 20 | return "[Rectangle] {}/{}".format(self.__width, self.__height) 21 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/README.md: -------------------------------------------------------------------------------- 1 | ##0x0A-python-inheritance 2 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/0-lookup.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/0-lookup.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/1-my_list.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/1-my_list.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/10-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/10-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/100-my_int.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/100-my_int.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/101-add_attribute.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/101-add_attribute.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/11-square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/11-square.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/2-is_same_class.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/2-is_same_class.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/3-is_kind_of_class.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/3-is_kind_of_class.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/4-inherits_from.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/4-inherits_from.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/5-base_geometry.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/5-base_geometry.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/6-base_geometry.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/6-base_geometry.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/7-base_geometry.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/7-base_geometry.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/8-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/8-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x0A-python-inheritance/__pycache__/9-rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0A-python-inheritance/__pycache__/9-rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | read_file = __import__('0-read_file').read_file 3 | 4 | read_file("my_file_0.txt") 5 | 6 | -------------------------------------------------------------------------------- /0x0B-python-input_output/0-read_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines read file module """ 3 | 4 | 5 | def read_file(filename=""): 6 | """ 7 | read_file function 8 | reads a text file (UTF8) and prints it result to stdout 9 | """ 10 | with open(filename, mode='r', encoding='utf-8') as f: 11 | print(f.read(), end='') 12 | -------------------------------------------------------------------------------- /0x0B-python-input_output/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | write_file = __import__('1-write_file').write_file 3 | 4 | nb_characters = write_file("my_first_file.txt", "This School is so cool!\n") 5 | print(nb_characters) 6 | -------------------------------------------------------------------------------- /0x0B-python-input_output/1-write_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines Write_file module.""" 3 | 4 | 5 | def write_file(filename="", text=""): 6 | """Write a string to a UTF8 text file. 7 | """ 8 | with open(filename, "w", encoding="utf-8") as my_file: 9 | return my_file.write(text) 10 | -------------------------------------------------------------------------------- /0x0B-python-input_output/10-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Student = __import__('10-student').Student 3 | 4 | student_1 = Student("John", "Doe", 23) 5 | student_2 = Student("Bob", "Dylan", 27) 6 | 7 | j_student_1 = student_1.to_json() 8 | j_student_2 = student_2.to_json(['first_name', 'age']) 9 | j_student_3 = student_2.to_json(['middle_name', 'age']) 10 | 11 | print(j_student_1) 12 | print(j_student_2) 13 | print(j_student_3) 14 | -------------------------------------------------------------------------------- /0x0B-python-input_output/10-student.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a class Student.""" 3 | 4 | 5 | class Student: 6 | """Represent a student.""" 7 | 8 | def __init__(self, first_name, last_name, age): 9 | """Initialize student props. 10 | """ 11 | self.first_name = first_name 12 | self.last_name = last_name 13 | self.age = age 14 | 15 | def to_json(self, attrs=None): 16 | 17 | if (type(attrs) == list and 18 | all(type(ele) == str for ele in attrs)): 19 | return {k: getattr(self, k) for k in attrs if hasattr(self, k)} 20 | return self.__dict__ 21 | -------------------------------------------------------------------------------- /0x0B-python-input_output/100-append_after.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """append_after module""" 3 | 4 | 5 | def append_after(filename="", search_string="", new_string=""): 6 | """class body. 7 | """ 8 | text = "" 9 | with open(filename) as r: 10 | for line in r: 11 | text += line 12 | if search_string in line: 13 | text += new_string 14 | with open(filename, "w") as w: 15 | w.write(text) 16 | -------------------------------------------------------------------------------- /0x0B-python-input_output/11-student.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a class Student.""" 3 | 4 | 5 | class Student: 6 | """Represent a student.""" 7 | 8 | def __init__(self, first_name, last_name, age): 9 | """Initialize student props 10 | """ 11 | self.first_name = first_name 12 | self.last_name = last_name 13 | self.age = age 14 | 15 | def to_json(self, attrs=None): 16 | if (type(attrs) == list and 17 | all(type(ele) == str for ele in attrs)): 18 | return {k: getattr(self, k) for k in attrs if hasattr(self, k)} 19 | return self.__dict__ 20 | 21 | def reload_from_json(self, json): 22 | for k, v in json.items(): 23 | setattr(self, k, v) 24 | -------------------------------------------------------------------------------- /0x0B-python-input_output/12-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 12-main 4 | """ 5 | pascal_triangle = __import__('12-pascal_triangle').pascal_triangle 6 | 7 | def print_triangle(triangle): 8 | """ 9 | Print the triangle 10 | """ 11 | for row in triangle: 12 | print("[{}]".format(",".join([str(x) for x in row]))) 13 | 14 | 15 | if __name__ == "__main__": 16 | print_triangle(pascal_triangle(5)) 17 | -------------------------------------------------------------------------------- /0x0B-python-input_output/12-pascal_triangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """pascal_traigle module.""" 3 | 4 | 5 | def pascal_triangle(n): 6 | """ pascal traigle class body. 7 | """ 8 | if n <= 0: 9 | return [] 10 | 11 | triangles = [[1]] 12 | while len(triangles) != n: 13 | tri = triangles[-1] 14 | tmp = [1] 15 | for i in range(len(tri) - 1): 16 | tmp.append(tri[i] + tri[i + 1]) 17 | tmp.append(1) 18 | triangles.append(tmp) 19 | return 20 | -------------------------------------------------------------------------------- /0x0B-python-input_output/2-append_write.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a module appends a string.""" 3 | 4 | 5 | def append_write(filename="", text=""): 6 | """Appends a string to the end of a UTF8 text file. 7 | """ 8 | with open(filename, "a", encoding="utf-8") as my_file: 9 | return my_file.write(text) 10 | -------------------------------------------------------------------------------- /0x0B-python-input_output/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | append_write = __import__('2-append_write').append_write 3 | 4 | nb_characters_added = append_write("file_append.txt", "This School is so cool!\n") 5 | print(nb_characters_added) 6 | -------------------------------------------------------------------------------- /0x0B-python-input_output/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | to_json_string = __import__('3-to_json_string').to_json_string 3 | 4 | my_list = [1, 2, 3] 5 | s_my_list = to_json_string(my_list) 6 | print(s_my_list) 7 | print(type(s_my_list)) 8 | 9 | my_dict = { 10 | 'id': 12, 11 | 'name': "John", 12 | 'places': [ "San Francisco", "Tokyo" ], 13 | 'is_active': True, 14 | 'info': { 15 | 'age': 36, 16 | 'average': 3.14 17 | } 18 | } 19 | s_my_dict = to_json_string(my_dict) 20 | print(s_my_dict) 21 | print(type(s_my_dict)) 22 | 23 | try: 24 | my_set = { 132, 3 } 25 | s_my_set = to_json_string(my_set) 26 | print(s_my_set) 27 | print(type(s_my_set)) 28 | except Exception as e: 29 | print("[{}] {}".format(e.__class__.__name__, e)) 30 | -------------------------------------------------------------------------------- /0x0B-python-input_output/3-to_json_string.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Define to_json_string module """ 3 | 4 | import json 5 | 6 | 7 | def to_json_string(my_obj): 8 | """ 9 | returns the JSON representation of an object (string) 10 | """ 11 | 12 | return json.dumps(my_obj) 13 | -------------------------------------------------------------------------------- /0x0B-python-input_output/4-from_json_string.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """ from_json_string module """ 4 | import json 5 | 6 | 7 | def from_json_string(my_str): 8 | """ 9 | Return a JSON object 10 | """ 11 | 12 | return json.loads(my_str) 13 | -------------------------------------------------------------------------------- /0x0B-python-input_output/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from_json_string = __import__('4-from_json_string').from_json_string 3 | 4 | s_my_list = "[1, 2, 3]" 5 | my_list = from_json_string(s_my_list) 6 | print(my_list) 7 | print(type(my_list)) 8 | 9 | s_my_dict = """ 10 | {"is_active": true, "info": {"age": 36, "average": 3.14}, 11 | "id": 12, "name": "John", "places": ["San Francisco", "Tokyo"]} 12 | """ 13 | my_dict = from_json_string(s_my_dict) 14 | print(my_dict) 15 | print(type(my_dict)) 16 | 17 | try: 18 | s_my_dict = """ 19 | {"is_active": true, 12 } 20 | """ 21 | my_dict = from_json_string(s_my_dict) 22 | print(my_dict) 23 | print(type(my_dict)) 24 | except Exception as e: 25 | print("[{}] {}".format(e.__class__.__name__, e)) 26 | -------------------------------------------------------------------------------- /0x0B-python-input_output/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | save_to_json_file = __import__('5-save_to_json_file').save_to_json_file 3 | 4 | filename = "my_list.json" 5 | my_list = [1, 2, 3] 6 | save_to_json_file(my_list, filename) 7 | 8 | filename = "my_dict.json" 9 | my_dict = { 10 | 'id': 12, 11 | 'name': "John", 12 | 'places': [ "San Francisco", "Tokyo" ], 13 | 'is_active': True, 14 | 'info': { 15 | 'age': 36, 16 | 'average': 3.14 17 | } 18 | } 19 | save_to_json_file(my_dict, filename) 20 | 21 | try: 22 | filename = "my_set.json" 23 | my_set = { 132, 3 } 24 | save_to_json_file(my_set, filename) 25 | except Exception as e: 26 | print("[{}] {}".format(e.__class__.__name__, e)) 27 | -------------------------------------------------------------------------------- /0x0B-python-input_output/5-save_to_json_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Define save_to_json_file module """ 4 | import json 5 | 6 | 7 | def save_to_json_file(my_obj, filename): 8 | """ 9 | Writes an Object to a text file. 10 | """ 11 | 12 | with open(filename, mode='w', encoding='utf-8') as f: 13 | json.dump(my_obj, f, ensure_ascii=False) 14 | -------------------------------------------------------------------------------- /0x0B-python-input_output/6-load_from_json_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """load from json""" 3 | import json 4 | 5 | 6 | def load_from_json_file(filename): 7 | """load from json to file""" 8 | with open(filename, encoding="utf-8") as file_loaded: 9 | return json.load(file+loaded) 10 | -------------------------------------------------------------------------------- /0x0B-python-input_output/7-add_item.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Save argument to a file.""" 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | save_to_json_file = __import__('5-save_to_json_file').save_to_json_file 7 | load_from_json_file = \ 8 | __import__('6-load_from_json_file').load_from_json_file 9 | 10 | try: 11 | items = load_from_json_file("add_item.json") 12 | except FileNotFoundError: 13 | items = [] 14 | items.extend(sys.argv[1:]) 15 | save_to_json_file(items, "add_item.json") 16 | -------------------------------------------------------------------------------- /0x0B-python-input_output/8-class_to_json.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ class-to-JSON module.""" 3 | 4 | 5 | def class_to_json(obj): 6 | """Return the dictionary represntation of json.""" 7 | return obj.__dict__ 8 | -------------------------------------------------------------------------------- /0x0B-python-input_output/8-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | MyClass = __import__('8-my_class').MyClass 3 | class_to_json = __import__('8-class_to_json').class_to_json 4 | 5 | m = MyClass("John") 6 | m.number = 89 7 | print(type(m)) 8 | print(m) 9 | 10 | mj = class_to_json(m) 11 | print(type(mj)) 12 | print(mj) 13 | -------------------------------------------------------------------------------- /0x0B-python-input_output/8-my_class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ My class module 3 | """ 4 | 5 | class MyClass: 6 | """ My class 7 | """ 8 | 9 | def __init__(self, name): 10 | self.name = name 11 | self.number = 0 12 | 13 | def __str__(self): 14 | return "[MyClass] {} - {:d}".format(self.name, self.number) 15 | -------------------------------------------------------------------------------- /0x0B-python-input_output/9-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Student = __import__('9-student').Student 3 | 4 | students = [Student("John", "Doe", 23), Student("Bob", "Dylan", 27)] 5 | 6 | for student in students: 7 | j_student = student.to_json() 8 | print(type(j_student)) 9 | print(j_student['first_name']) 10 | print(type(j_student['first_name'])) 11 | print(j_student['age']) 12 | print(type(j_student['age'])) 13 | -------------------------------------------------------------------------------- /0x0B-python-input_output/9-student.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a class Student.""" 3 | 4 | 5 | class Student: 6 | """ Student class body.""" 7 | 8 | def __init__(self, first_name, last_name, age): 9 | """Initialize student props in contructor 10 | """ 11 | self.first_name = first_name 12 | self.last_name = last_name 13 | self.age = age 14 | 15 | def to_json(self): 16 | return self.__dict__ 17 | -------------------------------------------------------------------------------- /0x0B-python-input_output/README.md: -------------------------------------------------------------------------------- 1 | #0x0B-python-input_output 2 | -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/0-read_file.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/0-read_file.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/1-write_file.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/1-write_file.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/10-student.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/10-student.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/11-student.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/11-student.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/2-append_write.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/2-append_write.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/3-to_json_string.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/3-to_json_string.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/4-from_json_string.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/4-from_json_string.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/5-save_to_json_file.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/5-save_to_json_file.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/6-load_from_json_file.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/6-load_from_json_file.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/8-class_to_json.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/8-class_to_json.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/8-my_class.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/8-my_class.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/__pycache__/9-student.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/__pycache__/9-student.cpython-38.pyc -------------------------------------------------------------------------------- /0x0B-python-input_output/add_item.json: -------------------------------------------------------------------------------- 1 | cat: add_item.json: No such file or directory 2 | -------------------------------------------------------------------------------- /0x0B-python-input_output/file_append.txt: -------------------------------------------------------------------------------- 1 | This School is so cool! 2 | This School is so cool! 3 | This School is so cool! 4 | -------------------------------------------------------------------------------- /0x0B-python-input_output/my_dict.json: -------------------------------------------------------------------------------- 1 | {"id": 12, "name": "John", "places": ["San Francisco", "Tokyo"], "is_active": true, "info": {"age": 36, "average": 3.14}} -------------------------------------------------------------------------------- /0x0B-python-input_output/my_file_0.txt: -------------------------------------------------------------------------------- 1 | We offer a truly innovative approach to education: 2 | focus on building reliable applications and scalable systems, take on real-world challenges, collaborate with your peers. 3 | 4 | A school every software engineer would have dreamt of! 5 | -------------------------------------------------------------------------------- /0x0B-python-input_output/my_first_file.txt: -------------------------------------------------------------------------------- 1 | This School is so cool! 2 | -------------------------------------------------------------------------------- /0x0B-python-input_output/my_list.json: -------------------------------------------------------------------------------- 1 | [1, 2, 3] -------------------------------------------------------------------------------- /0x0B-python-input_output/my_set.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0B-python-input_output/my_set.json -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 0-main """ 3 | from models.base import Base 4 | 5 | if __name__ == "__main__": 6 | 7 | b1 = Base() 8 | print(b1.id) 9 | 10 | b2 = Base() 11 | print(b2.id) 12 | 13 | b3 = Base() 14 | print(b3.id) 15 | 16 | b4 = Base(12) 17 | print(b4.id) 18 | 19 | b5 = Base() 20 | print(b5.id) 21 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 1-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(10, 2) 8 | print(r1.id) 9 | 10 | r2 = Rectangle(2, 10) 11 | print(r2.id) 12 | 13 | r3 = Rectangle(10, 2, 0, 0, 12) 14 | print(r3.id) 15 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/10-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 10-main """ 3 | from models.square import Square 4 | 5 | if __name__ == "__main__": 6 | 7 | s1 = Square(5) 8 | print(s1) 9 | print(s1.size) 10 | s1.size = 10 11 | print(s1) 12 | 13 | try: 14 | s1.size = "9" 15 | except Exception as e: 16 | print("[{}] {}".format(e.__class__.__name__, e)) 17 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/11-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 11-main """ 3 | from models.square import Square 4 | 5 | if __name__ == "__main__": 6 | 7 | s1 = Square(5) 8 | print(s1) 9 | 10 | s1.update(10) 11 | print(s1) 12 | 13 | s1.update(1, 2) 14 | print(s1) 15 | 16 | s1.update(1, 2, 3) 17 | print(s1) 18 | 19 | s1.update(1, 2, 3, 4) 20 | print(s1) 21 | 22 | s1.update(x=12) 23 | print(s1) 24 | 25 | s1.update(size=7, y=1) 26 | print(s1) 27 | 28 | s1.update(size=7, id=89, y=1) 29 | print(s1) 30 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/12-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 12-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(10, 2, 1, 9) 8 | print(r1) 9 | r1_dictionary = r1.to_dictionary() 10 | print(r1_dictionary) 11 | print(type(r1_dictionary)) 12 | 13 | r2 = Rectangle(1, 1) 14 | print(r2) 15 | r2.update(**r1_dictionary) 16 | print(r2) 17 | print(r1 == r2) 18 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/13-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 13-main """ 3 | from models.square import Square 4 | 5 | if __name__ == "__main__": 6 | 7 | s1 = Square(10, 2, 1) 8 | print(s1) 9 | s1_dictionary = s1.to_dictionary() 10 | print(s1_dictionary) 11 | print(type(s1_dictionary)) 12 | 13 | s2 = Square(1, 1) 14 | print(s2) 15 | s2.update(**s1_dictionary) 16 | print(s2) 17 | print(s1 == s2) 18 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/14-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 14-main """ 3 | from models.base import Base 4 | from models.rectangle import Rectangle 5 | 6 | if __name__ == "__main__": 7 | 8 | r1 = Rectangle(10, 7, 2, 8) 9 | dictionary = r1.to_dictionary() 10 | json_dictionary = Base.to_json_string([dictionary]) 11 | print(dictionary) 12 | print(type(dictionary)) 13 | print(json_dictionary) 14 | print(type(json_dictionary)) 15 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/15-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 15-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(10, 7, 2, 8) 8 | r2 = Rectangle(2, 4) 9 | Rectangle.save_to_file([r1, r2]) 10 | 11 | with open("Rectangle.json", "r") as file: 12 | print(file.read()) 13 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/16-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 16-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | list_input = [ 8 | {'id': 89, 'width': 10, 'height': 4}, 9 | {'id': 7, 'width': 1, 'height': 7} 10 | ] 11 | json_list_input = Rectangle.to_json_string(list_input) 12 | list_output = Rectangle.from_json_string(json_list_input) 13 | print("[{}] {}".format(type(list_input), list_input)) 14 | print("[{}] {}".format(type(json_list_input), json_list_input)) 15 | print("[{}] {}".format(type(list_output), list_output)) 16 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 2-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | try: 8 | Rectangle(10, "2") 9 | except Exception as e: 10 | print("[{}] {}".format(e.__class__.__name__, e)) 11 | 12 | try: 13 | r = Rectangle(10, 2) 14 | r.width = -10 15 | except Exception as e: 16 | print("[{}] {}".format(e.__class__.__name__, e)) 17 | 18 | try: 19 | r = Rectangle(10, 2) 20 | r.x = {} 21 | except Exception as e: 22 | print("[{}] {}".format(e.__class__.__name__, e)) 23 | 24 | try: 25 | Rectangle(10, 2, 3, -1) 26 | except Exception as e: 27 | print("[{}] {}".format(e.__class__.__name__, e)) 28 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(3, 2) 8 | print(r1.area()) 9 | 10 | r2 = Rectangle(2, 10) 11 | print(r2.area()) 12 | 13 | r3 = Rectangle(8, 7, 0, 0, 12) 14 | print(r3.area()) 15 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 4-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(4, 6) 8 | r1.display() 9 | 10 | print("---") 11 | 12 | r1 = Rectangle(2, 2) 13 | r1.display() 14 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 5-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(4, 6, 2, 1, 12) 8 | print(r1) 9 | 10 | r2 = Rectangle(5, 5, 1) 11 | print(r2) 12 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 6-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(2, 3, 2, 2) 8 | r1.display() 9 | 10 | print("---") 11 | 12 | r2 = Rectangle(3, 2, 1, 0) 13 | r2.display() 14 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/7-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Doc """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(10, 10, 10, 10) 8 | print(r1) 9 | 10 | r1.update(89) 11 | print(r1) 12 | 13 | r1.update(89, 2) 14 | print(r1) 15 | 16 | r1.update(89, 2, 3) 17 | print(r1) 18 | 19 | r1.update(89, 2, 3, 4) 20 | print(r1) 21 | 22 | r1.update(89, 2, 3, 4, 5) 23 | print(r1) 24 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/8-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 8-main """ 3 | from models.rectangle import Rectangle 4 | 5 | if __name__ == "__main__": 6 | 7 | r1 = Rectangle(10, 10, 10, 10) 8 | print(r1) 9 | 10 | r1.update(height=1) 11 | print(r1) 12 | 13 | r1.update(width=1, x=2) 14 | print(r1) 15 | 16 | r1.update(y=1, width=2, x=3, id=89) 17 | print(r1) 18 | 19 | r1.update(x=1, height=2, y=3, width=4) 20 | print(r1) 21 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/9-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 9-main """ 3 | from models.square import Square 4 | 5 | if __name__ == "__main__": 6 | 7 | s1 = Square(5) 8 | print(s1) 9 | print(s1.area()) 10 | s1.display() 11 | 12 | print("---") 13 | 14 | s2 = Square(2, 2) 15 | print(s2) 16 | print(s2.area()) 17 | s2.display() 18 | 19 | print("---") 20 | 21 | s3 = Square(3, 1, 3) 22 | print(s3) 23 | print(s3.area()) 24 | s3.display() 25 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/README.md: -------------------------------------------------------------------------------- 1 | ##0x0C-python-almost_a_circle 2 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/models/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0C-python-almost_a_circle/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/models/__pycache__/base.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0C-python-almost_a_circle/models/__pycache__/base.cpython-38.pyc -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/models/__pycache__/rectangle.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0C-python-almost_a_circle/models/__pycache__/rectangle.cpython-38.pyc -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/models/__pycache__/square.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0C-python-almost_a_circle/models/__pycache__/square.cpython-38.pyc -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/tests/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/tests/test_base.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Unittests for base 3 | """ 4 | 5 | import unittest 6 | from models.base import Base 7 | 8 | 9 | class TestBase(unittest.TestCase): 10 | """Define unit test for Base model""" 11 | 12 | def test_initialization(self): 13 | base1 = Base() 14 | base2 = Base() 15 | self.assertEqual(base1.id, 1) 16 | self.assertEqual(base2.id, 2) 17 | 18 | def test_saving_id(self): 19 | base = Base(100) 20 | self.assertEqual(base.id, 100) 21 | 22 | def test_to_json_string_valid(self): 23 | pass 24 | 25 | if __name__ == '__main__': 26 | unittest.main() 27 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/tests/test_square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Unittests for base 3 | """ 4 | 5 | import unittest 6 | from models.square import Square 7 | 8 | 9 | class TestSquare(unittest.TestCase): 10 | """Define unit test for Square model""" 11 | 12 | def test_initialization_success(self): 13 | s1 = Square(5) 14 | s2 = Square(10) 15 | self.assertEqual(s1.id, 5) 16 | self.assertEqual(s2.id, 6) 17 | 18 | def test_initialization_without_arguments(self): 19 | 20 | self.assertRaises(TypeError, Square) 21 | 22 | if __name__ == '__main__': 23 | unittest.main() 24 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/0-list_databases.sql: -------------------------------------------------------------------------------- 1 | -- Lists all databases of my MySQL server 2 | SHOW DATABASES; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/1-create_database_if_missing.sql: -------------------------------------------------------------------------------- 1 | -- Creates the database 'hbtn_0c_0' 2 | -- If database already exists, the script should not fail 3 | CREATE DATABASE IF NOT EXISTS hbtn_0c_0; 4 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/10-top_score.sql: -------------------------------------------------------------------------------- 1 | -- List all records in 'second_table' of db 'hbtn_0c_0' 2 | -- Results should display both score and name 3 | -- Records should be ordered by score (top first) 4 | SELECT score, name FROM second_table ORDER BY score DESC; 5 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/100-move_to_utf8.sql: -------------------------------------------------------------------------------- 1 | -- Converts the entire database hbtn_0c_0 to UTF8. 2 | USE `hbtn_0c_0` 3 | ALTER TABLE `first_table` 4 | CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci 5 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/101-avg_temperatures.sql: -------------------------------------------------------------------------------- 1 | -- retrieve average temperature 2 | SELECT city, avg(value) AS avg_temp FROM temperatures 3 | GROUP BY city 4 | ORDER BY avg_temp DESC; 5 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/11-best_score.sql: -------------------------------------------------------------------------------- 1 | -- List all records with score >= 10 in 'second_table' of db 'hbtn_0c_0' 2 | -- Results should display both score and name 3 | SELECT score, name FROM second_table WHERE score >= 10 ORDER BY score DESC; 4 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/12-no_cheating.sql: -------------------------------------------------------------------------------- 1 | -- Update score of Bob to 10 from 'second_table' of db 'hbtn_0c_0' 2 | UPDATE second_table SET score = 10 WHERE name = "Bob"; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/13-change_class.sql: -------------------------------------------------------------------------------- 1 | -- Remove all records with score <= 5 in 'second_table' of 'hbtn_0c_0' 2 | DELETE FROM second_table WHERE score <= 5; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/14-average.sql: -------------------------------------------------------------------------------- 1 | -- Computer score average of all records in 'second_table' of 'hbtn_0c_0' 2 | SELECT AVG(score) AS average FROM second_table; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/15-groups.sql: -------------------------------------------------------------------------------- 1 | -- List number of records with same score in 'second_table' 2 | SELECT score, COUNT(1) AS number FROM second_table 3 | GROUP BY score 4 | ORDER BY number DESC; 5 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/16-no_link.sql: -------------------------------------------------------------------------------- 1 | -- List all records of 'second_table' of db 'hbtn_0c_0' 2 | SELECT score, name 3 | FROM second_table 4 | HAVING name IS NOT NULL 5 | ORDER BY score DESC; 6 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/2-remove_database.sql: -------------------------------------------------------------------------------- 1 | -- Delete the database 'hbtn_0c_0' 2 | -- If 'hbtn_0c_0' doesn't exist, script should not fail 3 | DROP DATABASE IF EXISTS hbtn_0c_0; 4 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/3-list_tables.sql: -------------------------------------------------------------------------------- 1 | -- List all tables of a database in your MySQL database 2 | SHOW tables; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/4-first_table.sql: -------------------------------------------------------------------------------- 1 | -- Create a table called 'first_table' 2 | -- 'first_table' should have (id INT) and (name VARCHAR(256)) 3 | CREATE TABLE IF NOT EXISTS first_table (id INT, name VARCHAR(256)); 4 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/5-full_table.sql: -------------------------------------------------------------------------------- 1 | -- prints the full description of a table first_table 2 | SHOW CREATE TABLE first_table; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/6-list_values.sql: -------------------------------------------------------------------------------- 1 | -- List all rows of 'first_table' from db 'hbtn_0c_0' 2 | -- db name will be passed as arg to mysql cmd 3 | SELECT * FROM first_table; 4 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/7-insert_value.sql: -------------------------------------------------------------------------------- 1 | -- Insert new record row in 'first_table' from db 'hbtn_0c_0' 2 | -- id == 89 3 | -- name = Best School 4 | INSERT INTO `first_table` (`id`, `name`) VALUES (89, "Best School"); 5 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/8-count_89.sql: -------------------------------------------------------------------------------- 1 | -- Display number of records with id == 89 in 'first_table' 2 | -- of db 'hbtn_0c_0' in your MySQL server 3 | SELECT COUNT(*) FROM first_table WHERE id = 89; 4 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/9-full_creation.sql: -------------------------------------------------------------------------------- 1 | -- Create table 'second_table' in db 'hbtn_0c_0' 2 | -- Addprops (id INT), (name VARCHAR(256)), (score INT) 3 | CREATE TABLE IF NOT EXISTS second_table (id INT, name VARCHAR(256), score INT); 4 | 5 | -- Script should create 4 records 6 | INSERT INTO `second_table` (`id`, `name`, `score`) VALUES (1, "John", 10); 7 | INSERT INTO `second_table` (`id`, `name`, `score`) VALUES (2, "Alex", 3); 8 | INSERT INTO `second_table` (`id`, `name`, `score`) VALUES (3, "Bob", 14); 9 | INSERT INTO `second_table` (`id`, `name`, `score`) VALUES (4, "George", 8); 10 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/README.md: -------------------------------------------------------------------------------- 1 | ## 0x0D-SQL_introduction 2 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/0-select_states.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Write a script that lists all states from the database hbtn_0e_0_usa """ 3 | import MySQLdb 4 | import sys 5 | 6 | 7 | if __name__ == "__main__": 8 | db = MySQLdb.connect(host="localhost", user=sys.argv[1], 9 | passwd=sys.argv[2], db=sys.argv[3], port=3306) 10 | c = db.cursor() 11 | c.execute("SELECT * FROM states") 12 | rows = c.fetchall() 13 | for row in rows: 14 | print(row) 15 | c.close() 16 | db.close() 17 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/0-select_states.sql: -------------------------------------------------------------------------------- 1 | -- Create states table in hbtn_0e_0_usa with some data 2 | CREATE DATABASE IF NOT EXISTS hbtn_0e_0_usa; 3 | USE hbtn_0e_0_usa; 4 | CREATE TABLE IF NOT EXISTS states ( 5 | id INT NOT NULL AUTO_INCREMENT, 6 | name VARCHAR(256) NOT NULL, 7 | PRIMARY KEY (id) 8 | ); 9 | INSERT INTO states (name) VALUES ("California"), ("Arizona"), ("Texas"), ("New York"), ("Nevada"); 10 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/1-filter_states.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ lists all states from the database hbtn_0e_0_usa """ 3 | import MySQLdb 4 | import sys 5 | 6 | 7 | if __name__ == "__main__": 8 | db = MySQLdb.connect(host="localhost", user=sys.argv[1], 9 | passwd=sys.argv[2], db=sys.argv[3], port=3306) 10 | c = db.cursor() 11 | c.execute("""SELECT * FROM states WHERE name 12 | LIKE BINARY 'N%' ORDER BY states.id""") 13 | rows = c.fetchall() 14 | for row in rows: 15 | print(row) 16 | c.close() 17 | db.close() 18 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/12-model_state_update_id_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Write a script that changes the name of a State object from the database 3 | """ 4 | import sys 5 | from model_state import Base, State 6 | from sqlalchemy import (create_engine) 7 | from sqlalchemy.orm import sessionmaker 8 | 9 | 10 | if __name__ == "__main__": 11 | engine = create_engine('mysql+mysqldb://{}:{}@localhost:3306/{}' 12 | .format(sys.argv[1], sys.argv[2], sys.argv[3])) 13 | Base.metadata.create_all(engine) 14 | Session = sessionmaker(bind=engine) 15 | session = Session() 16 | new_instance = session.query(State).filter_by(id=2).first() 17 | new_instance.name = 'New Mexico' 18 | session.commit() 19 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/13-model_state_delete_a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Delete all State objects with a name containing the letter a 3 | """ 4 | import sys 5 | from model_state import Base, State 6 | from sqlalchemy import (create_engine) 7 | from sqlalchemy.orm import sessionmaker 8 | 9 | 10 | if __name__ == "__main__": 11 | engine = create_engine('mysql+mysqldb://{}:{}@localhost:3306/{}' 12 | .format(sys.argv[1], sys.argv[2], sys.argv[3])) 13 | Base.metadata.create_all(engine) 14 | Session = sessionmaker(bind=engine) 15 | session = Session() 16 | for instance in session.query(State).filter(State.name.like('%a%')): 17 | session.delete(instance) 18 | session.commit() 19 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/2-my_filter_states.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ display all table in a state where name matched the arg """ 3 | import MySQLdb 4 | import sys 5 | 6 | 7 | if __name__ == "__main__": 8 | db = MySQLdb.connect(host="localhost", user=sys.argv[1], 9 | passwd=sys.argv[2], db=sys.argv[3], port=3306) 10 | c = db.cursor() 11 | c.execute("SELECT * FROM states WHERE name LIKE BINARY '{}'" 12 | .format(sys.argv[4])) 13 | rows = c.fetchall() 14 | for row in rows: 15 | print(row) 16 | c.close() 17 | db.close() 18 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/3-my_safe_filter_states.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Write query that matches arges but safe SQL injection """ 3 | import MySQLdb 4 | import sys 5 | 6 | 7 | if __name__ == "__main__": 8 | db = MySQLdb.connect(host="localhost", user=sys.argv[1], 9 | passwd=sys.argv[2], db=sys.argv[3], port=3306) 10 | c = db.cursor() 11 | match = sys.argv[4] 12 | c.execute("SELECT * FROM states WHERE name LIKE %s", (match, )) 13 | rows = c.fetchall() 14 | for row in rows: 15 | print(row) 16 | c.close() 17 | db.close() 18 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/4-cities_by_state.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ lists all citie cities from database """ 3 | import MySQLdb 4 | import sys 5 | 6 | 7 | if __name__ == "__main__": 8 | db = MySQLdb.connect(host="localhost", user=sys.argv[1], 9 | passwd=sys.argv[2], db=sys.argv[3], port=3306) 10 | c = db.cursor() 11 | c.execute("""SELECT cities.id, cities.name, states.name FROM 12 | cities INNER JOIN states ON states.id=cities.state_id""") 13 | rows = c.fetchall() 14 | for row in rows: 15 | print(row) 16 | c.close() 17 | db.close() 18 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/5-filter_cities.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ lists all cities of a state in argument """ 3 | import MySQLdb 4 | import sys 5 | 6 | 7 | if __name__ == "__main__": 8 | db = MySQLdb.connect(host="localhost", user=sys.argv[1], 9 | passwd=sys.argv[2], db=sys.argv[3], port=3306) 10 | c = db.cursor() 11 | c.execute("""SELECT cities.name FROM 12 | cities INNER JOIN states ON states.id=cities.state_id 13 | WHERE states.name=%s""", (sys.argv[4],)) 14 | rows = c.fetchall() 15 | tmp = list(row[0] for row in rows) 16 | print(*tmp, sep=", ") 17 | c.close() 18 | db.close() 19 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/6-model_state.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Start link class to table in database 3 | """ 4 | import sys 5 | from model_state import Base, State 6 | 7 | from sqlalchemy import (create_engine) 8 | 9 | if __name__ == "__main__": 10 | engine = create_engine('mysql+mysqldb://{}:{}@localhost/{}'.format(sys.argv[1], sys.argv[2], sys.argv[3]), pool_pre_ping=True) 11 | Base.metadata.create_all(engine) 12 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/6-model_state.sql: -------------------------------------------------------------------------------- 1 | -- Create database hbtn_0e_6_usa 2 | CREATE DATABASE IF NOT EXISTS hbtn_0e_6_usa; 3 | USE hbtn_0e_6_usa; 4 | SHOW CREATE TABLE states; 5 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/7-model_state_fetch_all.sql: -------------------------------------------------------------------------------- 1 | -- Insert states 2 | INSERT INTO states (name) VALUES ("California"), ("Arizona"), ("Texas"), ("New York"), ("Nevada"); 3 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/9-model_state_filter_a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """ Write a script that lists all State objects that contain the letter a 4 | """ 5 | import sys 6 | from model_state import Base, State 7 | from sqlalchemy import (create_engine) 8 | from sqlalchemy.orm import sessionmaker 9 | 10 | 11 | if __name__ == "__main__": 12 | engine = create_engine('mysql+mysqldb://{}:{}@localhost:3306/{}' 13 | .format(sys.argv[1], sys.argv[2], sys.argv[3])) 14 | Base.metadata.create_all(engine) 15 | Session = sessionmaker(bind=engine) 16 | session = Session() 17 | for instance in session.query(State).filter(State.name.like('%a%')): 18 | print(instance.id, instance.name, sep=": ") 19 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/README.md: -------------------------------------------------------------------------------- 1 | #0x0F-python-object_relational_mapping 2 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/__pycache__/model_state.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swagasoft/alx-higher_level_programming/140ac44f0b4383afe1df2c2e6fd89c3a28ef30e6/0x0F-python-object_relational_mapping/__pycache__/model_state.cpython-38.pyc -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/model_city.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | model_city.py that contains the class definition of a City 4 | """ 5 | from model_state import Base 6 | from sqlalchemy import Column, Integer, String, ForeignKey 7 | from sqlalchemy.ext.declarative import declarative_base 8 | 9 | 10 | class City(Base): 11 | """ 12 | City Base class 13 | """ 14 | __tablename__ = 'cities' 15 | id = Column(Integer, unique=True, nullable=False, primary_key=True) 16 | name = Column(String(128), nullable=False) 17 | state_id = Column(Integer, ForeignKey("states.id"), nullable=False) 18 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/model_state.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """ 4 | Write a python file that contains the class definition of a State 5 | and an instance Base. 6 | """ 7 | 8 | from sqlalchemy import Column, Integer, String, MetaData 9 | from sqlalchemy.ext.declarative import declarative_base 10 | 11 | mymetadata = MetaData() 12 | Base = declarative_base(metadata=mymetadata) 13 | 14 | 15 | class State(Base): 16 | 17 | """ 18 | Class with attributes of a state. 19 | """ 20 | 21 | __tablename__ = 'states' 22 | id = Column(Integer, unique=True, nullable=False, primary_key=True) 23 | name = Column(String(128), nullable=False) 24 | -------------------------------------------------------------------------------- /0x10-python-network_0/0-body_size.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Send a request to that URL, and displays the size of the body of the response 3 | curl -s "$1" | wc -c 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/1-body.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # send a GET request to an URL with curl, and display the body of the response 3 | curl -sL "$1" 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/100-status_code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Displays only the status code of the response. 3 | curl -s -o /dev/null -w "%{http_code}" "$1" 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Test function find_peak """ 3 | find_peak = __import__('6-peak').find_peak 4 | 5 | print(find_peak([1, 2, 4, 6, 3])) 6 | print(find_peak([4, 2, 1, 2, 3, 1])) 7 | print(find_peak([2, 2, 2])) 8 | print(find_peak([])) 9 | print(find_peak([-2, -4, 2, 1])) 10 | print(find_peak([4, 2, 1, 2, 2, 2, 3, 1])) 11 | -------------------------------------------------------------------------------- /0x10-python-network_0/2-delete.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DELETE request to the URL passed as the first argument and displays the body of the response 3 | curl -sX DELETE "$1" 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/3-methods.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # display all HTTP methods the server will accept using curl. 3 | curl -sI "$1" | grep "Allow" | cut -d " " -f 2- 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/4-header.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Send a GET request to the URL, and displays the body of the response 3 | curl -sH "X-School-User-Id: 98" "$1" 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/5-post_params.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #POST request to the passed URL using curl, and display the body of the response 3 | curl -s -X POST -d "email=test@gmail.com&subject=I will always be here for PLD" "$1" 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Test function find_peak """ 3 | find_peak = __import__('6-peak').find_peak 4 | 5 | print(find_peak([1, 2, 4, 6, 3])) 6 | print(find_peak([4, 2, 1, 2, 3, 1])) 7 | print(find_peak([2, 2, 2])) 8 | print(find_peak([])) 9 | print(find_peak([-2, -4, 2, 1])) 10 | print(find_peak([4, 2, 1, 2, 2, 2, 3, 1])) 11 | -------------------------------------------------------------------------------- /0x10-python-network_0/6-peak.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """contains the function find_peak""" 3 | 4 | 5 | def find_peak(list_of_integers): 6 | """finds a peak in a list of unsorted integers""" 7 | li = list_of_integers 8 | l = len(li) 9 | if l == 0: 10 | return 11 | m = l // 2 12 | if (m == l - 1 or li[m] >= li[m + 1]) and (m == 0 or li[m] >= li[m - 1]): 13 | return li[m] 14 | if m != l - 1 and li[m + 1] > li[m]: 15 | return find_peak(li[m + 1:]) 16 | return find_peak(li[:m]) 17 | -------------------------------------------------------------------------------- /0x10-python-network_0/6-peak.txt: -------------------------------------------------------------------------------- 1 | O(log(n)) 2 | -------------------------------------------------------------------------------- /0x10-python-network_0/README.md: -------------------------------------------------------------------------------- 1 | 0x10-python-network_0 2 | -------------------------------------------------------------------------------- /0x11-python-network_1/0-hbtn_status.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Fetches https://alx-intranet.hbtn.io/status.""" 3 | import urllib.request 4 | 5 | 6 | if __name__ == "__main__": 7 | request = urllib.request.Request("https://alx-intranet.hbtn.io/status") 8 | with urllib.request.urlopen(request) as response: 9 | body = response.read() 10 | print("Body response:") 11 | print("\t- type: {}".format(type(body))) 12 | print("\t- content: {}".format(body)) 13 | print("\t- utf8 content: {}".format(body.decode("utf-8"))) 14 | -------------------------------------------------------------------------------- /0x11-python-network_1/1-hbtn_header.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Displays the X-Request-Id header variable of a request to a given URL. 3 | Usage: ./1-hbtn_header.py 4 | """ 5 | import sys 6 | import urllib.request 7 | 8 | 9 | if __name__ == "__main__": 10 | url = sys.argv[1] 11 | 12 | request = urllib.request.Request(url) 13 | with urllib.request.urlopen(request) as response: 14 | print(dict(response.headers).get("X-Request-Id")) 15 | -------------------------------------------------------------------------------- /0x11-python-network_1/10-my_github.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Uses the GitHub API to display a GitHub ID based on given credentials. 3 | """ 4 | import sys 5 | import requests 6 | from requests.auth import HTTPBasicAuth 7 | 8 | 9 | if __name__ == "__main__": 10 | auth = HTTPBasicAuth(sys.argv[1], sys.argv[2]) 11 | r = requests.get("https://api.github.com/user", auth=auth) 12 | print(r.json().get("id")) 13 | -------------------------------------------------------------------------------- /0x11-python-network_1/100-github_commits.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Lists the 10 most recent commits on a given GitHub repository. 3 | """ 4 | import sys 5 | import requests 6 | 7 | 8 | if __name__ == "__main__": 9 | url = "https://api.github.com/repos/{}/{}/commits".format( 10 | sys.argv[2], sys.argv[1]) 11 | 12 | r = requests.get(url) 13 | commits = r.json() 14 | try: 15 | for i in range(10): 16 | print("{}: {}".format( 17 | commits[i].get("sha"), 18 | commits[i].get("commit").get("author").get("name"))) 19 | except IndexError: 20 | pass 21 | -------------------------------------------------------------------------------- /0x11-python-network_1/2-post_email.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Sends a POST request to a given URL with a given email. 3 | """ 4 | import sys 5 | import urllib.parse 6 | import urllib.request 7 | 8 | 9 | if __name__ == "__main__": 10 | url = sys.argv[1] 11 | value = {"email": sys.argv[2]} 12 | data = urllib.parse.urlencode(value).encode("ascii") 13 | 14 | request = urllib.request.Request(url, data) 15 | with urllib.request.urlopen(request) as response: 16 | print(response.read().decode("utf-8")) 17 | -------------------------------------------------------------------------------- /0x11-python-network_1/3-error_code.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Sends a request to a given URL and displays the response body. 3 | Usage: ./3-error_code.py 4 | - Handles HTTP errors. 5 | """ 6 | import sys 7 | import urllib.error 8 | import urllib.request 9 | 10 | 11 | if __name__ == "__main__": 12 | url = sys.argv[1] 13 | 14 | request = urllib.request.Request(url) 15 | try: 16 | with urllib.request.urlopen(request) as response: 17 | print(response.read().decode("ascii")) 18 | except urllib.error.HTTPError as e: 19 | print("Error code: {}".format(e.code)) 20 | -------------------------------------------------------------------------------- /0x11-python-network_1/4-hbtn_status.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Fetches https://alx-intranet.hbtn.io/status.""" 3 | import requests 4 | 5 | 6 | if __name__ == "__main__": 7 | r = requests.get("https://alx-intranet.hbtn.io/status") 8 | print("Body response:") 9 | print("\t- type: {}".format(type(r.text))) 10 | print("\t- content: {}".format(r.text)) 11 | -------------------------------------------------------------------------------- /0x11-python-network_1/5-hbtn_header.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Displays the X-Request-Id header variable of a request to a given URL. 3 | """ 4 | import sys 5 | import requests 6 | 7 | 8 | if __name__ == "__main__": 9 | url = sys.argv[1] 10 | 11 | r = requests.get(url) 12 | print(r.headers.get("X-Request-Id")) 13 | -------------------------------------------------------------------------------- /0x11-python-network_1/6-post_email.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Sends a POST request to a given URL with a given email. 3 | Usage: ./6-post_email.py 4 | - Displays the body of the response. 5 | """ 6 | import sys 7 | import requests 8 | 9 | 10 | if __name__ == "__main__": 11 | url = sys.argv[1] 12 | value = {"email": sys.argv[2]} 13 | 14 | r = requests.post(url, data=value) 15 | print(r.text) 16 | -------------------------------------------------------------------------------- /0x11-python-network_1/7-error_code.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Sends a request to a given URL and displays the response body. 3 | Usage: ./7-error_code.py 4 | - Handles HTTP errors. 5 | """ 6 | import sys 7 | import requests 8 | 9 | 10 | if __name__ == "__main__": 11 | url = sys.argv[1] 12 | 13 | r = requests.get(url) 14 | if r.status_code >= 400: 15 | print("Error code: {}".format(r.status_code)) 16 | else: 17 | print(r.text) 18 | -------------------------------------------------------------------------------- /0x11-python-network_1/README.md: -------------------------------------------------------------------------------- 1 | #0x11-python-network_1 2 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/0-javascript_is_amazing.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const myVar = 'JavaScript is amazing'; 3 | console.log(myVar); 4 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/1-multi_languages.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | console.log('C is fun'); 3 | console.log('Python is cool'); 4 | console.log('JavaScript is amazing'); 5 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/10-factorial.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | function factorial (n) { 3 | if (n < 0) { 4 | return (-1); 5 | } 6 | if (n === 0 || isNaN(n)) { 7 | return (1); 8 | } 9 | return (n * factorial(n - 1)); 10 | } 11 | 12 | console.log(factorial(Number(process.argv[2]))); 13 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/100-let_me_const.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | myVar = 333; 3 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/101-call_me_moby.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.callMeMoby = function (x, theFunction) { 3 | for (let i = 0; i < x; i++) { 4 | theFunction(); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/102-add_me_maybe.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.addMeMaybe = function (number, theFunction) { 3 | theFunction(++number); 4 | }; 5 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/103-object_fct.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const myObject = { 3 | type: 'object', 4 | value: 12 5 | }; 6 | console.log(myObject); 7 | myObject.incr = function () { 8 | this.value++; 9 | }; 10 | myObject.incr(); 11 | console.log(myObject); 12 | myObject.incr(); 13 | console.log(myObject); 14 | myObject.incr(); 15 | console.log(myObject); 16 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/11-second_biggest.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | if (process.argv.length <= 3) { 3 | console.log('0'); 4 | } else { 5 | const arr = process.argv.slice(2).map(Number); 6 | const second = arr.sort(function (a, b) { return b - a; })[1]; 7 | console.log(second); 8 | } 9 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/12-object.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const myObject = { 3 | type: 'object', 4 | value: 12 5 | }; 6 | console.log(myObject); 7 | myObject.value = 89; 8 | console.log(myObject); 9 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/13-add.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.add = function (a, b) { 3 | return (a + b); 4 | }; 5 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/2-arguments.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | if (process.argv.length === 2) { 3 | console.log('No argument'); 4 | } else if (process.argv.length === 3) { 5 | console.log('Argument found'); 6 | } else { 7 | console.log('Arguments found'); 8 | } 9 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/3-value_argument.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | if (process.argv[2] === undefined) { 3 | console.log('No argument'); 4 | } else { 5 | console.log(process.argv[2]); 6 | } 7 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/4-concat.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | console.log(process.argv[2] + ' is ' + process.argv[3]); 3 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/5-to_integer.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | if (isNaN(process.argv[2]) || process.argv[2] === undefined) { 3 | console.log('Not a number'); 4 | } else { 5 | console.log('My number:', parseInt(process.argv[2])); 6 | } 7 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/6-multi_languages_loop.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const lst = ['C is fun', 'Python is cool', 'JavaScript is amazing']; 3 | for (const line of lst) { 4 | console.log(line); 5 | } 6 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/7-multi_c.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | if (process.argv[2] === undefined || isNaN(process.argv[2])) { 3 | console.log('Missing number of occurrences'); 4 | } else { 5 | const x = Number(process.argv[2]); 6 | let i = 0; 7 | while (i < x) { 8 | console.log('C is fun'); 9 | i++; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/8-square.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | if (process.argv[2] === undefined || isNaN(process.argv[2])) { 3 | console.log('Missing size'); 4 | } else { 5 | const x = Number(process.argv[2]); 6 | let i = 0; 7 | while (i < x) { 8 | console.log('X'.repeat(x)); 9 | i++; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/9-add.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | function add (a, b) { 3 | const c = a + b; 4 | console.log(c); 5 | } 6 | 7 | add(Number(process.argv[2]), Number(process.argv[3])); 8 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/README.md: -------------------------------------------------------------------------------- 1 | # Javascript Warm up 0x12-javascript-warm_up 2 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/0-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const Rectangle = require('./0-rectangle'); 3 | 4 | const r1 = new Rectangle(); 5 | console.log(r1); 6 | console.log(r1.constructor); 7 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/0-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | module.exports = class Rectangle { }; 3 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/1-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const Rectangle = require('./1-rectangle'); 3 | 4 | const r1 = new Rectangle(2, 3); 5 | console.log(r1); 6 | console.log(r1.width); 7 | console.log(r1.height); 8 | 9 | const r2 = new Rectangle(2, -3); 10 | console.log(r2); 11 | console.log(r2.width); 12 | console.log(r2.height); 13 | 14 | const r3 = new Rectangle(2); 15 | console.log(r3); 16 | console.log(r3.width); 17 | console.log(r3.height) 18 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/1-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | class Rectangle { 4 | constructor (w, h) { 5 | this.width = w; 6 | this.height = h; 7 | } 8 | } 9 | 10 | module.exports = Rectangle; 11 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/10-converter.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | exports.converter = function (base) { 4 | return function (num) { 5 | return num.toString(base); 6 | }; 7 | }; 8 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/10-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const converter = require('./10-converter').converter; 3 | 4 | let myConverter = converter(10); 5 | 6 | console.log(myConverter(2)); 7 | console.log(myConverter(12)); 8 | console.log(myConverter(89)); 9 | 10 | 11 | myConverter = converter(16); 12 | 13 | console.log(myConverter(2)); 14 | console.log(myConverter(12)); 15 | console.log(myConverter(89)); 16 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/100-data.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.list = [1, 2, 3, 4, 5]; 3 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/100-map.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const list = require('./100-data').list; 3 | console.log(list); 4 | console.log(list.map((x, i) => x * i)); 5 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/101-data.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.dict = { 3 | 89: 1, 4 | 90: 2, 5 | 91: 1, 6 | 92: 3, 7 | 93: 1, 8 | 94: 2 9 | }; 10 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/101-sorted.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const dict = require('./101-data').dict; 3 | const dKeys = Object.keys(dict); 4 | const values = Object.values(dict); 5 | let matched; 6 | const result = {}; 7 | // loop over the values 8 | for (let i = 0; i < values.length; i++) { 9 | result[JSON.stringify(values[i])] = []; 10 | matched = dKeys.filter(key => dict[key] === values[i]); 11 | matched.forEach(item => result[JSON.stringify(values[i])].push(item)); 12 | } 13 | console.log(result) 14 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/1010-data.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.dict = { 3 | 89: 1, 4 | 90: 2, 5 | 91: 1, 6 | 92: 3, 7 | 93: 1, 8 | 94: 2 9 | }; 10 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/102-concat.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const { readFileSync, writeFile } = require('fs'); 3 | const { argv } = require('process'); 4 | 5 | const getContent = (file) => { 6 | return readFileSync(file, 'utf8'); 7 | }; 8 | 9 | const concated = getContent(argv[2]) + '' + getContent(argv[3]); 10 | 11 | writeFile(argv[4], concated, 'utf8', err => { 12 | if (err) throw err; 13 | }); 14 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/2-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const Rectangle = require('./2-rectangle'); 3 | 4 | const r1 = new Rectangle(2, 3); 5 | console.log(r1); 6 | console.log(r1.width); 7 | console.log(r1.height); 8 | 9 | const r2 = new Rectangle(2, -3); 10 | console.log(r2); 11 | console.log(r2.width); 12 | console.log(r2.height); 13 | 14 | const r3 = new Rectangle(2); 15 | console.log(r3); 16 | console.log(r3.width); 17 | console.log(r3.height); 18 | 19 | const r4 = new Rectangle(2, 0); 20 | console.log(r4); 21 | console.log(r4.width); 22 | console.log(r4.height); 23 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/2-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | class Rectangle { 4 | constructor (w, h) { 5 | if (w > 0 && h > 0) { 6 | this.width = w; 7 | this.height = h; 8 | } 9 | } 10 | } 11 | 12 | module.exports = Rectangle; 13 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/3-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const Rectangle = require('./3-rectangle'); 3 | 4 | const r1 = new Rectangle(2, 3); 5 | r1.print(); 6 | 7 | const r2 = new Rectangle(10, 5); 8 | r2.print(); 9 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/3-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | class Rectangle { 4 | constructor (w, h) { 5 | if (w > 0 && h > 0) { 6 | this.width = w; 7 | this.height = h; 8 | } 9 | } 10 | 11 | print () { 12 | for (let i = 0; i < this.height; i++) { 13 | console.log('X'.repeat(this.width)); 14 | } 15 | } 16 | } 17 | 18 | module.exports = Rectangle; 19 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/4-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const Rectangle = require('./4-rectangle'); 3 | 4 | const r1 = new Rectangle(2, 3); 5 | console.log('Normal:'); 6 | r1.print(); 7 | 8 | console.log('Double:'); 9 | r1.double(); 10 | r1.print(); 11 | 12 | console.log('Rotate:'); 13 | r1.rotate(); 14 | r1.print(); 15 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/4-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | class Rectangle { 4 | constructor (w, h) { 5 | if (w > 0 && h > 0) { 6 | this.width = w; 7 | this.height = h; 8 | } 9 | } 10 | 11 | print () { 12 | for (let i = 0; i < this.height; i++) { 13 | console.log('X'.repeat(this.width)); 14 | } 15 | } 16 | 17 | rotate () { 18 | [this.width, this.height] = [this.height, this.width]; 19 | } 20 | 21 | double () { 22 | this.width = this.width * 2; 23 | this.height = this.height * 2; 24 | } 25 | } 26 | 27 | module.exports = Rectangle; 28 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/5-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const Square = require('./5-square'); 3 | 4 | const s1 = new Square(4); 5 | s1.print(); 6 | s1.double(); 7 | s1.print(); 8 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/5-square.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const Rectangle = require('./4-rectangle'); 4 | 5 | class Square extends Rectangle { 6 | constructor (size) { 7 | super(size, size); 8 | } 9 | } 10 | 11 | module.exports = Square; 12 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/6-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const Square = require('./6-square'); 3 | 4 | const s1 = new Square(4); 5 | s1.charPrint(); 6 | 7 | s1.charPrint('C'); 8 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/6-square.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const supSquare = require('./5-square'); 4 | 5 | class Square extends supSquare { 6 | charPrint (c) { 7 | if (c == null) { 8 | c = 'X'; 9 | } 10 | for (let i = 0; i < this.width; i++) { 11 | console.log(c.repeat(this.width)); 12 | } 13 | } 14 | } 15 | 16 | module.exports = Square; 17 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/7-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const nbOccurences = require('./7-occurrences').nbOccurences; 3 | 4 | console.log(nbOccurences([1, 2, 3, 4, 5, 6], 3)); 5 | console.log(nbOccurences([3, 2, 3, 4, 5, 3, 3], 3)); 6 | console.log(nbOccurences(["S", 12, "c", "S", "School", 8], "S")); 7 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/7-occurrences.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | exports.nbOccurences = function (list, searchElement) { 4 | return list.reduce((a, v) => (v === searchElement ? a + 1 : a), 0); 5 | }; 6 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/8-esrever.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.esrever = function (list) { 3 | let len = list.length - 1; 4 | let i = 0; 5 | while ((len - i) > 0) { 6 | const aux = list[len]; 7 | list[len] = list[i]; 8 | list[i] = aux; 9 | i++; 10 | len--; 11 | } 12 | return list; 13 | }; 14 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/8-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const esrever = require('./8-esrever').esrever; 3 | 4 | console.log(esrever([1, 2, 3, 4, 5])); 5 | console.log(esrever(["School", 89, { id: 12 }, "String"])); 6 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/9-logme.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | exports.logMe = function (item) { 4 | if (typeof this.count === 'undefined') { 5 | this.count = 0; 6 | } 7 | console.log(this.count + ': ' + item); 8 | this.count++; 9 | }; 10 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/9-main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const logMe = require('./9-logme').logMe; 3 | 4 | logMe("Hello"); 5 | logMe("Best"); 6 | logMe("School") 7 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/README.md: -------------------------------------------------------------------------------- 1 | #0x13-javascript_objects_scopes_closures 2 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/0-readme.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const fs = require('fs'); 3 | 4 | fs.readFile(process.argv[2], 'utf8', (err, data) => { 5 | if (err) { 6 | return console.log(err); 7 | } 8 | process.stdout.write(data); 9 | }); 10 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/1-writeme.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const fs = require('fs'); 4 | 5 | const args = process.argv; 6 | 7 | fs.writeFile(args[2], args[3], 'utf8', function (err) { 8 | if (err) { 9 | console.log(err); 10 | } 11 | }); 12 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/2-statuscode.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const request = require('request'); 4 | 5 | const url = process.argv[2]; 6 | 7 | request.get(url, (error, response) => { 8 | if (error) { 9 | console.error(error); 10 | } else { 11 | console.log(`code: ${response.statusCode}`); 12 | } 13 | }); 14 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/3-starwars_title.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const request = require('request'); 4 | 5 | const id = process.argv[2]; 6 | const url = `https://swapi-api.alx-tools.com/api/films/${id}`; 7 | 8 | request.get(url, (error, response, body) => { 9 | if (error) { 10 | console.error(error); 11 | } else if (response.statusCode !== 200) { 12 | console.error(`Error: ${response.statusCode} - ${response.statusMessage}`); 13 | } else { 14 | const film = JSON.parse(body); 15 | console.log(film.title); 16 | } 17 | }); 18 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/4-starwars_count.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const request = require('request'); 4 | 5 | const url = process.argv[2]; 6 | 7 | request.get(url, (error, response, body) => { 8 | if (error) { 9 | console.error(error); 10 | } else if (response.statusCode !== 200) { 11 | console.error(`Error: ${response.statusCode} - ${response.statusMessage}`); 12 | } else { 13 | const films = JSON.parse(body).results; 14 | const characterId = '18'; 15 | const count = films.filter(film => film.characters.includes(`https://swapi-api.alx-tools.com/api/people/${characterId}/`)).length; 16 | console.log(count); 17 | } 18 | }); 19 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/5-request_store.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const request = require('request'); 4 | const fs = require('fs'); 5 | 6 | const args = process.argv; 7 | const url = args[2]; 8 | const filePath = args[3]; 9 | 10 | request( 11 | { 12 | method: 'GET', 13 | uri: url 14 | }, 15 | function (error, response, body) { 16 | if (error) throw error; 17 | if (response.statusCode === 200) { 18 | fs.writeFile(filePath, body, 'utf8', function (error) { 19 | if (error) throw error; 20 | }); 21 | } 22 | } 23 | ); 24 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/6-completed_tasks.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const request = require('request'); 4 | 5 | const url = process.argv[2]; 6 | const out = {}; 7 | 8 | function count (todo) { 9 | if (todo.completed) { 10 | const userId = todo.userId.toString(); 11 | out[userId] = out[userId] + 1 || 1; 12 | } 13 | } 14 | 15 | request(url, (error, response, body) => { 16 | if (error) throw error; 17 | if (response.statusCode === 200) { 18 | JSON.parse(body).forEach(count); 19 | console.log(out); 20 | } 21 | }); 22 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/README.md: -------------------------------------------------------------------------------- 1 | 0x14-javascript-web_scraping 2 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/cisfun: -------------------------------------------------------------------------------- 1 | C is super fun! 2 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/my_file.txt: -------------------------------------------------------------------------------- 1 | Python is cool -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/0-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 |
8 | First HTML page 9 |
10 |
11 | Holberton School - 2017 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/0-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | const header = document.querySelector('header'); 4 | header.style.color = '#FF0000'; 5 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/1-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 |
9 | First HTML page 10 |
11 |
12 | Holberton School - 2017 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/1-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $('header').css('color', '#FF0000'); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/100-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 |
9 | First HTML page 10 |
11 |
12 | Holberton School - 2017 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/2-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 |
9 | First HTML page 10 |
11 |
Red header
12 |
13 | Holberton School - 2017 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/2-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $(document).ready(function () { 4 | $('#red_header').click(function () { 5 | $('header').css('color', '#FF0000'); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/3-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 11 | 12 | 13 |
14 | First HTML page 15 |
16 |
Red header
17 |
18 | Holberton School - 2017 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/3-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $(document).ready(function () { 4 | $('#red_header').click(function () { 5 | $('header').addClass('red'); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/4-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 14 | 15 | 16 |
17 | First HTML page 18 |
19 |
Toggle header
20 |
21 | Holberton School - 2017 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/4-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $(document).ready(function () { 4 | $('#toggle_header').click(function () { 5 | if ($('header').hasClass('green')) { 6 | $('header').removeClass('green'); 7 | $('header').addClass('red'); 8 | } else { 9 | $('header').removeClass('red'); 10 | $('header').addClass('green'); 11 | } 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/5-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 |
9 | First HTML page 10 |
11 |
12 |
Add item
13 |
14 |
    15 |
  • Item
  • 16 |
17 |
18 | Holberton School - 2017 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/5-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $(document).ready(function () { 4 | $('div#add_item').click(function () { 5 | $('ul.my_list').append('
  • Item
  • '); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/6-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 |
    9 | First HTML page 10 |
    11 |
    12 |
    Update the header
    13 |
    14 |
    15 | Holberton School - 2017 16 |
    17 | 18 | 19 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/6-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $(document).ready(function () { 4 | $('div#update_header').click(function () { 5 | $('header').text('New Header!!!'); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/7-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 |
    9 | Star Wars character 10 |
    11 |
    12 |
    13 |
    14 |
    15 | Holberton School - 2017 16 |
    17 | 18 | 19 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/7-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $(document).ready(function () { 4 | $.getJSON('https://swapi-api.alx-tools.com/api/people/5/?format=json', function (data) { 5 | $('div#character').text(data.name); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/8-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 |
    9 | Star Wars movies 10 |
    11 |
    12 |
      13 |
    14 |
    15 |
    16 | Holberton School - 2017 17 |
    18 | 19 | 20 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/8-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $(document).ready(function () { 4 | $.getJSON('https://swapi-api.alx-tools.com/api/films/?format=json', function (data) { 5 | const items = []; 6 | $.each(data.results, function (index, value) { 7 | items.push('
  • ' + value.title + '
  • '); 8 | }); 9 | $.each(items, function (index, value) { 10 | $('ul#list_movies').append(value); 11 | }); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/9-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 | 9 |
    10 | Say Hello! 11 |
    12 |
    13 |
    14 |
    15 | 18 | 19 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/9-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | 3 | $(document).ready(function () { 4 | $.getJSON('https://fourtonfish.com/hellosalut/?lang=fr', function (data) { 5 | $('div#hello').text(data.hello); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/README.md: -------------------------------------------------------------------------------- 1 | 0x15. JavaScript - Web jQuery 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Welcome tohigh level rogramming projects 2 | ##Thes is the basic using pthon 3 | --------------------------------------------------------------------------------