├── 0x00-python-hello_world ├── 0-run ├── 1-run_inline ├── 10-check_cycle.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 └── lists.h ├── 0x01-python-if_else_loops_functions ├── 0-positive_or_negative.py ├── 1-last_digit.py ├── 10-add.py ├── 100-print_tebahpla.py ├── 101-remove_char_at.py ├── 102-magic_calculation.py ├── 11-pow.py ├── 12-fizzbuzz.py ├── 13-insert_number.c ├── 2-print_alphabet.py ├── 3-print_alphabt.py ├── 4-print_hexa.py ├── 5-print_comb2.py ├── 6-print_comb3.py ├── 7-islower.py ├── 8-uppercase.py ├── 9-print_last_digit.py ├── README.md └── lists.h ├── 0x02-python-import_modules ├── 0-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__ │ ├── add_0.cpython-39.pyc │ ├── calculator_1.cpython-39.pyc │ └── variable_load_5.cpython-39.pyc ├── add_0.py ├── calculator_1.py ├── hidden_4.pyc └── variable_load_5.py ├── 0x03-python-data_structures ├── .gitignore ├── 0-print_list_integer.py ├── 1-element_at.py ├── 10-divisible_by_2.py ├── 100-print_python_list_info.c ├── 11-delete_at.py ├── 12-switch.py ├── 13-is_palindrome.c ├── 2-replace_in_list.py ├── 3-print_reversed_list_integer.py ├── 4-new_in_list.py ├── 5-no_c.py ├── 6-print_matrix_integer.py ├── 7-add_tuple.py ├── 8-multiple_returns.py ├── 9-max_integer.py ├── README.md ├── linked_lists.c ├── lists.h └── palindrome ├── 0x04-python-more_data_structures ├── .gitignore ├── 0-square_matrix_simple.py ├── 1-search_replace.py ├── 10-best_score.py ├── 100-weight_average.py ├── 101-square_matrix_map.py ├── 102-complex_delete.py ├── 103-python.c ├── 11-multiply_list_map.py ├── 12-roman_to_int.py ├── 2-uniq_add.py ├── 3-common_elements.py ├── 4-only_diff_elements.py ├── 5-number_keys.py ├── 6-print_sorted_dictionary.py ├── 7-update_dictionary.py ├── 8-simple_delete.py ├── 9-multiply_by_2.py └── README.md ├── 0x05-python-exceptions ├── .gitignore ├── 0-safe_print_list.py ├── 1-safe_print_integer.py ├── 100-safe_print_integer_err.py ├── 101-safe_function.py ├── 102-magic_calculation.py ├── 103-python.c ├── 2-safe_print_list_integers.py ├── 3-safe_print_division.py ├── 4-list_division.py ├── 5-raise_exception.py ├── 6-raise_exception_msg.py └── README.md ├── 0x06-python-classes ├── 0-square.py ├── 1-square.py ├── 100-singly_linked_list.py ├── 101-square.py ├── 102-square.py ├── 103-magic_class.py ├── 2-square.py ├── 3-square.py ├── 4-square.py ├── 5-square.py ├── 6-square.py ├── README.md └── tests │ ├── 0-main.py │ ├── 0-square.py │ ├── 1-main.py │ ├── 1-square.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 │ └── __pycache__ │ ├── 0-square.cpython-39.pyc │ ├── 1-square.cpython-39.pyc │ ├── 2-square.cpython-39.pyc │ ├── 3-square.cpython-39.pyc │ ├── 4-square.cpython-39.pyc │ ├── 5-square.cpython-39.pyc │ └── 6-square.cpython-39.pyc ├── 0x07-python-test_driven_development ├── .gitignore ├── 0-add_integer.py ├── 100-matrix_mul.py ├── 101-lazy_matrix_mul.py ├── 102-python.c ├── 2-matrix_divided.py ├── 3-say_my_name.py ├── 4-print_square.py ├── 5-text_indentation.py ├── README.md └── tests │ ├── 0-add_integer.py │ ├── 0-add_integer.txt │ ├── 100-matrix_mul.txt │ ├── 101-lazy_matrix_mul.txt │ ├── 2-matrix_divided.txt │ ├── 3-say_my_name.txt │ ├── 4-print_square.txt │ ├── 5-text_indentation.txt │ ├── 6-max_integer.py │ └── 6-max_integer_test.py ├── 0x07-test_driven_development ├── __pycache__ │ ├── 3-say_my_name.cpython-39.pyc │ ├── 4-print_square.cpython-39.pyc │ └── 5-text_indentation.cpython-39.pyc └── tests │ └── __pycache__ │ └── 0-add_integer.cpython-39.pyc ├── 0x08-python-more_classes ├── 0-rectangle.py ├── 1-rectangle.py ├── 101-nqueens.py ├── 2-rectangle.py ├── 3-rectangle.py ├── 4-rectangle.py ├── 5-rectangle.py ├── 6-rectangle.py ├── 7-rectangle.py ├── 8-rectangle.py ├── 9-rectangle.py └── README.md ├── 0x09-python-everything_is_object ├── 0-answer.txt ├── 1-answer.txt ├── 10-answer.txt ├── 100-magic_string.py ├── 101-locked_class.py ├── 103-line1.txt ├── 103-line2.txt ├── 104-line1.txt ├── 104-line2.txt ├── 104-line3.txt ├── 104-line4.txt ├── 104-line5.txt ├── 105-line1.txt ├── 106-line1.txt ├── 106-line2.txt ├── 106-line3.txt ├── 106-line4.txt ├── 106-line5.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 ├── 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 ├── 0x0A-python-inheritance ├── 0-lookup.py ├── 1-my_list.py ├── 10-square.py ├── 100-my_int.py ├── 101-add_attribute.py ├── 11-square.py ├── 2-is_same_class.py ├── 3-is_kind_of_class.py ├── 4-inherits_from.py ├── 5-base_geometry.py ├── 6-base_geometry.py ├── 7-base_geometry.py ├── 8-rectangle.py ├── 9-rectangle.py ├── README.md └── tests │ ├── 0-main.py │ ├── 1-main.py │ ├── 1-my_list.txt │ ├── 10-main.py │ ├── 100-main.py │ ├── 101-main.py │ ├── 11-main.py │ ├── 2-main.py │ ├── 3-main.py │ ├── 4-main.py │ ├── 5-main.py │ ├── 6-main.py │ ├── 7-base_geometry.txt │ ├── 7-main.py │ ├── 8-main.py │ └── 9-main.py ├── 0x0B-python-input_output ├── 0-read_file.py ├── 1-write_file.py ├── 10-student.py ├── 100-append_after.py ├── 101-stats.py ├── 11-student.py ├── 12-pascal_triangle.py ├── 2-append_write.py ├── 3-to_json_string.py ├── 4-from_json_string.py ├── 5-save_to_json_file.py ├── 6-load_from_json_file.py ├── 7-add_item.py ├── 8-class_to_json.py ├── 9-student.py ├── README.md ├── read_write_heap.py └── tests │ ├── 0-main.py │ ├── 1-main.py │ ├── 10-main.py │ ├── 10-my_class.py │ ├── 100-main.py │ ├── 11-main.py │ ├── 12-main.py │ ├── 14-main.py │ ├── 2-main.py │ ├── 3-main.py │ ├── 4-main.py │ ├── 5-main.py │ └── 6-main.py ├── 0x0C-python-almost_a_circle ├── README.md ├── models │ ├── __init__.py │ ├── base.py │ ├── rectangle.py │ └── square.py └── tests │ ├── __init__.py │ └── test_models │ ├── __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 ├── 102-top_city.sql ├── 103-max_state.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 ├── 0x0E-SQL_more_queries ├── 0-privileges.sql ├── 1-create_user.sql ├── 10-genre_id_by_show.sql ├── 11-genre_id_all_shows.sql ├── 12-no_genre.sql ├── 13-count_shows_by_genre.sql ├── 14-my_genres.sql ├── 15-comedy_only.sql ├── 16-shows_by_genre.sql ├── 2-create_read_user.sql ├── 3-force_name.sql ├── 4-never_empty.sql ├── 5-unique_id.sql ├── 6-states.sql ├── 7-cities.sql ├── 8-cities_of_california_subquery.sql ├── 9-cities_by_state_join.sql └── README.md ├── 0x0F-python-object_relational_mapping ├── 0-select_states.py ├── 1-filter_states.py ├── 10-model_state_my_get.py ├── 100-relationship_states_cities.py ├── 101-relationship_states_cities_list.py ├── 102-relationship_cities_states_list.py ├── 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 ├── 2-my_filter_states.py ├── 3-my_safe_filter_states.py ├── 4-cities_by_state.py ├── 5-filter_cities.py ├── 7-model_state_fetch_all.py ├── 8-model_state_fetch_first.py ├── 9-model_state_filter_a.py ├── README.md ├── model_city.py ├── model_state.py ├── relationship_city.py └── relationship_state.py ├── 0x10-python-network_0 ├── .idea │ ├── .gitignore │ ├── 0x10-python-network_0.iml │ ├── inspectionProfiles │ │ ├── Project_Default.xml │ │ └── profiles_settings.xml │ ├── misc.xml │ ├── modules.xml │ └── vcs.xml ├── 0-body_size.sh ├── 1-body.sh ├── 100-status_code.sh ├── 101-post_json.sh ├── 102-catch_me.sh ├── 2-delete.sh ├── 3-methods.sh ├── 4-header.sh ├── 5-post_params.sh ├── 6-peak.py ├── 6-peak.txt └── README.md ├── 0x11-python-network_1 ├── .idea │ ├── .gitignore │ ├── 0x11-python-network_1.iml │ ├── inspectionProfiles │ │ ├── Project_Default.xml │ │ └── profiles_settings.xml │ ├── misc.xml │ ├── modules.xml │ └── vcs.xml ├── 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-rectangle.js ├── 1-rectangle.js ├── 10-converter.js ├── 100-data.js ├── 100-map.js ├── 101-sorted.js ├── 102-concat.js ├── 2-rectangle.js ├── 3-rectangle.js ├── 4-rectangle.js ├── 5-square.js ├── 6-square.js ├── 7-occurrences.js ├── 8-esrever.js ├── 9-logme.js └── README.md ├── 0x14-javascript-web_scraping ├── 0-readme.js ├── 1-writeme.js ├── 100-starwars_characters.js ├── 101-starwars_characters.js ├── 2-statuscode.js ├── 3-starwars_title.js ├── 4-starwars_count.js ├── 5-request_store.js ├── 6-completed_tasks.js ├── README.md └── package.json ├── 0x15-javascript-web_jquery ├── 0-script.js ├── 1-script.js ├── 100-script.js ├── 101-script.js ├── 102-script.js ├── 103-script.js ├── 2-script.js ├── 3-script.js ├── 4-script.js ├── 5-script.js ├── 6-script.js ├── 7-script.js ├── 8-script.js ├── 9-script.js ├── README.md └── tests │ ├── 0-main.html │ ├── 1-main.html │ ├── 100-main.html │ ├── 101-main.html │ ├── 102-main.html │ ├── 103-main.html │ ├── 2-main.html │ ├── 3-main.html │ ├── 4-main.html │ ├── 5-main.html │ ├── 6-main.html │ ├── 7-main.html │ ├── 8-main.html │ └── 9-main.html └── 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/10-check_cycle.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * check_cycle - checks if a singly linked list has a cycle 5 | * @list: pointer to the head of the list 6 | * Return: 0 in case of no cycle and 1 at the opposite 7 | */ 8 | 9 | int check_cycle(listint_t *list) 10 | { 11 | listint_t *p2; 12 | listint_t *prev; 13 | 14 | p2 = list; 15 | prev = list; 16 | while (list && p2 && p2->next) 17 | { 18 | list = list->next; 19 | p2 = p2->next->next; 20 | 21 | if (list == p2) 22 | { 23 | list = prev; 24 | prev = p2; 25 | while (1) 26 | { 27 | p2 = prev; 28 | while (p2->next != list && p2->next != prev) 29 | { 30 | p2 = p2->next; 31 | } 32 | if (p2->next == list) 33 | break; 34 | 35 | list = list->next; 36 | } 37 | return (1); 38 | } 39 | } 40 | 41 | return (0); 42 | } -------------------------------------------------------------------------------- /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("{:d} Battery street".format(number)) 4 | -------------------------------------------------------------------------------- /0x00-python-hello_world/4-print_float.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | number = 3.14159 3 | print('Float: {:04.2f}'.format(number)) 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("Welcome to {}!".format(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("First 3 letters: {}".format(word_first_3)) 7 | print("Last 2 letters: {}".format(word_last_2)) 8 | print("Middle word: {}".format(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/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 | * 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 */ -------------------------------------------------------------------------------- /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("{} is positive".format(number)) 6 | elif number < 0: 7 | print("{} is negative".format(number)) 8 | else: 9 | print("{} is zero".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 | digit = abs(number) % 10 5 | if number < 0: 6 | digit = -digit 7 | print("Last digit of {} is {} and is ".format(number, digit), end="") 8 | if digit > 5: 9 | print("greater than 5") 10 | elif digit == 0: 11 | print("0") 12 | else: 13 | print("less than 6 and not 0") 14 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/10-add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def add(a, b): 3 | """Return the addition of a and b""" 4 | return (a + b) 5 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/100-print_tebahpla.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Print the alphabet in reverse order alterning upper and lower case""" 3 | i = 0 4 | for c in range(ord('z'), ord('a') - 1, -1): 5 | print("{}".format(chr(c - i)), end="") 6 | i = 32 if i == 0 else 0 7 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/101-remove_char_at.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def remove_char_at(str, n): 3 | """Create a copy of the string without the character at position n""" 4 | if n < 0: 5 | return (str) 6 | return (str[:n] + str[n+1:]) 7 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/102-magic_calculation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def magic_calculation(a, b, c): 3 | """Match bytecode provided by holberton school""" 4 | if a < b: 5 | return (c) 6 | if c > b: 7 | return (a + b) 8 | return (a*b - c) 9 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/11-pow.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def pow(a, b): 3 | """Return a to the power of b""" 4 | return (a ** b) 5 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/12-fizzbuzz.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def fizzbuzz(): 3 | """Print the numbers from 1 to 100 separated by a space. 4 | 5 | For multiples of three, print Fizz instead of the number. 6 | For multiples of five, print Buzz instead of the number. 7 | For multiples of three and five, print FizzBuzz instead of the number. 8 | """ 9 | for number in range(1, 101): 10 | if number % 3 == 0 and number % 5 == 0: 11 | print("FizzBuzz ", end="") 12 | elif number % 3 == 0: 13 | print("Fizz ", end="") 14 | elif number % 5 == 0: 15 | print("Buzz ", end="") 16 | else: 17 | print("{} ".format(number), end="") 18 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/13-insert_number.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | *insert_node - Inserts a number into a sorted singly-linked list 5 | *@head: A pointer the head of the linked list 6 | *@number: The number to insert 7 | * 8 | *Return: NULL in case of failure 9 | * a pointer to the new mode 10 | */ 11 | 12 | listint_t *insert_node(listint_t **head, int number) 13 | { 14 | listint_t *node = *head, *new; 15 | 16 | new = malloc(sizeof(listint_t)); 17 | if (new == NULL) 18 | return (NULL); 19 | new->n = number; 20 | 21 | if (node == NULL || node->n >= number) 22 | { 23 | new->next = node; 24 | *head = new; 25 | return (new); 26 | } 27 | 28 | while (node && node->next && node->next->n < number) 29 | node = node->next; 30 | 31 | new->next = node->next; 32 | node->next = new; 33 | 34 | return (new); 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/2-print_alphabet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for letter in range(97, 123): 3 | print("{}".format(chr(letter)), end="") 4 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/3-print_alphabt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for letter in range(97, 123): 3 | if chr(letter) != 'q' and chr(letter) != 'e': 4 | print("{}".format(chr(letter)), end="") 5 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/4-print_hexa.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for number in range(0, 99): 3 | print("{} = {}".format(number, hex(number))) 4 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/5-print_comb2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for number in range(0, 100): 3 | if number == 99: 4 | print("{}".format(number)) 5 | else: 6 | print("{:02}".format(number), end=", ") 7 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/6-print_comb3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | for digit1 in range(0, 10): 3 | for digit2 in range(digit1 + 1, 10): 4 | if digit1 == 8 and digit2 == 9: 5 | print("{}{}".format(digit1, digit2)) 6 | else: 7 | print("{}{}".format(digit1, digit2), end=", ") 8 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/7-islower.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def islower(c): 3 | """Print a string in lowercase.""" 4 | if ord(c) >= 97 and ord(c) <= 122: 5 | return True 6 | else: 7 | return False 8 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/8-uppercase.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def uppercase(str): 3 | """Print a string in uppercase.""" 4 | for c in str: 5 | if ord(c) >= 97 and ord(c) <= 123: 6 | c = chr(ord(c) - 32) 7 | print("{}".format(c), end="") 8 | print("") 9 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/9-print_last_digit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def print_last_digit(number): 3 | """Print the last digit of a number and return it""" 4 | print(abs(number) % 10, end="") 5 | return (abs(number) % 10) 6 | -------------------------------------------------------------------------------- /0x01-python-if_else_loops_functions/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 | listint_t *insert_node(listint_t **head, int number); 24 | 25 | #endif /* LISTS_H */ 26 | -------------------------------------------------------------------------------- /0x02-python-import_modules/0-add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | """Print the sum of 1 and 2""" 4 | from add_0 import add 5 | 6 | a = 1 7 | b = 2 8 | print("{} + {} = {}".format(a, b, add(a, b))) 9 | -------------------------------------------------------------------------------- /0x02-python-import_modules/1-calculation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | """Print the sum, difference, multiple and quotient of 10 and 5""" 4 | from calculator_1 import add, sub, mul, div 5 | 6 | a = 10 7 | b = 5 8 | 9 | print("{} + {} = {}".format(a, b, add(a, b))) 10 | print("{} - {} = {}".format(a, b, sub(a, b))) 11 | print("{} * {} = {}".format(a, b, mul(a, b))) 12 | print("{} / {} = {}".format(a, b, div(a, b))) 13 | -------------------------------------------------------------------------------- /0x02-python-import_modules/100-my_calculator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | if __name__ == "__main__": 4 | import sys 5 | 6 | nargs = len(sys.argv) - 1 7 | if nargs != 3: 8 | print("Usage: ./100-my_calculator.py ") 9 | sys.exit(1) 10 | 11 | op = sys.argv[2] 12 | if op != '+' and op != '-' and op != '*' and op != '/': 13 | print("Unknown operator. Available operators: +, -, * and /") 14 | sys.exit(1) 15 | 16 | from calculator_1 import add, sub, mul, div 17 | a = int(sys.argv[1]) 18 | b = int(sys.argv[3]) 19 | 20 | if op == '+': 21 | print("{} + {} = {}".format(a, b, add(a, b))) 22 | elif op == '-': 23 | print("{} - {} = {}".format(a, b, sub(a, b))) 24 | elif op == '*': 25 | print("{} * {} = {}".format(a, b, mul(a, b))) 26 | else: 27 | print("{} / {} = {}".format(a, b, div(a, b))) 28 | -------------------------------------------------------------------------------- /0x02-python-import_modules/101-easy_print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | __import__("os").write(1, "#pythoniscool\n".encode("UTF-8")) 3 | -------------------------------------------------------------------------------- /0x02-python-import_modules/102-magic_calculation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | def magic_calculation(a, b): 4 | """Match bytecode provided by Holberton School""" 5 | from magic_calculation_102 import add, sub 6 | 7 | if a < b: 8 | c = add(a, b) 9 | for i in range(4, 6): 10 | c = add(c, i) 11 | return (c) 12 | else: 13 | return(sub(a, b)) 14 | -------------------------------------------------------------------------------- /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 | """Print the number of and list of arguments""" 4 | import sys 5 | 6 | count = len(sys.argv) - 1 7 | if count == 0: 8 | print("0 arguments.") 9 | elif count == 1: 10 | print("1 argument:") 11 | else: 12 | print("{} arguments:".format(count)) 13 | for i in range(count): 14 | print("{}: {}".format(i + 1, sys.argv[i + 1])) 15 | -------------------------------------------------------------------------------- /0x02-python-import_modules/3-infinite_add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | if __name__ == "__main__": 3 | """Print the addition of all arguments""" 4 | import sys 5 | 6 | total = 0 7 | for i in range(len(sys.argv) - 1): 8 | total += int(sys.argv[i + 1]) 9 | print("{}".format(total)) 10 | -------------------------------------------------------------------------------- /0x02-python-import_modules/4-hidden_discovery.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | if __name__ == "__main__": 4 | """Print all names defined by hidden_4 module""" 5 | import hidden_4 6 | 7 | names = dir(hidden_4) 8 | for name in names: 9 | if name[:2] != "__": 10 | print(name) 11 | -------------------------------------------------------------------------------- /0x02-python-import_modules/5-variable_load.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | if __name__ == "__main__": 4 | """Print the value of variable a from variable_load_5.""" 5 | from variable_load_5 import a 6 | 7 | print(a) 8 | -------------------------------------------------------------------------------- /0x02-python-import_modules/__pycache__/add_0.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x02-python-import_modules/__pycache__/add_0.cpython-39.pyc -------------------------------------------------------------------------------- /0x02-python-import_modules/__pycache__/calculator_1.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x02-python-import_modules/__pycache__/calculator_1.cpython-39.pyc -------------------------------------------------------------------------------- /0x02-python-import_modules/__pycache__/variable_load_5.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x02-python-import_modules/__pycache__/variable_load_5.cpython-39.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 | 14 | -------------------------------------------------------------------------------- /0x02-python-import_modules/calculator_1.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 | 14 | 15 | def sub(a, b): 16 | """My subtraction function 17 | 18 | Args: 19 | a: first integer 20 | b: second integer 21 | 22 | Returns: 23 | The return value. a - b 24 | """ 25 | return (a - b) 26 | 27 | 28 | def mul(a, b): 29 | """My multiplication function 30 | 31 | Args: 32 | a: first integer 33 | b: second integer 34 | 35 | Returns: 36 | The return value. a * b 37 | """ 38 | return (a * b) 39 | 40 | 41 | def div(a, b): 42 | """My division function 43 | 44 | Args: 45 | a: first integer 46 | b: second integer 47 | 48 | Returns: 49 | The return value. a / b 50 | """ 51 | return int(a / b) 52 | 53 | -------------------------------------------------------------------------------- /0x02-python-import_modules/hidden_4.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/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/.gitignore: -------------------------------------------------------------------------------- 1 | main.c 2 | linked_lists.c 3 | .vscode -------------------------------------------------------------------------------- /0x03-python-data_structures/0-print_list_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def print_list_integer(my_list=[]): 3 | """Prints all integers of a list""" 4 | for i in range(len(my_list)): 5 | print('{:d}'.format(my_list[i])) 6 | -------------------------------------------------------------------------------- /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 | 7 | return (my_list[idx]) 8 | -------------------------------------------------------------------------------- /0x03-python-data_structures/10-divisible_by_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def divisible_by_2(my_list=[]): 3 | """Finds all multiples of 2 in a list""" 4 | multiples = [] 5 | for i in range(len(my_list)): 6 | if my_list[i] % 2 == 0: 7 | multiples.append(True) 8 | else: 9 | multiples.append(False) 10 | 11 | return multiples 12 | -------------------------------------------------------------------------------- /0x03-python-data_structures/100-print_python_list_info.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * print_python_list_info - prints info about a python list 6 | * @p: PyObject 7 | * 8 | *Return: void 9 | */ 10 | 11 | void print_python_list_info(PyObject *p) 12 | { 13 | long int size, i; 14 | PyListObject *list; 15 | PyObject *item; 16 | 17 | size = Py_SIZE(p); 18 | printf("[*] Size of the Python List = %ld\n", size); 19 | 20 | list = (PyListObject *)p; 21 | printf("[*] Allocated = %ld\n", list->allocated); 22 | 23 | for (i = 0; i < size; i++) 24 | { 25 | item = PyList_GetItem(p, i); 26 | printf("Element %ld: %s\n", i, Py_TYPE(item)->tp_name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /0x03-python-data_structures/11-delete_at.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def delete_at(my_list=[], idx=0): 3 | """ deletes the item at a specific position in a list.""" 4 | if idx >= 0 and idx < len(my_list): 5 | del my_list[idx] 6 | return my_list 7 | -------------------------------------------------------------------------------- /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-replace_in_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def replace_in_list(my_list, idx, element): 3 | """Replace an element of a list at a specific position.""" 4 | if idx < 0 or idx > (len(my_list) - 1): 5 | return my_list 6 | 7 | my_list[idx] = element 8 | return my_list 9 | -------------------------------------------------------------------------------- /0x03-python-data_structures/3-print_reversed_list_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def print_reversed_list_integer(my_list=[]): 3 | """ prints all integers of a list, in reverse order.""" 4 | if not my_list: 5 | pass 6 | else: 7 | my_list.reverse() 8 | for i in range(len(my_list)): 9 | print('{:d}'.format(my_list[i])) 10 | -------------------------------------------------------------------------------- /0x03-python-data_structures/4-new_in_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def new_in_list(my_list, idx, element): 3 | """Replace an element at specific index without modifying the whole list""" 4 | if idx < 0 or idx > (len(my_list) - 1): 5 | return my_list 6 | 7 | copy = [x for x in my_list] 8 | copy[idx] = element 9 | return copy 10 | -------------------------------------------------------------------------------- /0x03-python-data_structures/5-no_c.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def no_c(my_string): 3 | """Function that removes all c and C characters from a string""" 4 | new_string = "" 5 | for i in range(len(my_string)): 6 | if my_string[i] != 'c' and my_string[i] != 'C': 7 | new_string += my_string[i] 8 | return new_string 9 | -------------------------------------------------------------------------------- /0x03-python-data_structures/6-print_matrix_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def print_matrix_integer(matrix=[[]]): 3 | """Function that prints a matrix of integers""" 4 | for i in range(len(matrix)): 5 | for j in range(len(matrix[i])): 6 | if j != 0: 7 | print(" ", end='') 8 | print("{:d}".format(matrix[i][j]), end='') 9 | print() 10 | -------------------------------------------------------------------------------- /0x03-python-data_structures/7-add_tuple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def add_tuple(tuple_a=(), tuple_b=()): 3 | tuple_a += (0, 0) 4 | tuple_b += (0, 0) 5 | return (tuple_a[0] + tuple_b[0], tuple_a[1] + tuple_b[1]) 6 | -------------------------------------------------------------------------------- /0x03-python-data_structures/8-multiple_returns.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def multiple_returns(sentence): 3 | if sentence == "": 4 | return (0, None) 5 | return (len(sentence), sentence[0]) 6 | -------------------------------------------------------------------------------- /0x03-python-data_structures/9-max_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def max_integer(my_list=[]): 3 | if len(my_list) == 0: 4 | return (None) 5 | 6 | big = my_list[0] 7 | for i in range(len(my_list)): 8 | if my_list[i] > big: 9 | big = my_list[i] 10 | return (big) 11 | -------------------------------------------------------------------------------- /0x03-python-data_structures/linked_lists.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "lists.h" 4 | 5 | /** 6 | * print_listint - prints all elements of a listint_t list 7 | * @h: pointer to head of list 8 | * Return: number of nodes 9 | */ 10 | size_t print_listint(const listint_t *h) 11 | { 12 | const listint_t *current; 13 | unsigned int n; /* number of nodes */ 14 | 15 | current = h; 16 | n = 0; 17 | while (current != NULL) 18 | { 19 | printf("%i\n", current->n); 20 | current = current->next; 21 | n++; 22 | } 23 | 24 | return (n); 25 | } 26 | 27 | /** 28 | * add_nodeint_end - adds a new node at the end of a listint_t list 29 | * @head: pointer to pointer of first node of listint_t list 30 | * @n: integer to be included in new node 31 | * Return: address of the new element or NULL if it fails 32 | */ 33 | listint_t *add_nodeint_end(listint_t **head, const int n) 34 | { 35 | listint_t *new; 36 | listint_t *current; 37 | 38 | current = *head; 39 | 40 | new = malloc(sizeof(listint_t)); 41 | if (new == NULL) 42 | return (NULL); 43 | 44 | new->n = n; 45 | new->next = NULL; 46 | 47 | if (*head == NULL) 48 | *head = new; 49 | else 50 | { 51 | while (current->next != NULL) 52 | current = current->next; 53 | current->next = new; 54 | } 55 | 56 | return (new); 57 | } 58 | 59 | /** 60 | * free_listint - frees a listint_t list 61 | * @head: pointer to list to be freed 62 | * Return: void 63 | */ 64 | void free_listint(listint_t *head) 65 | { 66 | listint_t *current; 67 | 68 | while (head != NULL) 69 | { 70 | current = head; 71 | head = head->next; 72 | free(current); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /0x03-python-data_structures/lists.h: -------------------------------------------------------------------------------- 1 | #ifndef LISTS_H 2 | #define LISTS_H 3 | #include 4 | #include 5 | /** 6 | * struct listint_s - singly linked list 7 | * @n: integer 8 | * @next: points to the next node 9 | * 10 | * Description: singly linked list node structure 11 | * for project 12 | */ 13 | typedef struct listint_s 14 | { 15 | int n; 16 | struct listint_s *next; 17 | } listint_t; 18 | 19 | size_t print_listint(const listint_t *h); 20 | listint_t *add_nodeint_end(listint_t **head, const int n); 21 | void free_listint(listint_t *head); 22 | 23 | int is_palindrome(listint_t **head); 24 | 25 | #endif /* LISTS_H */ 26 | -------------------------------------------------------------------------------- /0x03-python-data_structures/palindrome: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x03-python-data_structures/palindrome -------------------------------------------------------------------------------- /0x04-python-more_data_structures/.gitignore: -------------------------------------------------------------------------------- 1 | tests/ 2 | 3 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/0-square_matrix_simple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def square_matrix_simple(matrix=[]): 3 | """computes the square value of all integers of a matrix.""" 4 | if not matrix: 5 | return None 6 | 7 | return list(list(map(lambda a: a*a, num_list)) for num_list in matrix) 8 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/1-search_replace.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def search_replace(my_list, search, replace): 3 | if not my_list: 4 | return my_list 5 | return [val if val != search else replace for val in my_list] 6 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/10-best_score.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def best_score(a_dictionary): 3 | """returns a key with the biggest integer value.""" 4 | if not a_dictionary: 5 | return None 6 | return max(a_dictionary, key=a_dictionary.get) 7 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/100-weight_average.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def weight_average(my_list=[]): 3 | """ returns the weighted average""" 4 | """ of all integers tuple (, )""" 5 | if not my_list: 6 | return 0 7 | 8 | num = 0 9 | den = 0 10 | 11 | for tup in my_list: 12 | num += tup[0] * tup[1] 13 | den += tup[1] 14 | 15 | return (num / den) 16 | -------------------------------------------------------------------------------- /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 y: y**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 | list_keys = list(a_dictionary.keys()) 4 | 5 | for value_dic in list_keys: 6 | if value == a_dictionary.get(value_dic): 7 | del a_dictionary[value_dic] 8 | 9 | return (a_dictionary) 10 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/103-python.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x04-python-more_data_structures/103-python.c -------------------------------------------------------------------------------- /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-roman_to_int.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def roman_to_int(roman_string): 3 | """ converts a Roman numeral to an integer.""" 4 | romans = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} 5 | if (roman_string is None) or (type(roman_string) is not str): 6 | return 0 7 | 8 | number = len(roman_string) 9 | value_int = romans[roman_string[number-1]] 10 | for i in range(number - 1, 0, -1): 11 | current_value = romans[roman_string[i]] 12 | previous_value = romans[roman_string[i-1]] 13 | 14 | if previous_value >= current_value: 15 | value_int += previous_value 16 | else: 17 | value_int -= previous_value 18 | 19 | return value_int 20 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/2-uniq_add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def uniq_add(my_list=[]): 3 | """adds all unique integers in a list (only once for each integer).""" 4 | sum = 0 5 | for i in set(my_list): 6 | sum += i 7 | return sum 8 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/3-common_elements.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def common_elements(set_1, set_2): 3 | """returns a set of common elements in two sets.""" 4 | return (set_1 & set_2) 5 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/4-only_diff_elements.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def only_diff_elements(set_1, set_2): 3 | """returns a set of all elements present in only one set.""" 4 | return (set_1 ^ set_2) 5 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/5-number_keys.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def number_keys(a_dictionary): 3 | """returns the number of keys in a dictionary.""" 4 | return len(a_dictionary.keys()) 5 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/6-print_sorted_dictionary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def print_sorted_dictionary(a_dictionary): 3 | """prints a dictionary by ordered keys.""" 4 | for key in sorted(a_dictionary.keys()): 5 | print("{}: {}".format(key, a_dictionary[key])) 6 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/7-update_dictionary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def update_dictionary(a_dictionary, key, value): 3 | """ replaces or adds key/value in a dictionary.""" 4 | a_dictionary[key] = value 5 | return a_dictionary 6 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/8-simple_delete.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def simple_delete(a_dictionary, key=""): 3 | """deletes a key in a dictionary.""" 4 | if key in a_dictionary: 5 | del a_dictionary[key] 6 | return a_dictionary 7 | -------------------------------------------------------------------------------- /0x04-python-more_data_structures/9-multiply_by_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def multiply_by_2(a_dictionary): 3 | """returns a new dictionary with""" 4 | """all values multiplied by 2""" 5 | new_dict = {x: (a_dictionary[x] * 2) for x in a_dictionary} 6 | return new_dict 7 | -------------------------------------------------------------------------------- /0x05-python-exceptions/.gitignore: -------------------------------------------------------------------------------- 1 | tests/ -------------------------------------------------------------------------------- /0x05-python-exceptions/0-safe_print_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def safe_print_list(my_list=[], x=0): 3 | counter = 0 4 | for i in range(x): 5 | try: 6 | print("{}".format(my_list[i]), end="") 7 | except IndexError: 8 | break 9 | else: 10 | counter += 1 11 | print() 12 | return counter 13 | -------------------------------------------------------------------------------- /0x05-python-exceptions/1-safe_print_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def safe_print_integer(value): 3 | try: 4 | print("{:d}".format(value)) 5 | return True 6 | except (ValueError, TypeError): 7 | return False 8 | -------------------------------------------------------------------------------- /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 | except Exception as i: 7 | sys.stderr.write("Exception: {}\n".format(i)) 8 | return (False) 9 | else: 10 | return (True) 11 | -------------------------------------------------------------------------------- /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 | except Exception as i: 7 | sys.stderr.write("Exception: {}\n".format(i)) 8 | result = None 9 | return (result) 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: 11 | result = b + a 12 | break 13 | return (result) 14 | -------------------------------------------------------------------------------- /0x05-python-exceptions/2-safe_print_list_integers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def safe_print_list_integers(my_list=[], x=0): 3 | counter = 0 4 | for i in range(x): 5 | try: 6 | print("{:d}".format(my_list[i]), end="") 7 | except (ValueError, TypeError): 8 | pass 9 | else: 10 | counter += 1 11 | print() 12 | return (counter) 13 | -------------------------------------------------------------------------------- /0x05-python-exceptions/3-safe_print_division.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def safe_print_division(a, b): 3 | try: 4 | result = a/b 5 | except: 6 | result = None 7 | finally: 8 | print("Inside result: {}".format(result)) 9 | return (result) 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 | for i in range(list_length): 5 | try: 6 | result = my_list_1[i] / my_list_2[i] 7 | except (TypeError): 8 | print("wrong type") 9 | result = 0 10 | except (ZeroDivisionError): 11 | print("division by 0") 12 | result = 0 13 | except (IndexError): 14 | print("out of range") 15 | result = 0 16 | finally: 17 | new_list.append(result) 18 | return (new_list) 19 | -------------------------------------------------------------------------------- /0x05-python-exceptions/5-raise_exception.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def raise_exception(): 3 | raise TypeError 4 | -------------------------------------------------------------------------------- /0x05-python-exceptions/6-raise_exception_msg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | def raise_exception_msg(message=""): 3 | raise NameError(message) 4 | -------------------------------------------------------------------------------- /0x06-python-classes/0-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Square class to represent a square""" 3 | 4 | 5 | class Square(): 6 | """Empty class""" 7 | pass 8 | -------------------------------------------------------------------------------- /0x06-python-classes/1-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Working on oop with python """ 3 | 4 | 5 | class Square(): 6 | """Class representing a square""" 7 | 8 | def __init__(self, size): 9 | """ initialize the class 10 | 11 | Args: 12 | size (int): size of the square 13 | """ 14 | self.__size = size 15 | -------------------------------------------------------------------------------- /0x06-python-classes/101-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Define a class Square.""" 3 | 4 | 5 | class Square: 6 | """Represent a square.""" 7 | 8 | def __init__(self, size=0, position=(0, 0)): 9 | """Initialize a new square. 10 | 11 | Args: 12 | size (int): The size of the new square. 13 | position (int, int): The position of the new square. 14 | """ 15 | self.size = size 16 | self.position = position 17 | 18 | @property 19 | def size(self): 20 | """Get/set the current size of the square.""" 21 | return (self.__size) 22 | 23 | @size.setter 24 | def size(self, value): 25 | if not isinstance(value, int): 26 | raise TypeError("size must be an integer") 27 | elif value < 0: 28 | raise ValueError("size must be >= 0") 29 | self.__size = value 30 | 31 | @property 32 | def position(self): 33 | """Get/set the current position of the square.""" 34 | return (self.__position) 35 | 36 | @position.setter 37 | def position(self, value): 38 | if (not isinstance(value, tuple) or 39 | len(value) != 2 or 40 | not all(isinstance(num, int) for num in value) or 41 | not all(num >= 0 for num in value)): 42 | raise TypeError("position must be a tuple of 2 positive integers") 43 | self.__position = value 44 | 45 | def area(self): 46 | """Return the current area of the square.""" 47 | return (self.__size * self.__size) 48 | 49 | def my_print(self): 50 | """Print the square with the # character.""" 51 | if self.__size == 0: 52 | print("") 53 | return 54 | 55 | [print("") for i in range(0, self.__position[1])] 56 | for i in range(0, self.__size): 57 | [print(" ", end="") for j in range(0, self.__position[0])] 58 | [print("#", end="") for k in range(0, self.__size)] 59 | print("") 60 | 61 | def __str__(self): 62 | """Define the print() representation of a Square.""" 63 | if self.__size != 0: 64 | [print("") for i in range(0, self.__position[1])] 65 | for i in range(0, self.__size): 66 | [print(" ", end="") for j in range(0, self.__position[0])] 67 | [print("#", end="") for k in range(0, self.__size)] 68 | if i != self.__size - 1: 69 | print("") 70 | return ("") 71 | -------------------------------------------------------------------------------- /0x06-python-classes/102-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Define a class Square.""" 3 | 4 | 5 | class Square: 6 | """Represent a square.""" 7 | 8 | def __init__(self, size=0): 9 | """Initialize a new square. 10 | 11 | Args: 12 | size (int): The size of the new square. 13 | """ 14 | self.size = size 15 | 16 | @property 17 | def size(self): 18 | """Get/set the current size of the square.""" 19 | return (self.__size) 20 | 21 | @size.setter 22 | def size(self, value): 23 | if not isinstance(value, int): 24 | raise TypeError("size must be an integer") 25 | elif value < 0: 26 | raise ValueError("size must be >= 0") 27 | self.__size = value 28 | 29 | def area(self): 30 | """Return the current area of the square.""" 31 | return (self.__size * self.__size) 32 | 33 | def __eq__(self, other): 34 | """Define the == comparision to a Square.""" 35 | return self.area() == other.area() 36 | 37 | def __ne__(self, other): 38 | """Define the != comparison to a Square.""" 39 | return self.area() != other.area() 40 | 41 | def __lt__(self, other): 42 | """Define the < comparison to a Square.""" 43 | return self.area() < other.area() 44 | 45 | def __le__(self, other): 46 | """Define the <= comparison to a Square.""" 47 | return self.area() <= other.area() 48 | 49 | def __gt__(self, other): 50 | """Define the > comparison to a Square.""" 51 | return self.area() > other.area() 52 | 53 | def __ge__(self, other): 54 | """Define the >= compmarison to a Square.""" 55 | return self.area() >= other.area() 56 | -------------------------------------------------------------------------------- /0x06-python-classes/103-magic_class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Define a MagicClass matching exactly a bytecode provided by Holberton.""" 4 | 5 | import math 6 | 7 | 8 | class MagicClass: 9 | """Represent a circle.""" 10 | 11 | def __init__(self, radius=0): 12 | """Initialize a MagicClass. 13 | 14 | Arg: 15 | radius (float or int): The radius of the new MagicClass. 16 | """ 17 | self.__radius = 0 18 | if type(radius) is not int and type(radius) is not float: 19 | raise TypeError("radius must be a number") 20 | self.__radius = radius 21 | 22 | def area(self): 23 | """Return the area of the MagicClass.""" 24 | return (self.__radius ** 2 * math.pi) 25 | 26 | def circumference(self): 27 | """Return The circumference of the MagicClass.""" 28 | return (2 * math.pi * self.__radius) 29 | -------------------------------------------------------------------------------- /0x06-python-classes/2-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class Square that defines a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0): 9 | if (type(size) is not int): 10 | raise TypeError("size must be an integer") 11 | elif (size < 0): 12 | raise ValueError("size must be >= 0") 13 | self.__size = size 14 | -------------------------------------------------------------------------------- /0x06-python-classes/3-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class Square that defines a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0): 9 | if (type(size) is not int): 10 | raise TypeError("size must be an integer") 11 | elif (size < 0): 12 | raise ValueError("size must be >= 0") 13 | self.__size = size 14 | 15 | def area(self): 16 | return self.__size ** 2 17 | -------------------------------------------------------------------------------- /0x06-python-classes/4-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class Square that defines a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0): 9 | self.__size = size 10 | 11 | @property 12 | def size(self): 13 | return self.__size 14 | 15 | @size.setter 16 | def size(self, value): 17 | if (type(value) is not int): 18 | raise TypeError("size must be an integer") 19 | elif (value < 0): 20 | raise ValueError("size must be >= 0") 21 | self.__size = value 22 | 23 | def area(self): 24 | return self.__size ** 2 25 | -------------------------------------------------------------------------------- /0x06-python-classes/5-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class Square that defines a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0): 9 | self.__size = size 10 | 11 | @property 12 | def size(self): 13 | return self.__size 14 | 15 | @size.setter 16 | def size(self, value): 17 | if (type(value) is not int): 18 | raise TypeError("size must be an integer") 19 | elif (value < 0): 20 | raise ValueError("size must be >= 0") 21 | self.__size = value 22 | 23 | def area(self): 24 | return self.__size ** 2 25 | 26 | def my_print(self): 27 | if not self.__size: 28 | print("") 29 | for i in range(self.__size): 30 | print("#" * self.__size) 31 | -------------------------------------------------------------------------------- /0x06-python-classes/6-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Square class to represent a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0, position=(0, 0)): 9 | """"Initialize data""" 10 | self.size = size 11 | self.position = position 12 | 13 | @property 14 | def size(self): 15 | """"get size""" 16 | return self.__size 17 | 18 | @property 19 | def position(self): 20 | """"get position""" 21 | return self.__position 22 | 23 | @size.setter 24 | def size(self, value): 25 | """"set size""" 26 | if (type(value) is not int): 27 | raise TypeError("size must be an integer") 28 | elif (value < 0): 29 | raise ValueError("size must be >= 0") 30 | else: 31 | self.__size = value 32 | 33 | @position.setter 34 | def position(self, value): 35 | """"set position""" 36 | if (type(value) is not tuple): 37 | raise TypeError("position must be a tuple of 2 positive integers") 38 | elif (len(value) != 2): 39 | raise TypeError("position must be a tuple of 2 positive integers") 40 | elif (type(value[0]) is not int) or (type(value[1]) is not int): 41 | raise TypeError("position must be a tuple of 2 positive integers") 42 | elif (value[0] < 0) or (value[1] < 0): 43 | raise TypeError("position must be a tuple of 2 positive integers") 44 | else: 45 | self.__position = value 46 | 47 | def area(self): 48 | """"get area of the square""" 49 | return self.size ** 2 50 | 51 | def my_print(self): 52 | """print the square""" 53 | if self.size == 0: 54 | print() 55 | else: 56 | for i in range(self.position[1]): 57 | print("") 58 | for i in range(self.size): 59 | print(" " * self.position[0], end="") 60 | print("#" * self.size) 61 | -------------------------------------------------------------------------------- /0x06-python-classes/tests/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__) -------------------------------------------------------------------------------- /0x06-python-classes/tests/0-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | class Square: 3 | pass 4 | -------------------------------------------------------------------------------- /0x06-python-classes/tests/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) -------------------------------------------------------------------------------- /0x06-python-classes/tests/1-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Working on oop with python """ 3 | 4 | 5 | class Square(): 6 | """Class representing a square""" 7 | 8 | def __init__(self, size): 9 | """ initialize the class 10 | 11 | Args: 12 | size (int): size of the square 13 | """ 14 | self.__size = size 15 | -------------------------------------------------------------------------------- /0x06-python-classes/tests/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Square = __import__('2-square').Square 3 | 4 | my_square_1 = Square(3) 5 | print(type(my_square_1)) 6 | print(my_square_1.__dict__) 7 | 8 | my_square_2 = Square() 9 | print(type(my_square_2)) 10 | print(my_square_2.__dict__) 11 | 12 | try: 13 | print(my_square_1.size) 14 | except Exception as e: 15 | print(e) 16 | 17 | try: 18 | print(my_square_1.__size) 19 | except Exception as e: 20 | print(e) 21 | 22 | try: 23 | my_square_3 = Square("3") 24 | print(type(my_square_3)) 25 | print(my_square_3.__dict__) 26 | except Exception as e: 27 | print(e) 28 | 29 | try: 30 | my_square_4 = Square(-89) 31 | print(type(my_square_4)) 32 | print(my_square_4.__dict__) 33 | except Exception as e: 34 | print(e) -------------------------------------------------------------------------------- /0x06-python-classes/tests/2-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class Square that defines a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0): 9 | if (type(size) is not int): 10 | raise TypeError("size must be an integer") 11 | elif (size < 0): 12 | raise ValueError("size must be >= 0") 13 | self.__size = size 14 | -------------------------------------------------------------------------------- /0x06-python-classes/tests/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/tests/3-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class Square that defines a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0): 9 | if (type(size) is not int): 10 | raise TypeError("size must be an integer") 11 | elif (size < 0): 12 | raise ValueError("size must be >= 0") 13 | self.__size = size 14 | 15 | def area(self): 16 | return self.__size ** 2 17 | -------------------------------------------------------------------------------- /0x06-python-classes/tests/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) -------------------------------------------------------------------------------- /0x06-python-classes/tests/4-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class Square that defines a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0): 9 | self.__size = size 10 | 11 | @property 12 | def size(self): 13 | return self.__size 14 | 15 | @size.setter 16 | def size(self, value): 17 | if (type(value) is not int): 18 | raise TypeError("size must be an integer") 19 | elif (value < 0): 20 | raise ValueError("size must be >= 0") 21 | self.__size = value 22 | 23 | def area(self): 24 | return self.__size ** 2 25 | -------------------------------------------------------------------------------- /0x06-python-classes/tests/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("--") -------------------------------------------------------------------------------- /0x06-python-classes/tests/5-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """class Square that defines a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0): 9 | self.__size = size 10 | 11 | @property 12 | def size(self): 13 | return self.__size 14 | 15 | @size.setter 16 | def size(self, value): 17 | if (type(value) is not int): 18 | raise TypeError("size must be an integer") 19 | elif (value < 0): 20 | raise ValueError("size must be >= 0") 21 | self.__size = value 22 | 23 | def area(self): 24 | return self.__size ** 2 25 | 26 | def my_print(self): 27 | if not self.__size: 28 | print("") 29 | for i in range(self.__size): 30 | print("#" * self.__size) 31 | -------------------------------------------------------------------------------- /0x06-python-classes/tests/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("--") -------------------------------------------------------------------------------- /0x06-python-classes/tests/6-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Square class to represent a square""" 3 | 4 | 5 | class Square(): 6 | """square class with it's size and proper validation""" 7 | 8 | def __init__(self, size=0, position=(0, 0)): 9 | """"Initialize data""" 10 | self.size = size 11 | self.position = position 12 | 13 | @property 14 | def size(self): 15 | """"get size""" 16 | return self.__size 17 | 18 | @property 19 | def position(self): 20 | """"get position""" 21 | return self.__position 22 | 23 | @size.setter 24 | def size(self, value): 25 | """"set size""" 26 | if (type(value) is not int): 27 | raise TypeError("size must be an integer") 28 | elif (value < 0): 29 | raise ValueError("size must be >= 0") 30 | else: 31 | self.__size = value 32 | 33 | @position.setter 34 | def position(self, value): 35 | """"set position""" 36 | if (type(value) is not tuple): 37 | raise TypeError("position must be a tuple of 2 positive integers") 38 | elif (len(value) != 2): 39 | raise TypeError("position must be a tuple of 2 positive integers") 40 | elif (type(value[0]) is not int) or (type(value[1]) is not int): 41 | raise TypeError("position must be a tuple of 2 positive integers") 42 | elif (value[0] < 0) or (value[1] < 0): 43 | raise TypeError("position must be a tuple of 2 positive integers") 44 | else: 45 | self.__position = value 46 | 47 | def area(self): 48 | """"get area of the square""" 49 | return self.size ** 2 50 | 51 | def my_print(self): 52 | """print the square""" 53 | if self.size == 0: 54 | print() 55 | else: 56 | for i in range(self.position[1]): 57 | print("") 58 | for i in range(self.size): 59 | print(" " * self.position[0], end="") 60 | print("#" * self.size) 61 | -------------------------------------------------------------------------------- /0x06-python-classes/tests/__pycache__/0-square.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x06-python-classes/tests/__pycache__/0-square.cpython-39.pyc -------------------------------------------------------------------------------- /0x06-python-classes/tests/__pycache__/1-square.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x06-python-classes/tests/__pycache__/1-square.cpython-39.pyc -------------------------------------------------------------------------------- /0x06-python-classes/tests/__pycache__/2-square.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x06-python-classes/tests/__pycache__/2-square.cpython-39.pyc -------------------------------------------------------------------------------- /0x06-python-classes/tests/__pycache__/3-square.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x06-python-classes/tests/__pycache__/3-square.cpython-39.pyc -------------------------------------------------------------------------------- /0x06-python-classes/tests/__pycache__/4-square.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x06-python-classes/tests/__pycache__/4-square.cpython-39.pyc -------------------------------------------------------------------------------- /0x06-python-classes/tests/__pycache__/5-square.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x06-python-classes/tests/__pycache__/5-square.cpython-39.pyc -------------------------------------------------------------------------------- /0x06-python-classes/tests/__pycache__/6-square.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x06-python-classes/tests/__pycache__/6-square.cpython-39.pyc -------------------------------------------------------------------------------- /0x07-python-test_driven_development/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | tests/*-main.py 3 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/0-add_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Module containing a dummy adder function for testing""" 3 | 4 | 5 | def add_integer(a, b=98): 6 | """ adds integers 7 | Arguments: 8 | @a: first integer 9 | @b: second integer, defaults to 98 if not given 10 | """ 11 | 12 | if type(a) not in [int, float]: 13 | raise TypeError("a must be an integer") 14 | if type(b) not in [int, float]: 15 | raise TypeError("b must be an integer") 16 | return int(a) + int(b) 17 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/101-lazy_matrix_mul.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a matrix multiplication function using NumPy.""" 3 | import numpy as np 4 | 5 | 6 | def lazy_matrix_mul(m_a, m_b): 7 | """Return the multiplication of two matrices. 8 | 9 | Args: 10 | m_a (list of lists of ints/floats): The first matrix. 11 | m_b (list of lists of ints/floats): The second matrix. 12 | """ 13 | 14 | return (np.matmul(m_a, m_b)) 15 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/102-python.c: -------------------------------------------------------------------------------- 1 | #include "Python.h" 2 | 3 | /** 4 | * print_python_string - Prints information about Python strings. 5 | * @p: A PyObject string object. 6 | */ 7 | void print_python_string(PyObject *p) 8 | { 9 | long int length; 10 | 11 | fflush(stdout); 12 | 13 | printf("[.] string object info\n"); 14 | if (strcmp(p->ob_type->tp_name, "str") != 0) 15 | { 16 | printf(" [ERROR] Invalid String Object\n"); 17 | return; 18 | } 19 | 20 | length = ((PyASCIIObject *)(p))->length; 21 | 22 | if (PyUnicode_IS_COMPACT_ASCII(p)) 23 | printf(" type: compact ascii\n"); 24 | else 25 | printf(" type: compact unicode object\n"); 26 | printf(" length: %ld\n", length); 27 | printf(" value: %ls\n", PyUnicode_AsWideCharString(p, &length)); 28 | } 29 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/2-matrix_divided.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a matrix division function.""" 4 | 5 | 6 | def matrix_divided(matrix, div): 7 | """Divide all elements of a matrix. 8 | 9 | Args: 10 | matrix (list): A list of lists of ints or floats. 11 | div (int/float): The divisor. 12 | Raises: 13 | TypeError: If the matrix contains non-numbers. 14 | TypeError: If the matrix contains rows of different sizes. 15 | TypeError: If div is not an int or float. 16 | ZeroDivisionError: If div is 0. 17 | Returns: 18 | A new matrix representing the result of the division. 19 | """ 20 | if (not isinstance(matrix, list) or matrix == [] or 21 | not all(isinstance(row, list) for row in matrix) or 22 | not all((isinstance(ele, int) or isinstance(ele, float)) 23 | for ele in [num for row in matrix for num in row])): 24 | raise TypeError("matrix must be a matrix (list of lists) of " 25 | "integers/floats") 26 | 27 | if not all(len(row) == len(matrix[0]) for row in matrix): 28 | raise TypeError("Each row of the matrix must have the same size") 29 | 30 | if not isinstance(div, int) and not isinstance(div, float): 31 | raise TypeError("div must be a number") 32 | 33 | if div == 0: 34 | raise ZeroDivisionError("division by zero") 35 | 36 | return ([list(map(lambda x: round(x / div, 2), row)) for row in matrix]) 37 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/3-say_my_name.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Module containing a function to print first and last name""" 3 | 4 | 5 | def say_my_name(first_name, last_name=""): 6 | """ prints first and last name 7 | Arguments: 8 | @first_name: first name to be printed 9 | @second_name: last_name to be printed 10 | """ 11 | 12 | if type(first_name) is not str: 13 | raise TypeError("first_name must be a string") 14 | if type(last_name) is not str: 15 | raise TypeError("last_name must be a string") 16 | print("My name is {} {}".format(first_name, last_name)) 17 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/4-print_square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Module containing a function that prints a square""" 3 | 4 | 5 | def print_square(size): 6 | """ adds integers 7 | Arguments: 8 | @size: size of the square 9 | """ 10 | 11 | if type(size) is not int: 12 | raise TypeError("size must be an integer") 13 | if (size < 0): 14 | raise ValueError("size must be >= 0") 15 | if size == 0: 16 | return 17 | for i in range(size): 18 | for j in range(size): 19 | print("#", end="") 20 | print() 21 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/5-text_indentation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a text-indentation function.""" 4 | 5 | 6 | def text_indentation(text): 7 | """Print text with two new lines after each '.', '?', and ':'. 8 | 9 | Args: 10 | text (string): The text to print. 11 | Raises: 12 | TypeError: If text is not a string. 13 | """ 14 | if not isinstance(text, str): 15 | raise TypeError("text must be a string") 16 | 17 | c = 0 18 | while c < len(text) and text[c] == ' ': 19 | c += 1 20 | 21 | while c < len(text): 22 | print(text[c], end="") 23 | if text[c] == "\n" or text[c] in ".?:": 24 | if text[c] in ".?:": 25 | print("\n") 26 | c += 1 27 | while c < len(text) and text[c] == ' ': 28 | c += 1 29 | continue 30 | c += 1 31 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/tests/0-add_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Module containing a dummy adder function for testing""" 3 | 4 | 5 | def add_integer(a, b=98): 6 | """ adds integers 7 | Arguments: 8 | @a: first integer 9 | @b: second integer, defaults to 98 if not given 10 | """ 11 | 12 | if type(a) not in [int, float]: 13 | raise TypeError("a must be an integer") 14 | if type(b) not in [int, float]: 15 | raise TypeError("b must be an integer") 16 | return int(a) + int(b) 17 | 18 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/tests/3-say_my_name.txt: -------------------------------------------------------------------------------- 1 | >>> say_my_name = __import__("3-say_my_name").say_my_name 2 | >>> say_my_name("abebe", "beso") 3 | My name is abebe beso 4 | >>> say_my_name("chala") 5 | My name is chala 6 | >>> say_my_name(5) 7 | Traceback (most recent call last): 8 | ... 9 | TypeError: first_name must be a string 10 | >>> say_my_name("chala", 30) 11 | Traceback (most recent call last): 12 | ... 13 | TypeError: last_name must be a string 14 | >>> say_my_name(50, 30) 15 | Traceback (most recent call last): 16 | ... 17 | TypeError: first_name must be a string 18 | >>> say_my_name("", "jo") 19 | My name is jo 20 | >>> say_my_name() 21 | Traceback (most recent call last): 22 | ... 23 | TypeError: say_my_name() missing 1 required positional argument: 'first_name' 24 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/tests/4-print_square.txt: -------------------------------------------------------------------------------- 1 | >>> print_square = __import__("4-print_square").print_square 2 | >>> print_square(4) 3 | #### 4 | #### 5 | #### 6 | #### 7 | >>> print_square(2.0) 8 | Traceback (most recent call last): 9 | ... 10 | TypeError: size must be an integer 11 | >>> print_square(-5) 12 | Traceback (most recent call last): 13 | ... 14 | ValueError: size must be >= 0 15 | >>> print_square(0) 16 | >>> print_square(1) 17 | # 18 | >>> print_square() 19 | Traceback (most recent call last): 20 | ... 21 | TypeError: print_square() missing 1 required positional argument: 'size' 22 | -------------------------------------------------------------------------------- /0x07-python-test_driven_development/tests/6-max_integer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Module to find the max integer in a list 3 | """ 4 | 5 | def max_integer(list=[]): 6 | """Function to find and return the max integer in a list of integers 7 | If the list is empty, the function returns None 8 | """ 9 | if len(list) == 0: 10 | return None 11 | result = list[0] 12 | i = 1 13 | while i < len(list): 14 | if list[i] > result: 15 | result = list[i] 16 | i += 1 17 | return result -------------------------------------------------------------------------------- /0x07-python-test_driven_development/tests/6-max_integer_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Unittests for max_integer([..]).""" 4 | 5 | import unittest 6 | max_integer = __import__('6-max_integer').max_integer 7 | 8 | 9 | class TestMaxInteger(unittest.TestCase): 10 | """Define unittests for max_integer([..]).""" 11 | 12 | def test_ordered_list(self): 13 | """Test an ordered list of integers.""" 14 | ordered = [1, 2, 3, 4] 15 | self.assertEqual(max_integer(ordered), 4) 16 | 17 | def test_unordered_list(self): 18 | """Test an unordered list of integers.""" 19 | unordered = [1, 2, 4, 3] 20 | self.assertEqual(max_integer(unordered), 4) 21 | 22 | def test_max_at_begginning(self): 23 | """Test a list with a beginning max value.""" 24 | max_at_beginning = [4, 3, 2, 1] 25 | self.assertEqual(max_integer(max_at_beginning), 4) 26 | 27 | def test_empty_list(self): 28 | """Test an empty list.""" 29 | empty = [] 30 | self.assertEqual(max_integer(empty), None) 31 | 32 | def test_one_element_list(self): 33 | """Test a list with a single element.""" 34 | one_element = [7] 35 | self.assertEqual(max_integer(one_element), 7) 36 | 37 | def test_floats(self): 38 | """Test a list of floats.""" 39 | floats = [1.53, 6.33, -9.123, 15.2, 6.0] 40 | self.assertEqual(max_integer(floats), 15.2) 41 | 42 | def test_ints_and_floats(self): 43 | """Test a list of ints and floats.""" 44 | ints_and_floats = [1.53, 15.5, -9, 15, 6] 45 | self.assertEqual(max_integer(ints_and_floats), 15.5) 46 | 47 | def test_string(self): 48 | """Test a string.""" 49 | string = "Brennan" 50 | self.assertEqual(max_integer(string), 'r') 51 | 52 | def test_list_of_strings(self): 53 | """Test a list of strings.""" 54 | strings = ["Brennan", "is", "my", "name"] 55 | self.assertEqual(max_integer(strings), "name") 56 | 57 | def test_empty_string(self): 58 | """Test an empty string.""" 59 | self.assertEqual(max_integer(""), None) 60 | 61 | if __name__ == '__main__': 62 | unittest.main() 63 | -------------------------------------------------------------------------------- /0x07-test_driven_development/__pycache__/3-say_my_name.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x07-test_driven_development/__pycache__/3-say_my_name.cpython-39.pyc -------------------------------------------------------------------------------- /0x07-test_driven_development/__pycache__/4-print_square.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x07-test_driven_development/__pycache__/4-print_square.cpython-39.pyc -------------------------------------------------------------------------------- /0x07-test_driven_development/__pycache__/5-text_indentation.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x07-test_driven_development/__pycache__/5-text_indentation.cpython-39.pyc -------------------------------------------------------------------------------- /0x07-test_driven_development/tests/__pycache__/0-add_integer.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x07-test_driven_development/tests/__pycache__/0-add_integer.cpython-39.pyc -------------------------------------------------------------------------------- /0x08-python-more_classes/0-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a Rectangle class.""" 4 | 5 | 6 | class Rectangle: 7 | """Represent a rectangle.""" 8 | pass 9 | -------------------------------------------------------------------------------- /0x08-python-more_classes/1-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a Rectangle class.""" 4 | 5 | 6 | class Rectangle: 7 | """Represent a rectangle.""" 8 | 9 | def __init__(self, width=0, height=0): 10 | """Initialize a new Rectangle. 11 | 12 | Args: 13 | width (int): The width of the new rectangle. 14 | height (int): The height of the new rectangle. 15 | """ 16 | self.width = width 17 | self.height = height 18 | 19 | @property 20 | def width(self): 21 | """Get/set the width of the rectangle.""" 22 | return self.__width 23 | 24 | @width.setter 25 | def width(self, value): 26 | if not isinstance(value, int): 27 | raise TypeError("width must be an integer") 28 | if value < 0: 29 | raise ValueError("width must be >= 0") 30 | self.__width = value 31 | 32 | @property 33 | def height(self): 34 | """Get/set the height of the rectangle.""" 35 | return self.__height 36 | 37 | @height.setter 38 | def height(self, value): 39 | if not isinstance(value, int): 40 | raise TypeError("height must be an integer") 41 | if value < 0: 42 | raise ValueError("height must be >= 0") 43 | self.__height = value 44 | -------------------------------------------------------------------------------- /0x08-python-more_classes/2-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a Rectangle class.""" 3 | 4 | 5 | class Rectangle: 6 | """Represent a rectangle.""" 7 | 8 | def __init__(self, width=0, height=0): 9 | """Initialize a new Rectangle. 10 | 11 | Args: 12 | width (int): The width of the new rectangle. 13 | height (int): The height of the new rectangle. 14 | """ 15 | self.width = width 16 | self.height = height 17 | 18 | @property 19 | def width(self): 20 | """Get/set the width of the Rectangle.""" 21 | return self.__width 22 | 23 | @width.setter 24 | def width(self, value): 25 | if not isinstance(value, int): 26 | raise TypeError("width must be an integer") 27 | if value < 0: 28 | raise ValueError("width must be >= 0") 29 | self.__width = value 30 | 31 | @property 32 | def height(self): 33 | """Get/set the height of the Rectangle.""" 34 | return self.__height 35 | 36 | @height.setter 37 | def height(self, value): 38 | if not isinstance(value, int): 39 | raise TypeError("height must be an integer") 40 | if value < 0: 41 | raise ValueError("height must be >= 0") 42 | self.__height = value 43 | 44 | def area(self): 45 | """Return the area of the Rectangle.""" 46 | return (self.__width * self.__height) 47 | 48 | def perimeter(self): 49 | """Return the perimeter of the Rectangle.""" 50 | if self.__width == 0 or self.__height == 0: 51 | return (0) 52 | return ((self.__width * 2) + (self.__height * 2)) 53 | -------------------------------------------------------------------------------- /0x08-python-more_classes/3-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a Rectangle class.""" 3 | 4 | 5 | class Rectangle: 6 | """Represent a rectangle.""" 7 | 8 | def __init__(self, width=0, height=0): 9 | """Initialize a new Rectangle. 10 | 11 | Args: 12 | width (int): The width of the new rectangle. 13 | height (int): The height of the new rectangle. 14 | """ 15 | self.width = width 16 | self.height = height 17 | 18 | @property 19 | def width(self): 20 | """Get/set the width of the Rectangle.""" 21 | return self.__width 22 | 23 | @width.setter 24 | def width(self, value): 25 | if not isinstance(value, int): 26 | raise TypeError("width must be an integer") 27 | if value < 0: 28 | raise ValueError("width must be >= 0") 29 | self.__width = value 30 | 31 | @property 32 | def height(self): 33 | """Get/set the height of the Rectangle.""" 34 | return self.__height 35 | 36 | @height.setter 37 | def height(self, value): 38 | if not isinstance(value, int): 39 | raise TypeError("height must be an integer") 40 | if value < 0: 41 | raise ValueError("height must be >= 0") 42 | self.__height = value 43 | 44 | def area(self): 45 | """Return the area of the Rectangle.""" 46 | return (self.__width * self.__height) 47 | 48 | def perimeter(self): 49 | """Return the perimeter of the Rectangle.""" 50 | if self.__width == 0 or self.__height == 0: 51 | return (0) 52 | return ((self.__width * 2) + (self.__height * 2)) 53 | 54 | def __str__(self): 55 | """Return the printable representation of the Rectangle. 56 | 57 | Represents the rectangle with the # character. 58 | """ 59 | if self.__width == 0 or self.__height == 0: 60 | return ("") 61 | 62 | rect = [] 63 | for i in range(self.__height): 64 | [rect.append('#') for j in range(self.__width)] 65 | if i != self.__height - 1: 66 | rect.append("\n") 67 | return ("".join(rect)) 68 | -------------------------------------------------------------------------------- /0x08-python-more_classes/4-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a Rectangle class.""" 3 | 4 | 5 | class Rectangle: 6 | """Represent a rectangle.""" 7 | 8 | def __init__(self, width=0, height=0): 9 | """Initialize a new Rectangle. 10 | 11 | Args: 12 | width (int): The width of the new rectangle. 13 | height (int): The height of the new rectangle. 14 | """ 15 | self.width = width 16 | self.height = height 17 | 18 | @property 19 | def width(self): 20 | """Get/set the width of the Rectangle.""" 21 | return self.__width 22 | 23 | @width.setter 24 | def width(self, value): 25 | if not isinstance(value, int): 26 | raise TypeError("width must be an integer") 27 | if value < 0: 28 | raise ValueError("width must be >= 0") 29 | self.__width = value 30 | 31 | @property 32 | def height(self): 33 | """Get/set the height of the Rectangle.""" 34 | return self.__height 35 | 36 | @height.setter 37 | def height(self, value): 38 | if not isinstance(value, int): 39 | raise TypeError("height must be an integer") 40 | if value < 0: 41 | raise ValueError("height must be >= 0") 42 | self.__height = value 43 | 44 | def area(self): 45 | """Return the area of the Rectangle.""" 46 | return (self.__width * self.__height) 47 | 48 | def perimeter(self): 49 | """Return the perimeter of the Rectangle.""" 50 | if self.__width == 0 or self.__height == 0: 51 | return (0) 52 | return ((self.__width * 2) + (self.__height * 2)) 53 | 54 | def __str__(self): 55 | """Return the printable representation of the Rectangle. 56 | 57 | Represents the rectangle with the # character. 58 | """ 59 | if self.__width == 0 or self.__height == 0: 60 | return ("") 61 | 62 | rect = [] 63 | for i in range(self.__height): 64 | [rect.append('#') for j in range(self.__width)] 65 | if i != self.__height - 1: 66 | rect.append("\n") 67 | return ("".join(rect)) 68 | 69 | def __repr__(self): 70 | """Return the string representation of the Rectangle.""" 71 | rect = "Rectangle(" + str(self.__width) 72 | rect += ", " + str(self.__height) + ")" 73 | return (rect) 74 | -------------------------------------------------------------------------------- /0x08-python-more_classes/5-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines a Rectangle class.""" 3 | 4 | 5 | class Rectangle: 6 | """Represent a rectangle.""" 7 | 8 | def __init__(self, width=0, height=0): 9 | """Initialize a new Rectangle. 10 | 11 | Args: 12 | width (int): The width of the new rectangle. 13 | height (int): The height of the new rectangle. 14 | """ 15 | self.width = width 16 | self.height = height 17 | 18 | @property 19 | def width(self): 20 | """Get/set the width of the Rectangle.""" 21 | return self.__width 22 | 23 | @width.setter 24 | def width(self, value): 25 | if not isinstance(value, int): 26 | raise TypeError("width must be an integer") 27 | if value < 0: 28 | raise ValueError("width must be >= 0") 29 | self.__width = value 30 | 31 | @property 32 | def height(self): 33 | """Get/set the height of the Rectangle.""" 34 | return self.__height 35 | 36 | @height.setter 37 | def height(self, value): 38 | if not isinstance(value, int): 39 | raise TypeError("height must be an integer") 40 | if value < 0: 41 | raise ValueError("height must be >= 0") 42 | self.__height = value 43 | 44 | def area(self): 45 | """Return the area of the Rectangle.""" 46 | return (self.__width * self.__height) 47 | 48 | def perimeter(self): 49 | """Return the perimeter of the Rectangle.""" 50 | if self.__width == 0 or self.__height == 0: 51 | return (0) 52 | return ((self.__width * 2) + (self.__height * 2)) 53 | 54 | def __str__(self): 55 | """Return the printable representation of the Rectangle. 56 | 57 | Represents the rectangle with the # character. 58 | """ 59 | if self.__width == 0 or self.__height == 0: 60 | return ("") 61 | 62 | rect = [] 63 | for i in range(self.__height): 64 | [rect.append('#') for j in range(self.__width)] 65 | if i != self.__height - 1: 66 | rect.append("\n") 67 | return ("".join(rect)) 68 | 69 | def __repr__(self): 70 | """Return the string representation of the Rectangle.""" 71 | rect = "Rectangle(" + str(self.__width) 72 | rect += ", " + str(self.__height) + ")" 73 | return (rect) 74 | 75 | def __del__(self): 76 | """Print a message for every deletion of a Rectangle.""" 77 | print("Bye rectangle...") 78 | -------------------------------------------------------------------------------- /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(l=[]): 3 | l += ["BestSchool"] 4 | return ", ".join(l) 5 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/101-locked_class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Module for a class that prevents dynamic attributes creation 4 | 5 | """ 6 | 7 | 8 | class LockedClass(): 9 | """Class to prevent dynamic attributes creation""" 10 | __slots__ = ['first_name'] 11 | 12 | def __init__(self): 13 | """Init method""" 14 | pass 15 | -------------------------------------------------------------------------------- /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/104-line1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/104-line2.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/104-line3.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/104-line4.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/104-line5.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/105-line1.txt: -------------------------------------------------------------------------------- 1 | 262 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/106-line1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/106-line2.txt: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/106-line3.txt: -------------------------------------------------------------------------------- 1 | No 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/106-line4.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | -------------------------------------------------------------------------------- /0x09-python-everything_is_object/106-line5.txt: -------------------------------------------------------------------------------- 1 | 1 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(l): 3 | return l[:] 4 | -------------------------------------------------------------------------------- /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 | No 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 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/0-lookup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines an object attribute lookup function.""" 4 | 5 | 6 | def lookup(obj): 7 | """Return a list of an object's available attributes.""" 8 | return (dir(obj)) 9 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/1-my_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines an inherited list class MyList.""" 4 | 5 | 6 | class MyList(list): 7 | """Implements sorted printing for the built-in list class.""" 8 | 9 | def print_sorted(self): 10 | """Print a list in sorted ascending order.""" 11 | print(sorted(self)) 12 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/10-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a Rectangle subclass Square.""" 4 | Rectangle = __import__('9-rectangle').Rectangle 5 | 6 | 7 | class Square(Rectangle): 8 | """Represent a square.""" 9 | 10 | def __init__(self, size): 11 | """Initialize a new square. 12 | 13 | Args: 14 | size (int): The size of the new square. 15 | """ 16 | self.integer_validator("size", size) 17 | super().__init__(size, size) 18 | self.__size = size 19 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/100-my_int.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a class MyInt that inherits from int.""" 4 | 5 | 6 | class MyInt(int): 7 | """Invert int operators == and !=.""" 8 | 9 | def __eq__(self, value): 10 | """Override == opeartor with != behavior.""" 11 | return self.real != value 12 | 13 | def __ne__(self, value): 14 | """Override != operator with == behavior.""" 15 | return self.real == value 16 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/101-add_attribute.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a function that adds attributes to objects.""" 4 | 5 | 6 | def add_attribute(obj, att, value): 7 | """Add a new attribute to an object if possible. 8 | 9 | Args: 10 | obj (any): The object to add an attribute to. 11 | att (str): The name of the attribute to add to obj. 12 | value (any): The value of att. 13 | Raises: 14 | TypeError: If the attribute cannot be added. 15 | """ 16 | if not hasattr(obj, "__dict__"): 17 | raise TypeError("can't add new attribute") 18 | setattr(obj, att, value) 19 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/11-square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a Rectangle subclass Square.""" 4 | Rectangle = __import__('9-rectangle').Rectangle 5 | 6 | 7 | class Square(Rectangle): 8 | """Represent a square.""" 9 | 10 | def __init__(self, size): 11 | """Initialize a new square. 12 | 13 | Args: 14 | size (int): The size of the new square. 15 | """ 16 | self.integer_validator("size", size) 17 | super().__init__(size, size) 18 | self.__size = size 19 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/2-is_same_class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a class-checking function.""" 4 | 5 | 6 | def is_same_class(obj, a_class): 7 | """Check if an object is exactly an instance of a given class. 8 | 9 | Args: 10 | obj (any): The object to check. 11 | a_class (type): The class to match the type of obj to. 12 | Returns: 13 | If obj is exactly an instance of a_class - True. 14 | Otherwise - False. 15 | """ 16 | if type(obj) == a_class: 17 | return True 18 | return False 19 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/3-is_kind_of_class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a class and inherited class-checking function.""" 4 | 5 | 6 | def is_kind_of_class(obj, a_class): 7 | """Check if an object is an instance or inherited instance of a class. 8 | 9 | Args: 10 | obj (any): The object to check. 11 | a_class (type): The class to match the type of obj to. 12 | Returns: 13 | If obj is an instance or inherited instance of a_class - True. 14 | Otherwise - False. 15 | """ 16 | if isinstance(obj, a_class): 17 | return True 18 | return False 19 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/4-inherits_from.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines an inherited class-checking function.""" 4 | 5 | 6 | def inherits_from(obj, a_class): 7 | """Checks if an object is an inherited instance of a class. 8 | 9 | Args: 10 | obj (any): The object to check. 11 | a_class (type): The class to match the type of obj to. 12 | Returns: 13 | If obj is an inherited instance of a_class - True. 14 | Otherwise - False. 15 | """ 16 | if issubclass(type(obj), a_class) and type(obj) != a_class: 17 | return True 18 | return False 19 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/5-base_geometry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines an empty class BaseGeometry.""" 4 | 5 | 6 | class BaseGeometry: 7 | """Represent base geometry.""" 8 | pass 9 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/6-base_geometry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a base geometry class BaseGeometry.""" 4 | 5 | 6 | class BaseGeometry: 7 | """Represent base geometry.""" 8 | 9 | def area(self): 10 | """Not implemented.""" 11 | raise Exception("area() is not implemented") 12 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/7-base_geometry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a base geometry class BaseGeometry.""" 4 | 5 | 6 | class BaseGeometry: 7 | """Reprsent base geometry.""" 8 | 9 | def area(self): 10 | """Not yet implemented.""" 11 | raise Exception("area() is not implemented") 12 | 13 | def integer_validator(self, name, value): 14 | """Validate a parameter as an integer. 15 | 16 | Args: 17 | name (str): The name of the parameter. 18 | value (int): The parameter to validate. 19 | Raises: 20 | TypeError: If value is not an integer. 21 | ValueError: If value is <= 0. 22 | """ 23 | if type(value) != int: 24 | raise TypeError("{} must be an integer".format(name)) 25 | if value <= 0: 26 | raise ValueError("{} must be greater than 0".format(name)) 27 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/8-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a class Rectangle that inherits from BaseGeometry.""" 4 | BaseGeometry = __import__('7-base_geometry').BaseGeometry 5 | 6 | 7 | class Rectangle(BaseGeometry): 8 | """Represent a rectangle using BaseGeometry.""" 9 | 10 | def __init__(self, width, height): 11 | """Intialize a new Rectangle. 12 | 13 | Args: 14 | width (int): The width of the new Rectangle. 15 | height (int): The height of the new Rectangle. 16 | """ 17 | self.integer_validator("width", width) 18 | self.__width = width 19 | self.integer_validator("height", height) 20 | self.__height = height 21 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/9-rectangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a class Rectangle that inherits from BaseGeometry.""" 4 | BaseGeometry = __import__('7-base_geometry').BaseGeometry 5 | 6 | 7 | class Rectangle(BaseGeometry): 8 | """Represent a rectangle using BaseGeometry.""" 9 | 10 | def __init__(self, width, height): 11 | """Intialize a new Rectangle. 12 | 13 | Args: 14 | width (int): The width of the new Rectangle. 15 | height (int): The height of the new Rectangle. 16 | """ 17 | super().integer_validator("width", width) 18 | self.__width = width 19 | super().integer_validator("height", height) 20 | self.__height = height 21 | 22 | def area(self): 23 | """Return the area of the rectangle.""" 24 | return self.__width * self.__height 25 | 26 | def __str__(self): 27 | """Return the print() and str() representation of a Rectangle.""" 28 | string = "[" + str(self.__class__.__name__) + "] " 29 | string += str(self.__width) + "/" + str(self.__height) 30 | return string 31 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/README.md: -------------------------------------------------------------------------------- 1 | # Python - Inheritance 2 | 3 | In this project, I learned about Python class inheritance. I learned about the 4 | differences between super- and sub-classes while practicing inheritance, 5 | definining classes with multiple base classes, and overiding inherited methods 6 | and attributes. 7 | -------------------------------------------------------------------------------- /0x0A-python-inheritance/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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/tests/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 | -------------------------------------------------------------------------------- /0x0B-python-input_output/0-read_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a text file-reading function.""" 4 | 5 | 6 | def read_file(filename=""): 7 | """Print the contents of a UTF8 text file to stdout.""" 8 | with open(filename, encoding="utf-8") as f: 9 | print(f.read(), end="") 10 | -------------------------------------------------------------------------------- /0x0B-python-input_output/1-write_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a file-writing function.""" 4 | 5 | 6 | def write_file(filename="", text=""): 7 | """Write a string to a UTF8 text file. 8 | 9 | Args: 10 | filename (str): The name of the file to write. 11 | text (str): The text to write to the file. 12 | Returns: 13 | The number of characters written. 14 | """ 15 | with open(filename, "w", encoding="utf-8") as f: 16 | return f.write(text) 17 | -------------------------------------------------------------------------------- /0x0B-python-input_output/10-student.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a class Student.""" 4 | 5 | 6 | class Student: 7 | """Represent a student.""" 8 | 9 | def __init__(self, first_name, last_name, age): 10 | """Initialize a new Student. 11 | 12 | Args: 13 | first_name (str): The first name of the student. 14 | last_name (str): The last name of the student. 15 | age (int): The age of the student. 16 | """ 17 | self.first_name = first_name 18 | self.last_name = last_name 19 | self.age = age 20 | 21 | def to_json(self, attrs=None): 22 | """Get a dictionary representation of the Student. 23 | 24 | If attrs is a list of strings, represents only those attributes 25 | included in the list. 26 | 27 | Args: 28 | attrs (list): (Optional) The attributes to represent. 29 | """ 30 | if (type(attrs) == list and 31 | all(type(ele) == str for ele in attrs)): 32 | return {k: getattr(self, k) for k in attrs if hasattr(self, k)} 33 | return self.__dict__ 34 | -------------------------------------------------------------------------------- /0x0B-python-input_output/100-append_after.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a text file insertion function.""" 4 | 5 | 6 | def append_after(filename="", search_string="", new_string=""): 7 | """Insert text after each line containing a given string in a file. 8 | 9 | Args: 10 | filename (str): The name of the file. 11 | search_string (str): The string to search for within the file. 12 | new_string (str): The string to insert. 13 | """ 14 | text = "" 15 | with open(filename) as r: 16 | for line in r: 17 | text += line 18 | if search_string in line: 19 | text += new_string 20 | with open(filename, "w") as w: 21 | w.write(text) 22 | -------------------------------------------------------------------------------- /0x0B-python-input_output/101-stats.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Reads from standard input and computes metrics. 4 | 5 | After every ten lines or the input of a keyboard interruption (CTRL + C), 6 | prints the following statistics: 7 | - Total file size up to that point. 8 | - Count of read status codes up to that point. 9 | """ 10 | 11 | 12 | def print_stats(size, status_codes): 13 | """Print accumulated metrics. 14 | 15 | Args: 16 | size (int): The accumulated read file size. 17 | status_codes (dict): The accumulated count of status codes. 18 | """ 19 | print("File size: {}".format(size)) 20 | for key in sorted(status_codes): 21 | print("{}: {}".format(key, status_codes[key])) 22 | 23 | if __name__ == "__main__": 24 | import sys 25 | 26 | size = 0 27 | status_codes = {} 28 | valid_codes = ['200', '301', '400', '401', '403', '404', '405', '500'] 29 | count = 0 30 | 31 | try: 32 | for line in sys.stdin: 33 | if count == 10: 34 | print_stats(size, status_codes) 35 | count = 1 36 | else: 37 | count += 1 38 | 39 | line = line.split() 40 | 41 | try: 42 | size += int(line[-1]) 43 | except (IndexError, ValueError): 44 | pass 45 | 46 | try: 47 | if line[-2] in valid_codes: 48 | if status_codes.get(line[-2], -1) == -1: 49 | status_codes[line[-2]] = 1 50 | else: 51 | status_codes[line[-2]] += 1 52 | except IndexError: 53 | pass 54 | 55 | print_stats(size, status_codes) 56 | 57 | except KeyboardInterrupt: 58 | print_stats(size, status_codes) 59 | raise 60 | -------------------------------------------------------------------------------- /0x0B-python-input_output/11-student.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a class Student.""" 4 | 5 | 6 | class Student: 7 | """Represent a student.""" 8 | 9 | def __init__(self, first_name, last_name, age): 10 | """Initialize a new Student. 11 | 12 | Args: 13 | first_name (str): The first name of the student. 14 | last_name (str): The last name of the student. 15 | age (int): The age of the student. 16 | """ 17 | self.first_name = first_name 18 | self.last_name = last_name 19 | self.age = age 20 | 21 | def to_json(self, attrs=None): 22 | """Get a dictionary representation of the Student. 23 | 24 | If attrs is a list of strings, represents only those attributes 25 | included in the list. 26 | 27 | Args: 28 | attrs (list): (Optional) The attributes to represent. 29 | """ 30 | if (type(attrs) == list and 31 | all(type(ele) == str for ele in attrs)): 32 | return {k: getattr(self, k) for k in attrs if hasattr(self, k)} 33 | return self.__dict__ 34 | 35 | def reload_from_json(self, json): 36 | """Replace all attributes of the Student. 37 | 38 | Args: 39 | json (dict): The key/value pairs to replace attributes with. 40 | """ 41 | for k, v in json.items(): 42 | setattr(self, k, v) 43 | -------------------------------------------------------------------------------- /0x0B-python-input_output/12-pascal_triangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a Pascal's Triangle function.""" 4 | 5 | 6 | def pascal_triangle(n): 7 | """Represent Pascal's Triangle of size n. 8 | 9 | Returns a list of lists of integers representing the triangle. 10 | """ 11 | if n <= 0: 12 | return [] 13 | 14 | triangles = [[1]] 15 | while len(triangles) != n: 16 | tri = triangles[-1] 17 | tmp = [1] 18 | for i in range(len(tri) - 1): 19 | tmp.append(tri[i] + tri[i + 1]) 20 | tmp.append(1) 21 | triangles.append(tmp) 22 | return triangles 23 | -------------------------------------------------------------------------------- /0x0B-python-input_output/2-append_write.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a file-appending function.""" 4 | 5 | 6 | def append_write(filename="", text=""): 7 | """Appends a string to the end of a UTF8 text file. 8 | 9 | Args: 10 | filename (str): The name of the file to append to. 11 | text (str): The string to append to the file. 12 | Returns: 13 | The number of characters appended. 14 | """ 15 | with open(filename, "a", encoding="utf-8") as f: 16 | return f.write(text) 17 | -------------------------------------------------------------------------------- /0x0B-python-input_output/3-to_json_string.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a string-to-JSON function.""" 4 | import json 5 | 6 | 7 | def to_json_string(my_obj): 8 | """Return the JSON representation of a string object.""" 9 | return json.dumps(my_obj) 10 | -------------------------------------------------------------------------------- /0x0B-python-input_output/4-from_json_string.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a JSON-to-object function.""" 4 | import json 5 | 6 | 7 | def from_json_string(my_str): 8 | """Return the Python object representation of a JSON string.""" 9 | return json.loads(my_str) 10 | -------------------------------------------------------------------------------- /0x0B-python-input_output/5-save_to_json_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a JSON file-writing function.""" 4 | import json 5 | 6 | 7 | def save_to_json_file(my_obj, filename): 8 | """Write an object to a text file using JSON representation.""" 9 | with open(filename, "w") as f: 10 | json.dump(my_obj, f) 11 | -------------------------------------------------------------------------------- /0x0B-python-input_output/6-load_from_json_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a JSON file-reading function.""" 4 | import json 5 | 6 | 7 | def load_from_json_file(filename): 8 | """Create a Python object from a JSON file.""" 9 | with open(filename) as f: 10 | return json.load(f) 11 | -------------------------------------------------------------------------------- /0x0B-python-input_output/7-add_item.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Add all arguments to a Python list and save them to a file.""" 4 | import sys 5 | 6 | if __name__ == "__main__": 7 | save_to_json_file = __import__('5-save_to_json_file').save_to_json_file 8 | load_from_json_file = \ 9 | __import__('6-load_from_json_file').load_from_json_file 10 | 11 | try: 12 | items = load_from_json_file("add_item.json") 13 | except FileNotFoundError: 14 | items = [] 15 | items.extend(sys.argv[1:]) 16 | save_to_json_file(items, "add_item.json") 17 | -------------------------------------------------------------------------------- /0x0B-python-input_output/8-class_to_json.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a Python class-to-JSON function.""" 4 | 5 | 6 | def class_to_json(obj): 7 | """Return the dictionary representation of a simple data structure.""" 8 | return obj.__dict__ 9 | -------------------------------------------------------------------------------- /0x0B-python-input_output/9-student.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """Defines a class Student.""" 4 | 5 | 6 | class Student: 7 | """Represent a student.""" 8 | 9 | def __init__(self, first_name, last_name, age): 10 | """Initialize a new Student. 11 | 12 | Args: 13 | first_name (str): The first name of the student. 14 | last_name (str): The last name of the student. 15 | age (int): The age of the student. 16 | """ 17 | self.first_name = first_name 18 | self.last_name = last_name 19 | self.age = age 20 | 21 | def to_json(self): 22 | """Get a dictionary representation of the Student.""" 23 | return self.__dict__ 24 | -------------------------------------------------------------------------------- /0x0B-python-input_output/README.md: -------------------------------------------------------------------------------- 1 | # Python - Input/Output 2 | 3 | In this project, I practiced file handling in Python. I used the builtin `with`, 4 | `open`, and `read` functions with the `json` module to read and write files and 5 | serialize and deserialize objects with JSON. 6 | -------------------------------------------------------------------------------- /0x0B-python-input_output/tests/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 | -------------------------------------------------------------------------------- /0x0B-python-input_output/tests/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | number_of_lines = __import__('1-number_of_lines').number_of_lines 3 | 4 | filename = "my_file_0.txt" 5 | nb_lines = number_of_lines(filename) 6 | print("{} has {:d} lines".format(filename, nb_lines)) 7 | -------------------------------------------------------------------------------- /0x0B-python-input_output/tests/10-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | MyClass = __import__('10-my_class').MyClass 3 | class_to_json = __import__('10-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/tests/10-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 | 14 | def __str__(self): 15 | return "[MyClass] {} - {:d}".format(self.name, self.number) 16 | -------------------------------------------------------------------------------- /0x0B-python-input_output/tests/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | append_after = __import__('100-append_after').append_after 3 | 4 | append_after("append_after_100.txt", "Python", "\"C is fun!\"\n") 5 | -------------------------------------------------------------------------------- /0x0B-python-input_output/tests/11-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Student = __import__('11-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/tests/12-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | Student = __import__('12-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/tests/14-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 14-main 4 | """ 5 | pascal_triangle = __import__('14-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/tests/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | read_lines = __import__('2-read_lines').read_lines 3 | 4 | print("1 line:") 5 | read_lines("my_file_0.txt", 1) 6 | print("--") 7 | print("3 lines:") 8 | read_lines("my_file_0.txt", 3) 9 | print("--") 10 | print("Full content:") 11 | read_lines("my_file_0.txt") 12 | -------------------------------------------------------------------------------- /0x0B-python-input_output/tests/3-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | write_file = __import__('3-write_file').write_file 3 | 4 | nb_characters = write_file("my_first_file.txt", "Holberton School is so cool!\n") 5 | print(nb_characters) 6 | -------------------------------------------------------------------------------- /0x0B-python-input_output/tests/4-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | append_write = __import__('4-append_write').append_write 3 | 4 | nb_characters_added = append_write("file_append.txt", "Holberton School is so cool!\n") 5 | print(nb_characters_added) 6 | -------------------------------------------------------------------------------- /0x0B-python-input_output/tests/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | to_json_string = __import__('5-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/tests/6-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from_json_string = __import__('6-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 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x0C-python-almost_a_circle/models/__init__.py -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/models/square.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Module that contains class Square, 3 | inheritance of class Rectangle 4 | """ 5 | from models.rectangle import Rectangle 6 | 7 | 8 | class Square(Rectangle): 9 | """ Class Rectangle """ 10 | 11 | def __init__(self, size, x=0, y=0, id=None): 12 | """ Initializes instances """ 13 | super().__init__(size, size, x, y, id) 14 | 15 | def __str__(self): 16 | """ str special method """ 17 | str_square = "[Square] " 18 | str_id = "({}) ".format(self.id) 19 | str_xy = "{}/{} - ".format(self.x, self.y) 20 | str_wh = "{}/{}".format(self.width, self.height) 21 | 22 | return str_square + str_id + str_xy + str_wh 23 | 24 | @property 25 | def size(self): 26 | """ Getter size """ 27 | return self.width 28 | 29 | @size.setter 30 | def size(self, value): 31 | """ Setter size """ 32 | self.width = value 33 | self.height = value 34 | 35 | def __str__(self): 36 | """ str special method """ 37 | str_rectangle = "[Square] " 38 | str_id = "({}) ".format(self.id) 39 | str_xy = "{}/{} - ".format(self.x, self.y) 40 | str_size = "{}".format(self.size) 41 | 42 | return str_rectangle + str_id + str_xy + str_size 43 | 44 | def update(self, *args, **kwargs): 45 | """ update method """ 46 | if args is not None and len(args) is not 0: 47 | list_atr = ['id', 'size', 'x', 'y'] 48 | for i in range(len(args)): 49 | if list_atr[i] == 'size': 50 | setattr(self, 'width', args[i]) 51 | setattr(self, 'height', args[i]) 52 | else: 53 | setattr(self, list_atr[i], args[i]) 54 | else: 55 | for key, value in kwargs.items(): 56 | if key == 'size': 57 | setattr(self, 'width', value) 58 | setattr(self, 'height', value) 59 | else: 60 | setattr(self, key, value) 61 | 62 | def to_dictionary(self): 63 | """ Returns a dictionary with attributes """ 64 | list_atr = ['id', 'size', 'x', 'y'] 65 | dict_res = {} 66 | 67 | for key in list_atr: 68 | if key == 'size': 69 | dict_res[key] = getattr(self, 'width') 70 | else: 71 | dict_res[key] = getattr(self, key) 72 | 73 | return dict_res 74 | -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x0C-python-almost_a_circle/tests/__init__.py -------------------------------------------------------------------------------- /0x0C-python-almost_a_circle/tests/test_models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pericles001/alx-higher_level_programming/231db76afbacfcc65f4b519e26ab2827eb99efd6/0x0C-python-almost_a_circle/tests/test_models/__init__.py -------------------------------------------------------------------------------- /0x0D-SQL_introduction/0-list_databases.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all databases of your MySQL server. 2 | SHOW DATABASES; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/1-create_database_if_missing.sql: -------------------------------------------------------------------------------- 1 | -- A script that creates a database hbtn_0c_0 in MYSQL server 2 | CREATE DATABASE IF NOT EXISTS hbtn_0c_0; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/10-top_score.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all records of the table second_table of the database hbtn_0c_0 in your MySQL server. 2 | SELECT score, name FROM second_table ORDER BY score DESC; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/100-move_to_utf8.sql: -------------------------------------------------------------------------------- 1 | -- a script that converts hbtn_0c_0 database to UTF8 (utf8mb4, collate utf8mb4_unicode_ci) in your MySQL server. 2 | ALTER TABLE `hbtn_0c_0`.`first_table` MODIFY `name` VARCHAR(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 3 | ALTER TABLE `hbtn_0c_0`.`first_table` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 4 | ALTER DATABASE `hbtn_0c_0` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 5 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/101-avg_temperatures.sql: -------------------------------------------------------------------------------- 1 | -- a script that displays the average temperature (Fahrenheit) by city ordered by temperature (descending). 2 | SELECT city, AVG(value) AS avg_temp FROM temperatures GROUP by CITY ORDER BY avg_temp DESC; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/102-top_city.sql: -------------------------------------------------------------------------------- 1 | -- a script that displays the top 3 of cities temperature during July and August ordered by temperature (descending) 2 | SELECT city, AVG(value) AS avg_temp 3 | FROM temperatures 4 | WHERE month = 7 OR month = 8 5 | GROUP BY city 6 | ORDER BY avg_temp DESC 7 | LIMIT 3; 8 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/103-max_state.sql: -------------------------------------------------------------------------------- 1 | -- a script that displays the max temperature of each state (ordered by State name). 2 | SELECT state, max(value) as max_temp 3 | FROM temperatures 4 | GROUP BY state 5 | ORDER BY state; 6 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/11-best_score.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all records with a score >= 10 in the table second_table of the database hbtn_0c_0 in your MySQL server. 2 | SELECT score, name FROM second_table WHERE score >= 10 ORDER BY score DESC; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/12-no_cheating.sql: -------------------------------------------------------------------------------- 1 | -- a script that updates the score of Bob to 10 in the table second_table. 2 | UPDATE second_table SET score = 10 WHERE name = "Bob"; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/13-change_class.sql: -------------------------------------------------------------------------------- 1 | -- a script that removes all records with a score <= 5 in the table second_table of the database hbtn_0c_0 in your MySQL server. 2 | DELETE FROM second_table WHERE score <= 5; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/14-average.sql: -------------------------------------------------------------------------------- 1 | -- a script that computes the score average of all records in the table second_table of the database hbtn_0c_0 in your MySQL server. 2 | SELECT AVG(score) AS average FROM second_table; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/15-groups.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists the number of records with the same score in the table second_table of the database hbtn_0c_0 in your MySQL server. 2 | SELECT score, COUNT(*) as `number` FROM second_table GROUP BY score ORDER BY score DESC; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/16-no_link.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all records of the table second_table of the database hbtn_0c_0 in your MySQL server. 2 | SELECT score, name FROM second_table WHERE name IS NOT NULL ORDER BY score DESC; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/2-remove_database.sql: -------------------------------------------------------------------------------- 1 | -- a script that deletes the database hbtn_0c_0 in your MySQL server. 2 | DROP DATABASE IF EXISTS hbtn_0c_0; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/3-list_tables.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all the tables of a database in your MySQL server. 2 | SHOW TABLES; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/4-first_table.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates a table called first_table in the current database in your MySQL server. 2 | CREATE TABLE IF NOT EXISTS first_table (id INT, name VARCHAR(256)); 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/5-full_table.sql: -------------------------------------------------------------------------------- 1 | -- a script that prints the full description of the table first_table from the database hbtn_0c_0 in your MySQL server. 2 | SHOW CREATE TABLE first_table; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/6-list_values.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all rows of the table first_table from the database hbtn_0c_0 in your MySQL server. 2 | SELECT * FROM first_table; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/7-insert_value.sql: -------------------------------------------------------------------------------- 1 | -- a script that inserts a new row in the table first_table (database hbtn_0c_0) in your MySQL server. 2 | INSERT INTO `first_table` (`id`, `name`) VALUES (89, "Best School"); 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/8-count_89.sql: -------------------------------------------------------------------------------- 1 | -- a script that displays the number of records with id = 89 in the table first_table of the database hbtn_0c_0 in your MySQL server. 2 | SELECT COUNT(*) FROM first_table WHERE id=89; 3 | -------------------------------------------------------------------------------- /0x0D-SQL_introduction/9-full_creation.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates a table second_table in the database hbtn_0c_0 in your MySQL server and add multiples rows. 2 | CREATE TABLE IF NOT EXISTS second_table ( 3 | id INT, 4 | name VARCHAR(256), 5 | score INT 6 | ); 7 | INSERT INTO `second_table` (`id`, `name`, `score`) VALUES(1, "John", 10); 8 | INSERT INTO `second_table` (`id`, `name`, `score`) VALUES(2, "Alex", 3); 9 | INSERT INTO `second_table` (`id`, `name`, `score`) VALUES(3, "Bob", 14); 10 | INSERT INTO `second_table` (`id`, `name`, `score`) VALUES(4, "George", 8); 11 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/0-privileges.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all privileges of the MySQL users user_0d_1 and user_0d_2 on your server (in localhost). 2 | SHOW GRANTS FOR 'user_0d_1'@'localhost'; 3 | SHOW GRANTS FOR 'user_0d_2'@'localhost'; 4 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/1-create_user.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates the MySQL server user user_0d_1. 2 | CREATE USER IF NOT EXISTS user_0d_1@localhost IDENTIFIED BY 'user_0d_1_pwd'; 3 | GRANT ALL PRIVILEGES 4 | ON *.* 5 | TO 'user_0d_1'@'localhost'; 6 | FLUSH PRIVILEGES; 7 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/10-genre_id_by_show.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all shows contained in hbtn_0d_tvshows that have at least one genre linked. 2 | SELECT tv_shows.title, tv_show_genres.genre_id 3 | FROM tv_show_genres 4 | INNER JOIN tv_shows 5 | ON tv_shows.id = tv_show_genres.show_id 6 | ORDER BY tv_shows.title, tv_show_genres.genre_id; 7 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/11-genre_id_all_shows.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all shows contained in the database hbtn_0d_tvshows. 2 | SELECT tv_shows.title, tv_show_genres.genre_id 3 | FROM tv_show_genres 4 | RIGHT JOIN tv_shows 5 | ON tv_shows.id = tv_show_genres.show_id 6 | ORDER BY tv_shows.title, tv_show_genres.genre_id; 7 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/12-no_genre.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all shows contained in hbtn_0d_tvshows without a genre linked. 2 | SELECT tv_shows.title, tv_show_genres.genre_id 3 | FROM tv_show_genres 4 | RIGHT JOIN tv_shows 5 | ON tv_shows.id = tv_show_genres.show_id 6 | WHERE tv_show_genres.show_id IS NULL 7 | ORDER BY tv_shows.title, tv_show_genres.genre_id; 8 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/13-count_shows_by_genre.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all genres from hbtn_0d_tvshows and displays the number of shows linked to each. 2 | SELECT tv_genres.name AS genre, COUNT(tv_genres.name) AS number_of_shows 3 | FROM tv_genres 4 | INNER JOIN tv_show_genres 5 | ON tv_genres.id = tv_show_genres.genre_id 6 | GROUP BY tv_genres.name 7 | ORDER BY number_of_shows DESC; 8 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/14-my_genres.sql: -------------------------------------------------------------------------------- 1 | -- a script that uses the hbtn_0d_tvshows database to lists all genres of the show Dexter. 2 | SELECT tv_genres.name 3 | FROM tv_shows 4 | INNER JOIN tv_show_genres 5 | ON tv_shows.id = tv_show_genres.show_id 6 | INNER JOIN tv_genres 7 | ON tv_show_genres.genre_id = tv_genres.id 8 | WHERE tv_shows.title = "Dexter" 9 | ORDER BY tv_genres.name; 10 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/15-comedy_only.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all Comedy shows in the database hbtn_0d_tvshows. 2 | SELECT tv_shows.title 3 | FROM tv_shows 4 | INNER JOIN tv_show_genres 5 | ON tv_shows.id = tv_show_genres.show_id 6 | INNER JOIN tv_genres 7 | ON tv_show_genres.genre_id = tv_genres.id 8 | WHERE tv_genres.name = "comedy" 9 | ORDER BY tv_shows.title; 10 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/16-shows_by_genre.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all shows, and all genres linked to that show, from the database hbtn_0d_tvshows. 2 | SELECT tv_shows.title, tv_genres.name 3 | FROM tv_shows 4 | LEFT JOIN tv_show_genres 5 | ON tv_shows.id = tv_show_genres.show_id 6 | LEFT JOIN tv_genres 7 | ON tv_show_genres.genre_id = tv_genres.id 8 | ORDER BY tv_shows.title, tv_genres.name; 9 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/2-create_read_user.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates the database hbtn_0d_2 and the user user_0d_2. 2 | CREATE DATABASE IF NOT EXISTS hbtn_0d_2; 3 | CREATE USER IF NOT EXISTS 'user_0d_2'@'localhost' IDENTIFIED BY 'user_0d_2_pwd'; 4 | GRANT SELECT ON hbtn_0d_2.* TO 'user_0d_2'@'localhost'; 5 | FLUSH PRIVILEGES; 6 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/3-force_name.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates the table force_name on your MySQL server. 2 | CREATE TABLE IF NOT EXISTS force_name (id INT, name VARCHAR(256)); 3 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/4-never_empty.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates the table id_not_null on your MySQL server. 2 | CREATE TABLE IF NOT EXISTS id_not_null (id INT DEFAULT 1, name VARCHAR(256)); 3 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/5-unique_id.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates the table unique_id on your MySQL server. 2 | CREATE TABLE IF NOT EXISTS unique_id (id INT UNIQUE DEFAULT 1, name VARCHAR(256)); 3 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/6-states.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates the database hbtn_0d_usa and the table states (in the database hbtn_0d_usa) on your MySQL server. 2 | CREATE DATABASE IF NOT EXISTS hbtn_0d_usa; 3 | CREATE TABLE IF NOT EXISTS hbtn_0d_usa.states ( 4 | id INT UNIQUE NOT NULL AUTO_INCREMENT, 5 | name VARCHAR(256) NOT NULL, 6 | PRIMARY KEY (id) 7 | ); 8 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/7-cities.sql: -------------------------------------------------------------------------------- 1 | -- a script that creates the database hbtn_0d_usa and the table cities (in the database hbtn_0d_usa) on your MySQL server. 2 | CREATE DATABASE IF NOT EXISTS `hbtn_0d_usa`; 3 | CREATE TABLE IF NOT EXISTS `hbtn_0d_usa`.`cities` ( 4 | `id` INT UNIQUE NOT NULL AUTO_INCREMENT, 5 | `state_id` INT NOT NULL, 6 | `name` VARCHAR(256) NOT NULL, 7 | PRIMARY KEY (`id`), 8 | FOREIGN KEY (`state_id`) REFERENCES `hbtn_0d_usa`.`states`(`id`)); 9 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/8-cities_of_california_subquery.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all the cities of California that can be found in the database hbtn_0d_usa. 2 | SELECT id, name 3 | FROM cities 4 | WHERE state_id = (SELECT id FROM states WHERE name = 'California') 5 | ORDER BY id ASC; 6 | -------------------------------------------------------------------------------- /0x0E-SQL_more_queries/9-cities_by_state_join.sql: -------------------------------------------------------------------------------- 1 | -- a script that lists all cities contained in the database hbtn_0d_usa. 2 | SELECT cities.id, cities.name, states.name 3 | FROM cities 4 | INNER JOIN states 5 | ON cities.state_id = states.id; 6 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/0-select_states.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """lists all states from the database hbtn_0e_0_usa 3 | Usage: ./0-select_states.py 4 | 5 | 6 | """ 7 | 8 | import sys 9 | import MySQLdb 10 | 11 | if __name__ == "__main__": 12 | db = MySQLdb.connect(user=sys.argv[1], passwd=sys.argv[2], db=sys.argv[3]) 13 | c = db.cursor() 14 | c.execute("SELECT * FROM `states`") 15 | [print(state) for state in c.fetchall()] 16 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/1-filter_states.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ lists all states with a name starting with N (upper N) 3 | from the database hbtn_0e_0_usa 4 | Usage: ./1-filter_states.py 5 | 6 | """ 7 | 8 | import sys 9 | from unicodedata import name 10 | import MySQLdb 11 | 12 | if __name__ == "__main__": 13 | db = MySQLdb.connect(user=sys.argv[1], passwd=sys.argv[2], db=sys.argv[3]) 14 | c = db.cursor() 15 | c.execute("SELECT * FROM `states` ORDER BY `id`") 16 | [print(state) for state in c.fetchall() if state[1][0] == "N"] 17 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/10-model_state_my_get.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | prints the State object with the name 4 | passed as argument from the database hbtn_0e_6_usa 5 | """ 6 | 7 | import sys 8 | from sqlalchemy import create_engine 9 | from sqlalchemy.orm import sessionmaker 10 | from model_state import State 11 | 12 | if __name__ == "__main__": 13 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}".format( 14 | sys.argv[1], sys.argv[2], sys.argv[3]), pool_pre_ping=True) 15 | session_maker = sessionmaker(bind=engine) 16 | session = session_maker() 17 | 18 | for state in session.query(State): 19 | if sys.argv[4] == state.name: 20 | print("{}".format(state.id)) 21 | break 22 | else: 23 | print("Not found") 24 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/100-relationship_states_cities.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | creates the State "California" with the City "San Francisco" from the 4 | database hbtn_0e_100_usa: (100-relationship_states_cities.py) 5 | """ 6 | 7 | import sys 8 | from unicodedata import name 9 | from venv import create 10 | from sqlalchemy import create_engine, true 11 | from sqlalchemy.orm import sessionmaker 12 | from relationship_state import State 13 | from relationship_city import Base, City 14 | 15 | if __name__ == "__main__": 16 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}".format( 17 | sys.argv[1], sys.argv[2], sys.argv[3]), pool_pre_ping=True) 18 | Base.metadata.create_all(engine) 19 | session_maker = sessionmaker(bind=engine) 20 | session = session_maker() 21 | 22 | session.add(City(name="San Francisco", state=State(name="California"))) 23 | session.commit() 24 | session.close() 25 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/101-relationship_states_cities_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | lists all State objects, and corresponding City 4 | objects, contained in the database hbtn_0e_101_usa 5 | """ 6 | 7 | import sys 8 | from unicodedata import name 9 | from venv import create 10 | from sqlalchemy import create_engine, true 11 | from sqlalchemy.orm import sessionmaker 12 | from relationship_state import State 13 | from relationship_city import Base, City 14 | 15 | if __name__ == "__main__": 16 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}".format( 17 | sys.argv[1], sys.argv[2], sys.argv[3]), pool_pre_ping=True) 18 | Base.metadata.create_all(engine) 19 | session_maker = sessionmaker(bind=engine) 20 | session = session_maker() 21 | 22 | for state in session.query(State).order_by(State.id).all(): 23 | print("{}: {}".format(state.id, state.name)) 24 | for city in state.cities: 25 | print("\t{}: {}".format(city.id, city.name)) 26 | session.close() 27 | engine.dispose() 28 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/102-relationship_cities_states_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | lists all City objects from the database hbtn_0e_101_usa 4 | """ 5 | 6 | import sys 7 | from sqlalchemy import create_engine 8 | from sqlalchemy.orm import sessionmaker 9 | from relationship_state import State 10 | from relationship_city import City 11 | 12 | if __name__ == "__main__": 13 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}" 14 | .format(sys.argv[1], sys.argv[2], sys.argv[3]), 15 | pool_pre_ping=True) 16 | session_maker = sessionmaker(bind=engine) 17 | session = session_maker() 18 | 19 | for city in session.query(City).order_by(City.id).all(): 20 | print("{}: {} -> {}".format(city.id, city.name, city.state.name)) 21 | session.close() 22 | engine.dispose() 23 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/11-model_state_insert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | adds the State object "Louisiana" to the database hbtn_0e_6_usa 4 | """ 5 | 6 | import sys 7 | from unicodedata import name 8 | from sqlalchemy import create_engine 9 | from sqlalchemy.orm import sessionmaker 10 | from model_state import State 11 | 12 | if __name__ == "__main__": 13 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}" 14 | .format(sys.argv[1], sys.argv[2], sys.argv[3]), 15 | pool_pre_ping=True) 16 | session_maker = sessionmaker(bind=engine) 17 | session = session_maker() 18 | 19 | obj = State(name="Louisiana") 20 | session.add(obj) 21 | session.commit() 22 | print(obj.id) 23 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/12-model_state_update_id_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | changes the name of a State object from the database hbtn_0e_6_usa 4 | """ 5 | 6 | import sys 7 | from unicodedata import name 8 | from sqlalchemy import create_engine 9 | from sqlalchemy.orm import sessionmaker 10 | from model_state import State 11 | 12 | if __name__ == "__main__": 13 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}" 14 | .format(sys.argv[1], sys.argv[2], sys.argv[3]), 15 | pool_pre_ping=True) 16 | session_maker = sessionmaker(bind=engine) 17 | session = session_maker() 18 | 19 | state = session.query(State).filter_by(id=2).first() 20 | state.name = "New Mexico" 21 | session.commit() 22 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/13-model_state_delete_a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | deletes all State objects with a name 4 | containing the letter a from the database hbtn_0e_6_usa 5 | """ 6 | 7 | import sys 8 | from sqlalchemy import create_engine 9 | from sqlalchemy.orm import sessionmaker 10 | from model_state import State 11 | 12 | if __name__ == "__main__": 13 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}".format( 14 | sys.argv[1], sys.argv[2], sys.argv[3]), pool_pre_ping=True) 15 | session_maker = sessionmaker(bind=engine) 16 | session = session_maker() 17 | 18 | states = session.query(State).filter(State.name.like('%a%')).all() 19 | for state in states: 20 | session.delete(state) 21 | 22 | session.commit() 23 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/14-model_city_fetch_by_state.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | prints all City objects from the database hbtn_0e_14_usa 4 | """ 5 | 6 | import sys 7 | from venv import create 8 | from sqlalchemy import create_engine, true 9 | from sqlalchemy.orm import sessionmaker 10 | from model_state import State 11 | from model_city import City 12 | 13 | if __name__ == "__main__": 14 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}".format( 15 | sys.argv[1], sys.argv[2], sys.argv[3]), pool_pre_ping=True) 16 | session_maker = sessionmaker(bind=engine) 17 | session = session_maker() 18 | 19 | for city, state in session.query(City, State)\ 20 | .filter(City.state_id == State.id)\ 21 | .order_by(City.id): 22 | print("{}: ({}) {}".format(state.name, city.id, city.name)) 23 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/2-my_filter_states.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ takes in an argument 3 | and displays all values 4 | in the states table of 5 | hbtn_0e_0_usa where name matches the argument 6 | Usage: ./2-my_filter_states.py 7 | 8 | 9 | 10 | """ 11 | import sys 12 | import MySQLdb 13 | 14 | if __name__ == "__main__": 15 | db = MySQLdb.connect(user=sys.argv[1], passwd=sys.argv[2], db=sys.argv[3]) 16 | c = db.cursor() 17 | c.execute("""SELECT * FROM states 18 | WHERE name LIKE BINARY '{}' 19 | ORDER BY states.id ASC""".format(sys.argv[4]).strip("'")) 20 | [print(state) for state in c.fetchall()] 21 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/3-my_safe_filter_states.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | displays all values in the states table of 4 | hbtn_0e_0_usa where name matches the argument 5 | """ 6 | 7 | import sys 8 | import MySQLdb 9 | 10 | if __name__ == "__main__": 11 | db = MySQLdb.connect(user=sys.argv[1], passwd=sys.argv[2], db=sys.argv[3]) 12 | c = db.cursor() 13 | c.execute("""SELECT * FROM states""") 14 | [print(state) for state in c.fetchall() if state[1] == sys.argv[4]] 15 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/4-cities_by_state.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | lists all cities from the database hbtn_0e_4_usa 4 | """ 5 | 6 | import sys 7 | import MySQLdb 8 | 9 | if __name__ == "__main__": 10 | db = MySQLdb.connect(user=sys.argv[1], passwd=sys.argv[2], db=sys.argv[3]) 11 | c = db.cursor() 12 | c.execute("""SELECT cities.id, cities.name, states.name 13 | FROM cities 14 | JOIN states 15 | ON cities.state_id = states.id 16 | ORDER BY cities.id ASC""") 17 | [print(city) for city in c.fetchall()] 18 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/5-filter_cities.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | lists all cities of that state, using the database hbtn_0e_4_usa 4 | """ 5 | import sys 6 | import MySQLdb 7 | 8 | if __name__ == "__main__": 9 | db = MySQLdb.connect(user=sys.argv[1], passwd=sys.argv[2], db=sys.argv[3]) 10 | c = db.cursor() 11 | c.execute("""SELECT * FROM cities 12 | INNER JOIN states 13 | ON cities.state_id = states.id 14 | ORDER BY cities.id""") 15 | print(", ".join([city[2] 16 | for city in c.fetchall() 17 | if city[4] == sys.argv[4]])) 18 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/7-model_state_fetch_all.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | lists all State objects from the database hbtn_0e_6_usa 4 | """ 5 | 6 | import sys 7 | from sqlalchemy import create_engine 8 | from sqlalchemy.orm import sessionmaker 9 | from model_state import State 10 | 11 | if __name__ == "__main__": 12 | engine = create_engine( 13 | "mysql+mysqldb://{}:{}@localhost/{}" 14 | .format(sys.argv[1], sys.argv[2], sys.argv[3]), 15 | pool_pre_ping=True 16 | ) 17 | session_maker = sessionmaker(bind=engine) 18 | session = session_maker() 19 | 20 | for state in session.query(State).order_by(State.id): 21 | print("{}: {}".format(state.id, state.name)) 22 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/8-model_state_fetch_first.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | prints the first State object from the database hbtn_0e_6_usa 4 | """ 5 | 6 | import imp 7 | import sys 8 | from venv import create 9 | from sqlalchemy import create_engine 10 | from sqlalchemy.orm import sessionmaker 11 | from model_state import State 12 | 13 | if __name__ == "__main__": 14 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}".format( 15 | sys.argv[1], sys.argv[2], sys.argv[3]), 16 | pool_pre_ping=True) 17 | session_maker = sessionmaker(bind=engine) 18 | session = session_maker() 19 | 20 | state = session.query(State).order_by(State.id).first() 21 | if state is None: 22 | print("Nothing") 23 | else: 24 | print("{}: {}".format(state.id, state.name)) 25 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/9-model_state_filter_a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | lists all State objects that contain 4 | the letter a from the database hbtn_0e_6_usa 5 | """ 6 | 7 | import imp 8 | import sys 9 | from venv import create 10 | from sqlalchemy import create_engine 11 | from sqlalchemy.orm import sessionmaker 12 | from model_state import State 13 | 14 | if __name__ == "__main__": 15 | engine = create_engine("mysql+mysqldb://{}:{}@localhost/{}".format( 16 | sys.argv[1], sys.argv[2], sys.argv[3]), 17 | pool_pre_ping=True) 18 | session_maker = sessionmaker(bind=engine) 19 | session = session_maker() 20 | 21 | for state in session.query(State).order_by(State.id): 22 | if "a" in state.name: 23 | print("{}: {}".format(state.id, state.name)) 24 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/model_city.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Defines a state model that contain the class definition 4 | of a City and an instance Base = declarative_base() 5 | """ 6 | from lib2to3.pytree import Base 7 | from sre_parse import State 8 | from unicodedata import name 9 | from sqlalchemy import Column, ForeignKey, Integer, String, null 10 | from sqlalchemy.ext.declarative import declarative_base 11 | 12 | Base = declarative_base() 13 | 14 | 15 | class City(Base): 16 | """ 17 | inherits from Base (imported from model_state) 18 | links to the MySQL table cities 19 | 20 | class attribute id that represents a column of 21 | an auto-generated, unique integer, can't be null and is a primary key 22 | 23 | class attribute name that represents a column 24 | of a string of 128 characters and can't be null 25 | 26 | class attribute state_id that represents a column 27 | of an integer, can't be null and is a foreign key to states.id 28 | 29 | """ 30 | __tablename__ = "cities" 31 | id = Column(Integer, primary_key=True) 32 | name = Column(String(128), nullable=False) 33 | state_id = Column(Integer, ForeignKey("states.id"), nullable=False) 34 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/model_state.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Defines a state model that contain the class definition 4 | of a State and an instance Base = declarative_base() 5 | """ 6 | from lib2to3.pytree import Base 7 | from sre_parse import State 8 | from unicodedata import name 9 | from sqlalchemy import Column, Integer, String 10 | from sqlalchemy.ext.declarative import declarative_base 11 | 12 | Base = declarative_base() 13 | 14 | 15 | class State(Base): 16 | """ 17 | inherits from Base Tips 18 | links to the MySQL table states 19 | class attribute id that represents a column 20 | of an auto-generated, unique integer, can't 21 | be null and is a primary key 22 | class attribute name that represents a column 23 | of a string with maximum 128 characters and 24 | can't be null 25 | 26 | """ 27 | __tablename__ = "states" 28 | id = Column(Integer, primary_key=True) 29 | name = Column(String(128), nullable=False) 30 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/relationship_city.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Defines a state model that contain the class definition 4 | of a City and an instance Base = declarative_base() 5 | """ 6 | from lib2to3.pytree import Base 7 | from sre_parse import State 8 | from unicodedata import name 9 | from sqlalchemy import Column, ForeignKey, Integer, String, null 10 | from sqlalchemy.ext.declarative import declarative_base 11 | 12 | Base = declarative_base() 13 | 14 | 15 | class City(Base): 16 | """ 17 | inherits from Base (imported from model_state) 18 | links to the MySQL table cities 19 | 20 | class attribute id that represents a column of 21 | an auto-generated, unique integer, can't be null and is a primary key 22 | 23 | class attribute name that represents a column 24 | of a string of 128 characters and can't be null 25 | 26 | class attribute state_id that represents a column 27 | of an integer, can't be null and is a foreign key to states.id 28 | 29 | """ 30 | __tablename__ = "cities" 31 | id = Column(Integer, primary_key=True) 32 | name = Column(String(128), nullable=False) 33 | state_id = Column(Integer, ForeignKey("states.id"), nullable=False) 34 | -------------------------------------------------------------------------------- /0x0F-python-object_relational_mapping/relationship_state.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Defines a state model that contain the class definition 4 | of a State and an instance Base = declarative_base() 5 | """ 6 | from lib2to3.pytree import Base 7 | from sre_parse import State 8 | from unicodedata import name 9 | from sqlalchemy import Column, Integer, String 10 | from sqlalchemy.orm import relationship 11 | from sqlalchemy.ext.declarative import declarative_base 12 | from relationship_city import Base, City 13 | Base = declarative_base() 14 | 15 | 16 | class State(Base): 17 | """ 18 | inherits from Base Tips 19 | links to the MySQL table states 20 | class attribute id that represents a column 21 | of an auto-generated, unique integer, can't 22 | be null and is a primary key 23 | class attribute name that represents a column 24 | of a string with maximum 128 characters and 25 | can't be null 26 | 27 | """ 28 | __tablename__ = "states" 29 | id = Column(Integer, primary_key=True) 30 | name = Column(String(128), nullable=False) 31 | 32 | cities = relationship("City", backref="state", cascade="all, delete") 33 | -------------------------------------------------------------------------------- /0x10-python-network_0/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/.idea/0x10-python-network_0.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /0x10-python-network_0/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /0x10-python-network_0/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /0x10-python-network_0/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /0x10-python-network_0/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /0x10-python-network_0/0-body_size.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #takes in a URL, sends 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 | # takes in a URL, sends a GET request to the URL,and displays the body of the response 3 | curl -sL "$1" 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/100-status_code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #sends a request to a URL passed as an argument, and displays only the status code of the response. 3 | curl -s -o /dev/null -w "%{http_code}" "$1" 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/101-post_json.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Sends a JSON POST request to a given URL with a given JSON file. 3 | curl -s -H "Content-Type: application/json" -d "$(cat "$2")" "$1" 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/102-catch_me.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Makes a request to 0.0.0.0:5000/catch_me that gets the message "You got me!". 3 | curl -sL -X PUT -H "Origin: HolbertonSchool" -d "user_id=98" 0.0.0.0:5000/catch_me 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/2-delete.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # sends a 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 | # takes in a URL and displays all HTTP methods the server will accept. 3 | curl -sI "$1" | grep "Allow" | cut -d " " -f 2- 4 | -------------------------------------------------------------------------------- /0x10-python-network_0/4-header.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #takes in a URL as an argument, sends 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 | #takes in a URL, sends a POST request to the passed URL,and displays 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-peak.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | a function that finds a peak in a list of unsorted integers. 4 | """ 5 | 6 | 7 | def find_peak(list_of_integers): 8 | """ 9 | Return a peak in a list of unsorted integers 10 | """ 11 | if len(list_of_integers) == 0: 12 | return None 13 | if len(list_of_integers) == 1: 14 | return list_of_integers[0] 15 | if len(list_of_integers) == 2: 16 | return max(list_of_integers) 17 | 18 | mid = int(len(list_of_integers) / 2) 19 | peak = list_of_integers[mid] 20 | if peak > list_of_integers[mid - 1] and peak > list_of_integers[mid + 1]: 21 | return peak 22 | elif peak < list_of_integers[mid - 1]: 23 | return find_peak(list_of_integers[:mid]) 24 | else: 25 | return find_peak(list_of_integers[mid + 1:]) 26 | -------------------------------------------------------------------------------- /0x10-python-network_0/6-peak.txt: -------------------------------------------------------------------------------- 1 | 0(log(n)) 2 | -------------------------------------------------------------------------------- /0x11-python-network_1/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /0x11-python-network_1/.idea/0x11-python-network_1.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /0x11-python-network_1/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /0x11-python-network_1/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /0x11-python-network_1/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /0x11-python-network_1/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /0x11-python-network_1/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /0x11-python-network_1/0-hbtn_status.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """fetches https://intranet.hbtn.io/status""" 3 | from urllib import request 4 | 5 | if __name__ == "__main__": 6 | with request.urlopen("https://intranet.hbtn.io/status") as response: 7 | response = response.read() 8 | print("Body response:") 9 | print("\t- type: {}".format(type(response))) 10 | print("\t- content: {}".format(response)) 11 | print("\t- utf8 content: {}".format(response.decode(encoding='utf-8'))) 12 | -------------------------------------------------------------------------------- /0x11-python-network_1/1-hbtn_header.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """takes in a URL, sends a request to the URL and displays the 3 | value of the X-Request-Id variable found in the header of the response. 4 | 5 | Usage: ./1-hbtn_header.py 6 | """ 7 | import sys 8 | 9 | import urllib.request 10 | 11 | if __name__ == "__main__": 12 | url = sys.argv[1] 13 | 14 | request = urllib.request.Request(url) 15 | with urllib.request.urlopen(request) as response: 16 | print(dict(response.headers).get("X-Request-Id")) 17 | -------------------------------------------------------------------------------- /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 | Usage: ./10-my_github.py 5 | - Uses Basic Authentication to access the ID. 6 | """ 7 | import sys 8 | import requests 9 | from requests.auth import HTTPBasicAuth 10 | 11 | 12 | if __name__ == "__main__": 13 | auth = HTTPBasicAuth(sys.argv[1], sys.argv[2]) 14 | r = requests.get("https://api.github.com/user", auth=auth) 15 | print(r.json().get("id")) 16 | -------------------------------------------------------------------------------- /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 | Usage: ./100-github_commits.py 5 | """ 6 | import sys 7 | import requests 8 | 9 | 10 | if __name__ == "__main__": 11 | url = "https://api.github.com/repos/{}/{}/commits".format( 12 | sys.argv[2], sys.argv[1]) 13 | 14 | r = requests.get(url) 15 | commits = r.json() 16 | try: 17 | for i in range(10): 18 | print("{}: {}".format( 19 | commits[i].get("sha"), 20 | commits[i].get("commit").get("author").get("name"))) 21 | except IndexError: 22 | pass 23 | -------------------------------------------------------------------------------- /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 | Usage: ./2-post_email.py 5 | - Displays the body of the response. 6 | """ 7 | import sys 8 | import urllib.parse 9 | import urllib.request 10 | 11 | 12 | if __name__ == "__main__": 13 | url = sys.argv[1] 14 | value = {"email": sys.argv[2]} 15 | data = urllib.parse.urlencode(value).encode("ascii") 16 | 17 | request = urllib.request.Request(url, data) 18 | with urllib.request.urlopen(request) as response: 19 | print(response.read().decode("utf-8")) 20 | -------------------------------------------------------------------------------- /0x11-python-network_1/3-error_code.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | takes in a URL, sends a request to the URL and displays 4 | the body of the response (decoded in utf-8). 5 | """ 6 | 7 | import sys 8 | from urllib import request, error 9 | 10 | if __name__ == "__main__": 11 | url = sys.argv[1] 12 | 13 | own_request = request.Request(url) 14 | try: 15 | with request.urlopen(own_request) as response: 16 | print(response.read().decode("ascii")) 17 | except error.HTTPError as e: 18 | print("Error code: {}".format(e.code)) 19 | -------------------------------------------------------------------------------- /0x11-python-network_1/4-hbtn_status.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | fetches https://alx-intranet.hbtn.io/status 4 | """ 5 | 6 | import requests 7 | 8 | if __name__ == '__main__': 9 | r = requests.get('https://alx-intranet.hbtn.io/status') 10 | print("Body response:") 11 | print("\t- type: {}".format(type(r.text))) 12 | print("\t- content: {}".format(r.text)) 13 | -------------------------------------------------------------------------------- /0x11-python-network_1/5-hbtn_header.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | takes in a URL, sends a request to the URL and displays 4 | the value of the variable X-Request-Id in the response header 5 | """ 6 | 7 | import requests 8 | import sys 9 | 10 | if __name__ == '__main__': 11 | url = sys.argv[1] 12 | 13 | r = requests.get(url) 14 | print(r.headers.get('X-Request-Id')) 15 | -------------------------------------------------------------------------------- /0x11-python-network_1/6-post_email.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """script that takes in a URL and an email address, sends a POST request 3 | to the passed URL with the email as a parameter, and finally displays 4 | the body of the response. 5 | """ 6 | import requests 7 | import sys 8 | 9 | if __name__ == '__main__': 10 | url = sys.argv[1] 11 | email = sys.argv[2] 12 | r = requests.post(url, data={'email': email}) 13 | print(r.text) 14 | -------------------------------------------------------------------------------- /0x11-python-network_1/7-error_code.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ script that takes in a URL, sends a request to 3 | the URL and displays the body of the response.""" 4 | import sys 5 | 6 | import requests 7 | 8 | if __name__ == "__main__": 9 | url = sys.argv[1] 10 | r = requests.get(url) 11 | if r.status_code >= 400: 12 | print("Error code: {}".format(r.status_code)) 13 | else: 14 | print(r.text) 15 | -------------------------------------------------------------------------------- /0x11-python-network_1/8-json_api.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Sends a POST request to http://0.0.0.0:5000/search_user with a given letter. 3 | 4 | Usage: ./8-json_api.py 5 | - The letter is sent as the value of the variable `q`. 6 | - If no letter is provided, sends `q=""`. 7 | """ 8 | import sys 9 | import requests 10 | 11 | 12 | if __name__ == "__main__": 13 | letter = "" if len(sys.argv) == 1 else sys.argv[1] 14 | payload = {"q": letter} 15 | 16 | r = requests.post("http://0.0.0.0:5000/search_user", data=payload) 17 | try: 18 | response = r.json() 19 | if response == {}: 20 | print("No result") 21 | else: 22 | print("[{}] {}".format(response.get("id"), response.get("name"))) 23 | except ValueError: 24 | print("Not a valid JSON") 25 | -------------------------------------------------------------------------------- /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\nPython is cool\nJavaScript is amazing'); 3 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/10-factorial.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | function factorial (n) { 3 | return n === 0 || isNaN(n) ? 1 : n * factorial(n - 1); 4 | } 5 | 6 | console.log(factorial(Number(process.argv[2]))); 7 | -------------------------------------------------------------------------------- /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++) theFunction(); 4 | }; 5 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/102-add_me_maybe.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.addMeMaybe = function addMeMaybe (number, theFunction) { 3 | return 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 = () => { myObject.value += 1; }; 8 | myObject.incr(); 9 | console.log(myObject); 10 | myObject.incr(); 11 | console.log(myObject); 12 | myObject.incr(); 13 | console.log(myObject); 14 | -------------------------------------------------------------------------------- /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 args = process.argv.map(Number) 6 | .slice(2, process.argv.length) 7 | .sort((a, b) => a - b); 8 | console.log(args[args.length - 2]); 9 | } 10 | -------------------------------------------------------------------------------- /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 add (a, b) { 3 | return a + b; 4 | }; 5 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/2-arguments.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const { argv } = require('process'); 3 | if (argv.length === 2) { console.log('No argument'); } else if (argv.length === 3) { console.log('Argument found'); } else { console.log('Arguments found'); } 4 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/3-value_argument.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const { argv } = require('process'); 3 | if (argv[2] === undefined) { console.log('No argument'); } else { console.log(argv[2]); } 4 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/4-concat.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const { argv } = require('process'); 3 | const argv1 = argv[2]; const argv2 = argv[3]; 4 | console.log(argv1 + ' is ' + argv2); 5 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/5-to_integer.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const { argv } = require('process'); 3 | const converted = Number(argv[2]); 4 | if (isNaN(converted)) { console.log('Not a number'); } else { console.log(`My number: ${converted}`); } 5 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/6-multi_languages_loop.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | for (const line of ['C is fun', 'Python is cool', 'JavaScript is amazing']) { 3 | console.log(line); 4 | } 5 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/7-multi_c.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const { argv } = require('process'); 3 | const occurence = Number(argv[2]); 4 | const display = () => { 5 | for (let i = 0; i < occurence; i++) { 6 | console.log('C is fun'); 7 | } 8 | }; 9 | isNaN(occurence) 10 | ? (console.log('Missing number of occurrences')) 11 | : (display()); 12 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/8-square.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const { argv } = require('process'); 3 | const size = Number(argv[2]); 4 | const repeat = 'X'.repeat(size); 5 | if (isNaN(size)) { 6 | console.log('Missing size'); 7 | } else { 8 | for (let i = 0; i < size; i++) { 9 | console.log(repeat); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /0x12-javascript-warm_up/9-add.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const { argv } = require('process'); 3 | const a = Number(argv[2]); 4 | const b = Number(argv[3]); 5 | const add = (a, b) => a + b; 6 | console.log(add(a, b)); 7 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/0-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | module.exports = class Rectangle { 3 | }; 4 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/1-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | module.exports = class Rectangle { 3 | constructor (w, h) { 4 | this.width = w; 5 | this.height = h; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/10-converter.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.converter = function (base) { 3 | return function (dec) { 4 | return dec.toString(base); 5 | }; 6 | }; 7 | -------------------------------------------------------------------------------- /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.js').list; 3 | console.log(list); 4 | console.log(list.map((x, xI) => x * xI)); 5 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/101-sorted.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const dict = require('./101-data').dict; 3 | const newDict = {}; 4 | for (const key in dict) { 5 | if (newDict[dict[key]] === undefined) { 6 | newDict[dict[key]] = [key]; 7 | } else { 8 | newDict[dict[key]].push(key); 9 | } 10 | } 11 | console.log(newDict); 12 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/102-concat.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const fs = require('fs'); 3 | const src1 = fs.readFileSync(process.argv[2], 'utf8'); 4 | const src2 = fs.readFileSync(process.argv[3], 'utf8'); 5 | fs.writeFileSync(process.argv[4], src1 + src2); 6 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/2-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | module.exports = class Rectangle { 3 | constructor (w, h) { 4 | if (w > 0 && h > 0) { [this.width, this.height] = [w, h]; } 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/3-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | module.exports = class Rectangle { 3 | constructor (w, h) { 4 | if (w > 0 && h > 0) { [this.width, this.height] = [w, h]; } 5 | } 6 | 7 | print () { 8 | for (let i = 0; i < this.height; i++) { 9 | console.log('X'.repeat(this.width)); 10 | } 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/4-rectangle.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | module.exports = class Rectangle { 3 | constructor (w, h) { 4 | if (w > 0 && h > 0) { [this.width, this.height] = [w, h]; } 5 | } 6 | 7 | print () { 8 | for (let i = 0; i < this.height; i++) { 9 | console.log('X'.repeat(this.width)); 10 | } 11 | } 12 | 13 | rotate () { 14 | [this.width, this.height] = [this.height, this.width]; 15 | } 16 | 17 | double () { 18 | [this.width, this.height] = [this.width * 2, this.height * 2]; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/5-square.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | module.exports = class Square extends require('./4-rectangle') { 3 | constructor (size) { 4 | super(size, size); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/6-square.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | module.exports = class Square extends require('./5-square') { 3 | charPrint (c) { 4 | if (c === undefined) { this.print(); } else { 5 | for (let i = 0; i < this.height; i++) { console.log(c.repeat(this.width)); } 6 | } 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/7-occurrences.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.nbOccurences = function (list, searchElement) { 3 | let count = 0; 4 | list.map( 5 | (x) => { 6 | if (x === searchElement) { 7 | count += 1; 8 | return 1; 9 | } else { 10 | return 0; 11 | } 12 | } 13 | ); 14 | return count; 15 | }; 16 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/8-esrever.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | exports.esrever = function (list) { 3 | const newList = []; 4 | for (let i = list.length - 1; i >= 0; i--) { 5 | newList.push(list[i]); 6 | } 7 | return newList; 8 | }; 9 | -------------------------------------------------------------------------------- /0x13-javascript_objects_scopes_closures/9-logme.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | let count = 0; 3 | exports.logMe = function (item) { 4 | console.log(`${count++}: ${item}`); 5 | }; 6 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/0-readme.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const fs = require('fs'); 3 | fs.readFile(process.argv[2], 'utf8', function (error, content) { 4 | console.log(error || content); 5 | }); 6 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/1-writeme.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const fs = require('fs'); 3 | fs.writeFile(process.argv[2], process.argv[3], error => { 4 | if (error) { 5 | console.log(error); 6 | } 7 | }); 8 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/100-starwars_characters.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const request = require('request'); 3 | const { argv } = require('process'); 4 | 5 | const BaseUrl = 'https://swapi-api.hbtn.io/api/films/'; 6 | function MakeRequest (url) { 7 | return new Promise(function (resolve, reject) { 8 | request(url, (error, response, body) => { 9 | if (!error && response.statusCode === 200) { 10 | resolve(body); 11 | } else { 12 | reject(error); 13 | } 14 | }); 15 | }); 16 | } 17 | 18 | async function main () { 19 | const movie = await MakeRequest(BaseUrl + argv[2]); 20 | const characters = JSON.parse(movie).characters; 21 | characters.forEach(async function (element) { 22 | const character = await MakeRequest(element); 23 | const CharacterName = JSON.parse(character).name; 24 | console.log(CharacterName); 25 | }); 26 | } 27 | 28 | main(); 29 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/101-starwars_characters.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const request = require('request'); 3 | const url = 'http://swapi.co/api/films/'; 4 | let id = parseInt(process.argv[2], 10); 5 | let characters = []; 6 | 7 | request(url, function (err, response, body) { 8 | if (err == null) { 9 | const resp = JSON.parse(body); 10 | const results = resp.results; 11 | if (id < 4) { 12 | id += 3; 13 | } else { 14 | id -= 3; 15 | } 16 | for (let i = 0; i < results.length; i++) { 17 | if (results[i].episode_id === id) { 18 | characters = results[i].characters; 19 | break; 20 | } 21 | } 22 | for (let j = 0; j < characters.length; j++) { 23 | request(characters[j], function (err, response, body) { 24 | if (err == null) { 25 | console.log(JSON.parse(body).name); 26 | } 27 | }); 28 | } 29 | } 30 | }); 31 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/2-statuscode.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const request = require('request'); 3 | request.get(process.argv[2]).on('response', function (response) { 4 | console.log(`code: ${response.statusCode}`); 5 | }); 6 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/3-starwars_title.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const request = require('request'); 3 | const { argv } = require('process'); 4 | 5 | const BaseUrl = 'https://swapi-api.hbtn.io/api'; 6 | request(BaseUrl + '/films/' + argv[2], (error, response, body) => { 7 | if (error) { 8 | console.error(error); 9 | } 10 | console.log(JSON.parse(body).title); 11 | }); 12 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/4-starwars_count.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const request = require('request'); 3 | request(process.argv[2], function (error, response, body) { 4 | if (!error) { 5 | const results = JSON.parse(body).results; 6 | console.log(results.reduce((count, movie) => { 7 | return movie.characters.find((character) => character.endsWith('/18/')) 8 | ? count + 1 9 | : count; 10 | }, 0)); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/5-request_store.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const fs = require('fs'); 3 | const request = require('request'); 4 | request(process.argv[2]).pipe(fs.createWriteStream(process.argv[3])); 5 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/6-completed_tasks.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/node 2 | const request = require('request'); 3 | request(process.argv[2], function (error, response, body) { 4 | if (!error) { 5 | const todos = JSON.parse(body); 6 | const completed = {}; 7 | todos.forEach((todo) => { 8 | if (todo.completed && completed[todo.userId] === undefined) { 9 | completed[todo.userId] = 1; 10 | } else if (todo.completed) { 11 | completed[todo.userId] += 1; 12 | } 13 | }); 14 | console.log(completed); 15 | } 16 | }); 17 | -------------------------------------------------------------------------------- /0x14-javascript-web_scraping/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "0x14-javascript-web_scraping", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "request": "^2.88.2" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/0-script.js: -------------------------------------------------------------------------------- 1 | document.querySelector('HEADER').style.color = '#FF0000'; 2 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/1-script.js: -------------------------------------------------------------------------------- 1 | $('HEADER').css('color', '#FF0000'); 2 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/100-script.js: -------------------------------------------------------------------------------- 1 | document.addEventListener('DOMContentLoaded', ()=>{ 2 | document.querySelector('HEADER').style.color = '#FF0000'; 3 | }); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/101-script.js: -------------------------------------------------------------------------------- 1 | $('document').ready(function () { 2 | $('DIV#add_item').click(function () { 3 | $('UL.my_list').append('
  • Item
  • '); 4 | }); 5 | $('DIV#remove_item').click(function () { 6 | $('UL.my_list li:last').remove(); 7 | }); 8 | $('DIV#clear_list').click(function () { 9 | $('UL.my_list').empty(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/102-script.js: -------------------------------------------------------------------------------- 1 | $('document').ready(function () { 2 | const url = 'https://www.fourtonfish.com/hellosalut/?'; 3 | $('INPUT#btn_translate').click(function () { 4 | $.get(url + $.param({ lang: $('INPUT#language_code').val() }), function (data) { 5 | $('DIV#hello').html(data.hello); 6 | }); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/103-script.js: -------------------------------------------------------------------------------- 1 | $('document').ready(function () { 2 | $('INPUT#btn_translate').click(translate); 3 | $('INPUT#language_code').focus(function () { 4 | $(this).keydown(function (e) { 5 | if (e.keyCode === 13) { 6 | translate(); 7 | } 8 | }); 9 | }); 10 | }); 11 | 12 | function translate () { 13 | const url = 'https://www.fourtonfish.com/hellosalut/?'; 14 | $.get(url + $.param({ lang: $('INPUT#language_code').val() }), function (data) { 15 | $('DIV#hello').html(data.hello); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/2-script.js: -------------------------------------------------------------------------------- 1 | $('DIV#red_header').click(()=>{ 2 | $('HEADER').css('color', '#FF0000'); 3 | }); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/3-script.js: -------------------------------------------------------------------------------- 1 | $('DIV#red_header').click(()=>{ 2 | $('HEADER').addClass('red'); 3 | }); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/4-script.js: -------------------------------------------------------------------------------- 1 | $('DIV#toggle_header').click(()=>{ 2 | $('HEADER').toggleClass('green red'); 3 | }); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/5-script.js: -------------------------------------------------------------------------------- 1 | $('DIV#add_item').click(()=>{ 2 | $('UL.my_list').append('
  • Item
  • '); 3 | }); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/6-script.js: -------------------------------------------------------------------------------- 1 | $('DIV#update_header').click(()=>{ 2 | $('HEADER').text('New Header!!!'); 3 | }); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/7-script.js: -------------------------------------------------------------------------------- 1 | $.get('https://swapi-api.hbtn.io/api/people/5/?format=json', (data)=>{ 2 | $('DIV#character').text(data.name); 3 | }); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/8-script.js: -------------------------------------------------------------------------------- 1 | $.get('https://swapi-api.hbtn.io/api/films/?format=json', (data)=>{ 2 | $('UL#list_movies').append(...data.results.map(movie => `
  • ${movie.title}
  • `)); 3 | }); 4 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/9-script.js: -------------------------------------------------------------------------------- 1 | $('document').ready( 2 | ()=>{ 3 | $.get('https://fourtonfish.com/hellosalut/?lang=fr', (data)=>{ 4 | $('DIV#hello').text(data.hello); 5 | }); 6 | }); 7 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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/tests/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 | 17 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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/tests/101-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 | 9 |
    10 | First HTML page 11 |
    12 |
    13 |
    Add item
    14 |
    Remove item
    15 |
    Clear list
    16 |
    17 |
      18 |
    • Item
    • 19 |
    20 |
    21 | Holberton School - 2017 22 |
    23 | 24 | 25 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/102-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 | 9 |
    10 | Say Hello 11 |
    12 |
    13 | 14 | 15 |
    16 |
    17 |
    18 |
    19 | Holberton School - 2017 20 |
    21 | 22 | 23 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/103-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 | 9 |
    10 | Say Hello 11 |
    12 |
    13 | 14 | 15 |
    16 |
    17 |
    18 |
    19 | Holberton School - 2017 20 |
    21 | 22 | 23 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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 | 18 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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 | 23 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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 | 26 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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 | 23 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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 | 20 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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 | 20 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/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 | 21 | -------------------------------------------------------------------------------- /0x15-javascript-web_jquery/tests/9-main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Holberton School 5 | 6 | 7 | 8 | 9 |
    10 | Say Hello! 11 |
    12 |
    13 |
    14 |
    15 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # High-level programming 2 | 3 | ## Description 4 | This repository contains programs written for the high-level programming section . 5 | 6 | 7 | ## Structure 8 | 9 | 10 | * [0x00. Python - Hello, World](./0x00-python-hello_world) 11 | * [0x01. Python - if/else, loops, functions](./0x01-python-if_else_loops_functions) 12 | * [0x02. Python - import & modules](./0x02-python-import_modules) 13 | * [0x03. Python - Data structures](./0x03-python-data_structures) 14 | * [0x04. Python - More Data structures](./0x04-python-more_data_structures) 15 | --------------------------------------------------------------------------------