From 3b8cef1d11de80ec9f8bca6529eceb87b63f35a2 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 29 Jul 2020 14:54:27 -0400 Subject: [PATCH 01/65] Exercises completed --- .../1_creating_a_repository/Solution/solution.py | 2 +- .../git/1_remote_repository/Solution/solution.py | 2 +- .../git/1_staging_area/Solution/solution.py | 2 +- .../git/1_update_code/Solution/solution.py | 2 +- .../hello_world/1_arithmetic/solution/solution.py | 8 ++++++++ .../1_concantenation/Solution/solution.py | 4 ++++ .../1_name_bindings/solution/solution.py | 3 +++ .../hello_world/1_operators/solution/solution.py | 2 ++ .../2_capture_display/Solution/solution.py | 5 +++++ .../2_python_caches/solution/solution.py | 4 ++-- .../2_string_arithmetic/solution/solution.py | 5 +++++ .../2_string_duplication/Solution/solution.py | 4 ++++ .../hello_world/2_type_check/Solution/solution.py | 8 ++++++++ .../hello_world/3_type_change/Solution/solution.py | 5 +++++ .../hello_world/3_user_input/solution/solution.py | 6 ++++++ .../1_basic_commands/solution/solution.py | 12 ++++++------ .../1_commands_with_options/solution/solution.py | 14 +++++++------- .../1_commands_with_options_2/solution/solution.py | 12 ++++++------ .../2_bash_commands/solution/solution.py | 6 +++--- .../2_bash_operators/solution/solution.py | 10 +++++----- 20 files changed, 83 insertions(+), 33 deletions(-) diff --git a/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py b/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py index cccdee23..e7abe60c 100644 --- a/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py +++ b/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'a' diff --git a/introduction_and_environment/git/1_remote_repository/Solution/solution.py b/introduction_and_environment/git/1_remote_repository/Solution/solution.py index cccdee23..482a5499 100644 --- a/introduction_and_environment/git/1_remote_repository/Solution/solution.py +++ b/introduction_and_environment/git/1_remote_repository/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'd' diff --git a/introduction_and_environment/git/1_staging_area/Solution/solution.py b/introduction_and_environment/git/1_staging_area/Solution/solution.py index cccdee23..b8eb8f57 100644 --- a/introduction_and_environment/git/1_staging_area/Solution/solution.py +++ b/introduction_and_environment/git/1_staging_area/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'c' diff --git a/introduction_and_environment/git/1_update_code/Solution/solution.py b/introduction_and_environment/git/1_update_code/Solution/solution.py index cccdee23..ca9c8ca8 100644 --- a/introduction_and_environment/git/1_update_code/Solution/solution.py +++ b/introduction_and_environment/git/1_update_code/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'b' diff --git a/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py b/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py index 217b5003..5c4e4332 100644 --- a/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py +++ b/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py @@ -1 +1,9 @@ from provided_code import x, y + +SUM = x + y +DIFF = x - y +MULT = x * y +DIV = x / y +POWER = x ** y +QUOTIENT = x // y +REMAINDER = x % y diff --git a/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py b/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py index ade03179..4f39a9d5 100644 --- a/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py +++ b/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_1 = "hello" +string_2 = "world!" +result = string_1 + string_2 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py b/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py index ade03179..6b02d8a7 100644 --- a/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py +++ b/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py @@ -1 +1,4 @@ # Code your solution here +x = 1337 +y = "hello world" +z = 13.5 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/1_operators/solution/solution.py b/introduction_and_environment/hello_world/1_operators/solution/solution.py index ade03179..f247d49c 100644 --- a/introduction_and_environment/hello_world/1_operators/solution/solution.py +++ b/introduction_and_environment/hello_world/1_operators/solution/solution.py @@ -1 +1,3 @@ # Code your solution here +x = 11 +y = 10 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py index ade03179..69d7ac2b 100644 --- a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +name = input("Enter your name:") +age = input("Enter your age:") + +print(name) +print(age) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_python_caches/solution/solution.py b/introduction_and_environment/hello_world/2_python_caches/solution/solution.py index 45a087b6..3e9db70e 100644 --- a/introduction_and_environment/hello_world/2_python_caches/solution/solution.py +++ b/introduction_and_environment/hello_world/2_python_caches/solution/solution.py @@ -1,2 +1,2 @@ -LOWER_BOUND = 0 -UPPER_BOUND = 0 +LOWER_BOUND = -5 +UPPER_BOUND = 256 diff --git a/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py b/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py index ade03179..92feda11 100644 --- a/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py +++ b/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py @@ -1 +1,6 @@ # Code your solution here +x = 'Hello' +y = 'World!' +z = 3 + +STR_ARITHMETIC = 2 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py b/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py index ade03179..123ed16b 100644 --- a/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_1 = 'Charlie' +dup_val = 5 +result = string_1 * dup_val +print(result) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_type_check/Solution/solution.py b/introduction_and_environment/hello_world/2_type_check/Solution/solution.py index 0ec5aa42..8e231d8e 100644 --- a/introduction_and_environment/hello_world/2_type_check/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_type_check/Solution/solution.py @@ -1 +1,9 @@ # Code your solution here... +input_1 = input("Store any data type value:") +input_2 = input("Store any other data type value:") + +result_1 = type(input_1) +result_2 = type(input_2) + +print(result_1) +print(result_2) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py index ade03179..428645c2 100644 --- a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +object_1 = 3.2 +object_2 = 2 + +print(str(object_1)) +print(int(object_2)) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/3_user_input/solution/solution.py b/introduction_and_environment/hello_world/3_user_input/solution/solution.py index ade03179..79af3166 100644 --- a/introduction_and_environment/hello_world/3_user_input/solution/solution.py +++ b/introduction_and_environment/hello_world/3_user_input/solution/solution.py @@ -1 +1,7 @@ # Code your solution here +first_num = input("State one number:") +second_num = input("State another number:") +third_num = input("State a third number:") + +result = (first_num * second_num * third_num) / 3 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py index a19ce0a0..0373a93d 100644 --- a/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py @@ -2,9 +2,9 @@ ONE = 'man' # Assign the correct strings below -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' -SEVEN = '' +TWO = 'ls' +THREE = 'mkdir' +FOUR = 'touch' +FIVE = 'cp' +SIX = 'mv' +SEVEN = 'rm' \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py index fa9fd397..b904358d 100644 --- a/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py @@ -1,9 +1,9 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' -SEVEN = '' +ONE = 'cd exercises' +TWO = 'pwd' +THREE = 'cat textfile.txt' +FOUR = 'tail textfile.txt' +FIVE = 'ls -a' +SIX = 'head textfile.txt' +SEVEN = 'cp stackdata.json stockdata.json' \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py index fa9fd397..30820b11 100644 --- a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py @@ -1,9 +1,9 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' +ONE = 'grep elephant book.txt' +TWO = 'mv notes.txt newdir' +THREE = 'grep -r string testdir' +FOUR = 'rm empty' +FIVE = 'cd' +SIX = 'rm -r Downloads' SEVEN = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py index fa9fd397..27a67e60 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' +ONE = 'mkdir testdir | cd testdir' +TWO = 'grep and textfile.txt' +THREE = 'grep -r >> contents.txt' FOUR = '' FIVE = '' SIX = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index f34e86b6..cc3e9e7a 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -1,7 +1,7 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' +ONE = 'mkdir testdir && cd testdir' +TWO = 'grep and textfile.txt' +THREE = 'grep -r >> contents.txt' +FOUR = 'cd current > current' +FIVE = 'ls > currentpath.txt' From 35695464c044a73f38b8f6160fb9d1426e59a2f0 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 30 Jul 2020 14:32:45 -0400 Subject: [PATCH 02/65] Exercises completed --- .../hello_world/3_type_change/Solution/solution.py | 2 +- .../1_DNS/solution/solution.py | 4 +++- .../1_architecture/solution/solution.py | 1 + .../1_bytes/solution/solution.py | 1 + .../1_languages/solution/solution.py | 3 ++- .../2_ASCII/Solutions/solution.py | 1 + .../2_operators/Solutions/solution.py | 1 + .../3_bitwise_operators_1/Solutions/solution.py | 14 ++++++++++++++ .../3_bitwise_operators_2/Solutions/solution.py | 10 ++++++++++ .../3_logical_operators_1/Solutions/solution.py | 6 ++++++ .../2_bash_commands/solution/solution.py | 6 +++--- .../2_bash_operators/solution/solution.py | 8 ++++---- .../3_star_wars/millenium_falcon/chewbacca.txt | 0 .../3_star_wars/millenium_falcon/han_solo.txt | 0 .../3_star_wars/the_rebellion/leia_organa.txt | 0 .../3_star_wars/tie_fighter/darth_vader.txt | 1 + .../3_star_wars/x_wing/luke_skywalker.txt | 0 17 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py index 428645c2..1480c6f8 100644 --- a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -1,6 +1,6 @@ # Code your solution here object_1 = 3.2 -object_2 = 2 +object_2 = '2' print(str(object_1)) print(int(object_2)) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py index ee95bbbb..fee1b0e9 100644 --- a/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py @@ -1 +1,3 @@ -# Code your solution below \ No newline at end of file +# Code your solution below + +print('Domain Name System') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py index abe91ec3..7ef8b2ba 100644 --- a/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py @@ -1 +1,2 @@ # Code your solution below +print('a.John Von Neuman') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py index abe91ec3..63bab332 100644 --- a/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py @@ -1 +1,2 @@ # Code your solution below +print('Gigabyte') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py index ee95bbbb..38b0c3cd 100644 --- a/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py @@ -1 +1,2 @@ -# Code your solution below \ No newline at end of file +# Code your solution below +print('Interpreter') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index e69de29b..279d1501 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -0,0 +1 @@ +print('Hexadecimal') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index e69de29b..f37988b4 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -0,0 +1 @@ +print('Boolean') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index e69de29b..378ee449 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -0,0 +1,14 @@ +x = 0 +y = 1 + +x & y = 0 +x | y = 1 +~ x, ~ y = 1, 0 + +Answer_and = 0 +Answer_or = 1 +Answer_not = 1, 0 + +print(Answer_and) +print(Answer_or) +print(Answer_not) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py index e69de29b..b3ac89c3 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py @@ -0,0 +1,10 @@ +x = 1 +y = 1 + +Answer_Xor = x ^ y +Answer_right_shift = x >> y +Answer_left_shift = x << y + +print(Answer_Xor) +print(Answer_right_shift) +print(Answer_left_shift) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py index e69de29b..c06b7320 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py @@ -0,0 +1,6 @@ +x = True +y = False + +Answer = bool(x and y) + +print(Answer) \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py index 27a67e60..fa9fd397 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = 'mkdir testdir | cd testdir' -TWO = 'grep and textfile.txt' -THREE = 'grep -r >> contents.txt' +ONE = '' +TWO = '' +THREE = '' FOUR = '' FIVE = '' SIX = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index cc3e9e7a..01c1d34c 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -1,7 +1,7 @@ # Assign the correct strings below ONE = 'mkdir testdir && cd testdir' -TWO = 'grep and textfile.txt' -THREE = 'grep -r >> contents.txt' -FOUR = 'cd current > current' -FIVE = 'ls > currentpath.txt' +TWO = 'cat textfile.txt | grep and' +THREE = 'ls >> contents.txt' +FOUR = 'cd current || mkdir current' +FIVE = 'pwd > currentpath.txt' diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt b/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt b/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt b/introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt b/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt new file mode 100644 index 00000000..3df9b92b --- /dev/null +++ b/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt @@ -0,0 +1 @@ +Darth Vader diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt b/introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt new file mode 100644 index 00000000..e69de29b From 39354d0e1fa0fbb5999b2112a32ab6a78f665f82 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 30 Jul 2020 20:11:09 -0400 Subject: [PATCH 03/65] Completed Exercises --- .../1_compare_check/Solution/solution.py | 5 +++++ .../1_even_odd/Solution/solution.py | 9 +++++++++ .../1_loop_divisibility/Solution/solution.py | 4 +++- .../1_string_convert/Solution/solution.py | 7 +++++++ .../1_string_length/Solution/solution.py | 3 +++ .../1_string_slice/Solution/solution.py | 4 ++++ .../2_add_item/Solution/solution.py | 4 ++++ .../2_append/Solution/solution.py | 3 +++ .../2_farm_area/Solution/solution.py | 5 +++++ .../2_remove_item/Solution/solution.py | 4 ++++ .../2_sum_list/Solution/solution.py | 3 +++ .../3_bitwise_operators_1/Solutions/solution.py | 9 +++------ .../3_logical_operators_2/Solutions/solution.py | 3 +++ 13 files changed, 56 insertions(+), 7 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py index ade03179..63f1d036 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +x = 200 +y = 201 + +result = x and y +print(bool(result)) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py index ade03179..9529b438 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +number = int(input()) +def Data(number): + if number % 2 == 0: + return Even + else: + return Odd + + +print(Data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py index cbc031aa..0d7bc458 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py @@ -1,2 +1,4 @@ # Code your solution here - \ No newline at end of file +for x in range(0, 51): + if x % 5 == 0 or x % 7 == 0: + print(x) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py index ade03179..ffd1a53e 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py @@ -1 +1,8 @@ # Code your solution here +string = str(input()) +def data(string): + if string.isupper(): + string.lower + else: + string.upper +print(data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py index ade03179..62059e37 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +string_1 = str(input()) +data = len(string_1) +print(data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py index ade03179..2f4be347 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_value = 'Hello Universe' +data = string_value[0:5] +data_val = data + 'World' +print(data_val) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py index ade03179..2e0a6d46 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +dict_a = {} +dict_a["key1"] = 2 +dict_val = dict_a +print(dict_val) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py index ade03179..2eef5e26 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_a = [] +list_b = list_a.append(3) +print(list_b) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index ade03179..294932c9 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +length = 6 +breadth = 4 + +data = length * breadth +print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py index ade03179..ab77c215 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +list_1 = [] +lister = list_1.remove() + +print(lister) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py index ade03179..8115ca30 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_a = [] +total = sum(list_a) +print(total) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index 378ee449..fbf8bbd8 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -1,13 +1,10 @@ x = 0 y = 1 -x & y = 0 -x | y = 1 -~ x, ~ y = 1, 0 -Answer_and = 0 -Answer_or = 1 -Answer_not = 1, 0 +Answer_and = x & y +Answer_or = x | y +Answer_not = ~ x print(Answer_and) print(Answer_or) diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index e69de29b..8d596bdc 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -0,0 +1,3 @@ +x = 1 +y = 2 + From d536594f57b40a0ff66468064899bc12f9e42907 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 11:10:49 -0400 Subject: [PATCH 04/65] Pushing exercises --- .../1_list_max/solution/solution.py | 11 +++++++++++ .../2_except_letter/Solution/solution.py | 10 ++++++++++ .../2_vowel_consonant/Solution/solution.py | 12 ++++++++++++ .../3_grade/Solution/solution.py | 19 +++++++++++++++++++ .../3_set_difference/Solution/solution.py | 4 ++++ .../3_string_case/Solution/solution.py | 6 ++++++ 6 files changed, 62 insertions(+) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index e69de29b..31afbb01 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -0,0 +1,11 @@ +L = [152, 463, 1112, 1337, -10] +# def LIST_MAX(L): +# if L == []: +# LIST_MAX1 = None +# else: +# LIST_MAX1 = sorted(L)[-1] +# return LIST_MAX1 + +# print(LIST_MAX(L)) +LIST_MAX = sorted(L)[-1] +# print(LIST_MAX) diff --git a/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py index ade03179..e09d2c29 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py @@ -1 +1,11 @@ # Code your solution here +string = 'BYTE ACADEMY' +vowels = ['A', 'E', 'I', 'O', 'U'] +def data(x): + ans = False + for characters in string: + if characters != vowels: + ans = True + return ans +print(data) + \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py index ade03179..a00455dd 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py @@ -1 +1,13 @@ # Code your solution here +vowels = ['a', 'e', 'i', 'o', 'u'] +consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'] +letter = input() + +def data(x): + for characters in letter: + if characters == vowels: + return vowel + elif characters == consonants: + return consonant + +print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index ade03179..3389f4e0 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1 +1,20 @@ # Code your solution here +def grade(mark): + if mark >= 90: + # return 'A+ GRADE' + print('A+ GRADE') + elif mark >= 70: + # return 'B GRADE' + print('B GRADE') + elif mark >= 50: + # return 'C GRADE' + print('C GRADE') + elif mark >= 35: + # return 'D GRADE' + print('D GRADE') + else: + # return 'FAIL' + print('FAIL') +score = int(input("Enter your grade here:")) +print(grade(score)) +# grade(score) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py index ade03179..e13ac0ba 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +set_1 = set() +set_2 = set() +result = set_1 - set_2 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index ade03179..50b2220f 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1 +1,7 @@ # Code your solution here +string_val = str(input()) +upper_data = string_val.upper() +lower_data = string_val.lower() + +print(upper_data) +print(lower_data) \ No newline at end of file From 9784d40d43ae968607c4ee1d008f6e1715a27610 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 11:32:37 -0400 Subject: [PATCH 05/65] Completed --- .../3_count_duplicate/Solution/solution.py | 3 +++ .../3_grade/Solution/solution.py | 20 ++++++++----------- .../3_string_case/Solution/solution.py | 1 + .../2_ASCII/Solutions/solution.py | 3 ++- .../2_operators/Solutions/solution.py | 3 ++- .../Solutions/solution.py | 7 +++++-- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py index ade03179..e12307d6 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_dup = [] +tot = list_dup.count +print(tot) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index 3389f4e0..cc177132 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1,20 +1,16 @@ # Code your solution here def grade(mark): if mark >= 90: - # return 'A+ GRADE' - print('A+ GRADE') + return 'A+ GRADE' elif mark >= 70: - # return 'B GRADE' - print('B GRADE') + return 'B GRADE' elif mark >= 50: - # return 'C GRADE' - print('C GRADE') + return 'C GRADE' elif mark >= 35: - # return 'D GRADE' - print('D GRADE') + return 'D GRADE' else: - # return 'FAIL' - print('FAIL') -score = int(input("Enter your grade here:")) -print(grade(score)) + return 'FAIL' +# score = int(input("Enter your grade here:")) +mark = 80 +print(grade(mark)) # grade(score) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index 50b2220f..0c9227fb 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1,5 +1,6 @@ # Code your solution here string_val = str(input()) + upper_data = string_val.upper() lower_data = string_val.lower() diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index 279d1501..117c7cd9 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -1 +1,2 @@ -print('Hexadecimal') \ No newline at end of file +# print('Hexadecimal') +print('Boolean') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index f37988b4..e983d85b 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -1 +1,2 @@ -print('Boolean') \ No newline at end of file +# print('Boolean') +print('Hexadecimal') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index 8d596bdc..3cfc611d 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -1,3 +1,6 @@ -x = 1 -y = 2 +x = True +y = False +Answer = bool(x or y) + +print(Answer) \ No newline at end of file From f07cce675b51ee39b0fd16aeb26541dfbf8612ff Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 16:53:18 -0400 Subject: [PATCH 06/65] Completed --- .../1_list_max/solution/solution.py | 26 ++++++++++++------- .../2_farm_area/Solution/solution.py | 3 ++- .../3_month_days/Solution/solution.py | 9 +++++++ .../3_palindrome/Solution/solution.py | 8 ++++++ .../3_shape_check/Solution/solution.py | 9 +++++++ 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index 31afbb01..a3cd5df7 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -1,11 +1,19 @@ -L = [152, 463, 1112, 1337, -10] -# def LIST_MAX(L): -# if L == []: -# LIST_MAX1 = None -# else: -# LIST_MAX1 = sorted(L)[-1] -# return LIST_MAX1 +# L = [152, 463, 1112, 1337, -10] +# LIST_MAX = sorted(L)[-1] # print(LIST_MAX(L)) -LIST_MAX = sorted(L)[-1] -# print(LIST_MAX) + +L = [152, 463, 1112, 1337, -10] +def LIST_MAX1(L): + current_max = L[0] + if L[1] > current_max: + current_max = L[1] + if L[2] > current_max: + current_max = L[2] + if L[3] > current_max: + current_max = L[3] + if L[4] > current_max: + current_max = L[4] + return current_max +LIST_MAX = LIST_MAX1(L) + diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index 294932c9..47344e65 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1,6 +1,7 @@ # Code your solution here +# length = len(input()) +# breadth = len(input()) length = 6 breadth = 4 - data = length * breadth print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py index ade03179..678676a5 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +month = input('Enter any month:') +month_dict = {'january':'31', 'february':'28, 29', 'march':'31', 'april':'30', 'may':'31', 'june':'30', 'july':'31', 'august':'31','september':'30', 'october':'31', 'november':'30', 'december':'31'} +def data(month): + if month in month_dict.keys(): + return month_dict[month] + else: + return None + +print(data(month)) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py index ade03179..b85e38d8 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py @@ -1 +1,9 @@ # Code your solution here +line = input('Enter any string value:') + +if line == line[::-1]: + is_palindrome = True +else: + is_palindrome = False + +print(is_palindrome) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py index ade03179..2b897c95 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +figure = input('Enter any geometric shape value:') +my_dict = {'3':'Triangle', '4':'Quadrilateral', '5':'Pentagon', '6':'Hexagon', '7':'Heptagon', '8':'Octagon', '9':'Nonagon'} + +def data(figure): + if figure in my_dict: + return my_dict[figure] + else: + return 'None' +print(data(figure)) \ No newline at end of file From 6cffc719b5c5c4fdcedf9e303c3a12e35106c10b Mon Sep 17 00:00:00 2001 From: PC-coding Date: Sun, 2 Aug 2020 15:00:48 -0400 Subject: [PATCH 07/65] Completed Exercises --- .DS_Store | Bin 0 -> 6148 bytes .../1_list_max/solution/solution.py | 3 +-- .../functions/1_range/Solution/solution.py | 10 ++++++++++ .../1_return_hello/Solution/solution.py | 7 +++++++ .../functions/2_max_value/Solution/solution.py | 10 ++++++++++ .../functions/2_shut_down/Solution/solution.py | 11 +++++++++++ .../2_variable_argument/Solution/solution.py | 4 ++++ .../functions/3_anonymous/Solution/solution.py | 4 ++++ .../functions/3_count_even/Solution/solution.py | 4 ++++ .../functions/3_factorial/Solution/solution.py | 11 +++++++++++ .../functions/3_total/Solution/solution.py | 11 +++++++++++ 11 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..689e5e94266dbf9be05223eb9f20bdf3f316910d GIT binary patch literal 6148 zcmeHKO>Wab6n@hNaDq^>K!gPgZ;)72C>4P&Dx@@|i!P85L9hUn+O=scIiARN8l@q~ z8}3k!z)iRT2jKwly_o?ePRp(c&^+nQ_vYt&qxo#lc!)@JC&4yRgNPhBW2J`T9OHiW zHQO*P+$mI!lp@M$NF&PDM%xCffK}jcQ-HtS8hI4cF-cnbeh*@KN zUTnGZot+lPj~0un)4aR=_~39fJDtB@d^l69A%Xo%S>51I_=MnGeNOsm63gTm{miXX z02Ooi0DE5!B`0(QoFED*E2;SzjAb?NVBbs>OCpbEMtB|xvUw;2UdWZZ|tb%nI zsJTM4rZih+t2gXy=?z0NYnQ5kdFP$$mpY40ZWXW!{EG_k{@}tHI|d7lYU@Cut^mLa znw25u-v#El20I1|jp%_1O$BPIFjowr>1cP&xQ@X>qo$KEmk(iP7UqT`)a=Obs^KI$ z8f|G6unMdyu&JvJKL7VGzW=Y1Y|ScQ75J|d5S3oP*Ts^|*}AqkK5Je0A)JlJ6&e)< jg*lE@z(?_IxH9y)8~{583yo-j*&hKVgDtEAe^h}V*0i{c literal 0 HcmV?d00001 diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index a3cd5df7..84e25b8d 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -15,5 +15,4 @@ def LIST_MAX1(L): if L[4] > current_max: current_max = L[4] return current_max -LIST_MAX = LIST_MAX1(L) - +LIST_MAX = LIST_MAX1(L) \ No newline at end of file diff --git a/introduction_to_python/functions/1_range/Solution/solution.py b/introduction_to_python/functions/1_range/Solution/solution.py index ade03179..6a92314c 100644 --- a/introduction_to_python/functions/1_range/Solution/solution.py +++ b/introduction_to_python/functions/1_range/Solution/solution.py @@ -1 +1,11 @@ # Code your solution here + +# number = int(input('Enter any integer value:')) +number = 99 +def result(number): + if number <= 100: + return 'GREATNESS' + else: + return 'OOPS' + +print(result(number)) \ No newline at end of file diff --git a/introduction_to_python/functions/1_return_hello/Solution/solution.py b/introduction_to_python/functions/1_return_hello/Solution/solution.py index ade03179..f3e68358 100644 --- a/introduction_to_python/functions/1_return_hello/Solution/solution.py +++ b/introduction_to_python/functions/1_return_hello/Solution/solution.py @@ -1 +1,8 @@ # Code your solution here +# name = input('Enter your name: ') +name = 'Newton' +def result(name): + val1 = 'Hello' + name + return val1 + +print(result(name)) \ No newline at end of file diff --git a/introduction_to_python/functions/2_max_value/Solution/solution.py b/introduction_to_python/functions/2_max_value/Solution/solution.py index ade03179..cf92f9d9 100644 --- a/introduction_to_python/functions/2_max_value/Solution/solution.py +++ b/introduction_to_python/functions/2_max_value/Solution/solution.py @@ -1 +1,11 @@ # Code your solution here +# a = int(input('Enter an integer value: ')) +# b = int(input('Enter another integer value: ')) +# c = int(input('Enter one last integer value: ')) +a = 1 +b = 2 +c = 3 +def result(a, b, c): + max_value = max(a, b, c) + return max_value +print(result(a, b, c)) diff --git a/introduction_to_python/functions/2_shut_down/Solution/solution.py b/introduction_to_python/functions/2_shut_down/Solution/solution.py index ade03179..d341aa64 100644 --- a/introduction_to_python/functions/2_shut_down/Solution/solution.py +++ b/introduction_to_python/functions/2_shut_down/Solution/solution.py @@ -1 +1,12 @@ # Code your solution here +# x = bool(input('Enter a boolean value: ')) +x = 'false' +def data(x): + if x == True: + return 'SHUTDOWN' + elif x == False: + return 'SHUTDOWN ABORTED' + else: + return 'This is not a boolean value.' +result = data(x) +print(result) \ No newline at end of file diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index ade03179..f389e9b0 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +def f(*args): + return sum(args) +result = f +print(result) \ No newline at end of file diff --git a/introduction_to_python/functions/3_anonymous/Solution/solution.py b/introduction_to_python/functions/3_anonymous/Solution/solution.py index ade03179..51abb9ed 100644 --- a/introduction_to_python/functions/3_anonymous/Solution/solution.py +++ b/introduction_to_python/functions/3_anonymous/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +def f(*args): + return list(map(lambda x: x % 13 == 0)) +result = f +print(result) \ No newline at end of file diff --git a/introduction_to_python/functions/3_count_even/Solution/solution.py b/introduction_to_python/functions/3_count_even/Solution/solution.py index ade03179..bee6f9e0 100644 --- a/introduction_to_python/functions/3_count_even/Solution/solution.py +++ b/introduction_to_python/functions/3_count_even/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +def f(*args): + return list(map(lambda x: x % 2== 0)) +result = f +print(result) \ No newline at end of file diff --git a/introduction_to_python/functions/3_factorial/Solution/solution.py b/introduction_to_python/functions/3_factorial/Solution/solution.py index ade03179..4c95b8b3 100644 --- a/introduction_to_python/functions/3_factorial/Solution/solution.py +++ b/introduction_to_python/functions/3_factorial/Solution/solution.py @@ -1 +1,12 @@ # Code your solution here +# n = int(input(Enter any integer: )) +n = 4 + +def numbers(n): + factorial = 1 + if int(n) >= 1: + for i in range(1, int(n) + 1): + factorial = factorial * i + +result = numbers(n) +print(result) \ No newline at end of file diff --git a/introduction_to_python/functions/3_total/Solution/solution.py b/introduction_to_python/functions/3_total/Solution/solution.py index ade03179..87550786 100644 --- a/introduction_to_python/functions/3_total/Solution/solution.py +++ b/introduction_to_python/functions/3_total/Solution/solution.py @@ -1 +1,12 @@ # Code your solution here +l = [10, 20, 30, 40, 50, 60] +# l = [1, 2, 3, 4, 5] +# used the list provided in test_solution.py for the test to work + +def a_list(l): + summ = 0 + for i in l: + summ += i + return summ +result = a_list(l) +print(result) \ No newline at end of file From b45b321e9ba4e515a32b73f55e49d05b1b0621f2 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 3 Aug 2020 13:17:08 -0400 Subject: [PATCH 08/65] Working on these --- .../recursive_functions/1_array_sum/solutions/solution.py | 2 ++ .../recursive_functions/1_count_down/solutions/solution.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py index aeb50baa..4ee6cf73 100644 --- a/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py +++ b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py @@ -1 +1,3 @@ # Write your solution here +def sum_array(num_list): + return 0 if num_list == [] else num_list[0] + sum_array(num_list[1:]) diff --git a/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py b/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py index aeb50baa..4342bf27 100644 --- a/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py +++ b/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py @@ -1 +1,5 @@ # Write your solution here +def count_down_from(num): + return num + if num >= 1: + count_down_from(num - 1) \ No newline at end of file From 7cf72fe19cd2321f666765c076fb0db0cabfa461 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 29 Jul 2020 14:54:27 -0400 Subject: [PATCH 09/65] Exercises completed --- .../1_creating_a_repository/Solution/solution.py | 2 +- .../git/1_remote_repository/Solution/solution.py | 2 +- .../git/1_staging_area/Solution/solution.py | 2 +- .../git/1_update_code/Solution/solution.py | 2 +- .../hello_world/1_arithmetic/solution/solution.py | 8 ++++++++ .../1_concantenation/Solution/solution.py | 4 ++++ .../1_name_bindings/solution/solution.py | 3 +++ .../hello_world/1_operators/solution/solution.py | 2 ++ .../2_capture_display/Solution/solution.py | 5 +++++ .../2_python_caches/solution/solution.py | 4 ++-- .../2_string_arithmetic/solution/solution.py | 5 +++++ .../2_string_duplication/Solution/solution.py | 4 ++++ .../hello_world/2_type_check/Solution/solution.py | 8 ++++++++ .../hello_world/3_type_change/Solution/solution.py | 5 +++++ .../hello_world/3_user_input/solution/solution.py | 6 ++++++ .../1_basic_commands/solution/solution.py | 12 ++++++------ .../1_commands_with_options/solution/solution.py | 14 +++++++------- .../1_commands_with_options_2/solution/solution.py | 12 ++++++------ .../2_bash_commands/solution/solution.py | 6 +++--- .../2_bash_operators/solution/solution.py | 10 +++++----- 20 files changed, 83 insertions(+), 33 deletions(-) diff --git a/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py b/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py index cccdee23..e7abe60c 100644 --- a/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py +++ b/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'a' diff --git a/introduction_and_environment/git/1_remote_repository/Solution/solution.py b/introduction_and_environment/git/1_remote_repository/Solution/solution.py index cccdee23..482a5499 100644 --- a/introduction_and_environment/git/1_remote_repository/Solution/solution.py +++ b/introduction_and_environment/git/1_remote_repository/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'd' diff --git a/introduction_and_environment/git/1_staging_area/Solution/solution.py b/introduction_and_environment/git/1_staging_area/Solution/solution.py index cccdee23..b8eb8f57 100644 --- a/introduction_and_environment/git/1_staging_area/Solution/solution.py +++ b/introduction_and_environment/git/1_staging_area/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'c' diff --git a/introduction_and_environment/git/1_update_code/Solution/solution.py b/introduction_and_environment/git/1_update_code/Solution/solution.py index cccdee23..ca9c8ca8 100644 --- a/introduction_and_environment/git/1_update_code/Solution/solution.py +++ b/introduction_and_environment/git/1_update_code/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'b' diff --git a/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py b/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py index 217b5003..5c4e4332 100644 --- a/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py +++ b/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py @@ -1 +1,9 @@ from provided_code import x, y + +SUM = x + y +DIFF = x - y +MULT = x * y +DIV = x / y +POWER = x ** y +QUOTIENT = x // y +REMAINDER = x % y diff --git a/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py b/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py index ade03179..4f39a9d5 100644 --- a/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py +++ b/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_1 = "hello" +string_2 = "world!" +result = string_1 + string_2 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py b/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py index ade03179..6b02d8a7 100644 --- a/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py +++ b/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py @@ -1 +1,4 @@ # Code your solution here +x = 1337 +y = "hello world" +z = 13.5 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/1_operators/solution/solution.py b/introduction_and_environment/hello_world/1_operators/solution/solution.py index ade03179..f247d49c 100644 --- a/introduction_and_environment/hello_world/1_operators/solution/solution.py +++ b/introduction_and_environment/hello_world/1_operators/solution/solution.py @@ -1 +1,3 @@ # Code your solution here +x = 11 +y = 10 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py index ade03179..69d7ac2b 100644 --- a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +name = input("Enter your name:") +age = input("Enter your age:") + +print(name) +print(age) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_python_caches/solution/solution.py b/introduction_and_environment/hello_world/2_python_caches/solution/solution.py index 45a087b6..3e9db70e 100644 --- a/introduction_and_environment/hello_world/2_python_caches/solution/solution.py +++ b/introduction_and_environment/hello_world/2_python_caches/solution/solution.py @@ -1,2 +1,2 @@ -LOWER_BOUND = 0 -UPPER_BOUND = 0 +LOWER_BOUND = -5 +UPPER_BOUND = 256 diff --git a/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py b/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py index ade03179..92feda11 100644 --- a/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py +++ b/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py @@ -1 +1,6 @@ # Code your solution here +x = 'Hello' +y = 'World!' +z = 3 + +STR_ARITHMETIC = 2 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py b/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py index ade03179..123ed16b 100644 --- a/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_1 = 'Charlie' +dup_val = 5 +result = string_1 * dup_val +print(result) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_type_check/Solution/solution.py b/introduction_and_environment/hello_world/2_type_check/Solution/solution.py index 0ec5aa42..8e231d8e 100644 --- a/introduction_and_environment/hello_world/2_type_check/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_type_check/Solution/solution.py @@ -1 +1,9 @@ # Code your solution here... +input_1 = input("Store any data type value:") +input_2 = input("Store any other data type value:") + +result_1 = type(input_1) +result_2 = type(input_2) + +print(result_1) +print(result_2) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py index ade03179..428645c2 100644 --- a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +object_1 = 3.2 +object_2 = 2 + +print(str(object_1)) +print(int(object_2)) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/3_user_input/solution/solution.py b/introduction_and_environment/hello_world/3_user_input/solution/solution.py index ade03179..79af3166 100644 --- a/introduction_and_environment/hello_world/3_user_input/solution/solution.py +++ b/introduction_and_environment/hello_world/3_user_input/solution/solution.py @@ -1 +1,7 @@ # Code your solution here +first_num = input("State one number:") +second_num = input("State another number:") +third_num = input("State a third number:") + +result = (first_num * second_num * third_num) / 3 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py index a19ce0a0..0373a93d 100644 --- a/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py @@ -2,9 +2,9 @@ ONE = 'man' # Assign the correct strings below -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' -SEVEN = '' +TWO = 'ls' +THREE = 'mkdir' +FOUR = 'touch' +FIVE = 'cp' +SIX = 'mv' +SEVEN = 'rm' \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py index fa9fd397..b904358d 100644 --- a/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py @@ -1,9 +1,9 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' -SEVEN = '' +ONE = 'cd exercises' +TWO = 'pwd' +THREE = 'cat textfile.txt' +FOUR = 'tail textfile.txt' +FIVE = 'ls -a' +SIX = 'head textfile.txt' +SEVEN = 'cp stackdata.json stockdata.json' \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py index fa9fd397..30820b11 100644 --- a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py @@ -1,9 +1,9 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' +ONE = 'grep elephant book.txt' +TWO = 'mv notes.txt newdir' +THREE = 'grep -r string testdir' +FOUR = 'rm empty' +FIVE = 'cd' +SIX = 'rm -r Downloads' SEVEN = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py index fa9fd397..27a67e60 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' +ONE = 'mkdir testdir | cd testdir' +TWO = 'grep and textfile.txt' +THREE = 'grep -r >> contents.txt' FOUR = '' FIVE = '' SIX = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index f34e86b6..cc3e9e7a 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -1,7 +1,7 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' +ONE = 'mkdir testdir && cd testdir' +TWO = 'grep and textfile.txt' +THREE = 'grep -r >> contents.txt' +FOUR = 'cd current > current' +FIVE = 'ls > currentpath.txt' From 8b554785e825dada1e30e38634902a87935b2e8a Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 30 Jul 2020 14:32:45 -0400 Subject: [PATCH 10/65] Exercises completed --- .../hello_world/3_type_change/Solution/solution.py | 2 +- .../1_DNS/solution/solution.py | 4 +++- .../1_architecture/solution/solution.py | 1 + .../1_bytes/solution/solution.py | 1 + .../1_languages/solution/solution.py | 3 ++- .../2_ASCII/Solutions/solution.py | 1 + .../2_operators/Solutions/solution.py | 1 + .../3_bitwise_operators_1/Solutions/solution.py | 14 ++++++++++++++ .../3_bitwise_operators_2/Solutions/solution.py | 10 ++++++++++ .../3_logical_operators_1/Solutions/solution.py | 6 ++++++ .../2_bash_commands/solution/solution.py | 6 +++--- .../2_bash_operators/solution/solution.py | 8 ++++---- .../3_star_wars/millenium_falcon/chewbacca.txt | 0 .../3_star_wars/millenium_falcon/han_solo.txt | 0 .../3_star_wars/the_rebellion/leia_organa.txt | 0 .../3_star_wars/tie_fighter/darth_vader.txt | 1 + .../3_star_wars/x_wing/luke_skywalker.txt | 0 17 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py index 428645c2..1480c6f8 100644 --- a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -1,6 +1,6 @@ # Code your solution here object_1 = 3.2 -object_2 = 2 +object_2 = '2' print(str(object_1)) print(int(object_2)) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py index ee95bbbb..fee1b0e9 100644 --- a/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py @@ -1 +1,3 @@ -# Code your solution below \ No newline at end of file +# Code your solution below + +print('Domain Name System') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py index abe91ec3..7ef8b2ba 100644 --- a/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py @@ -1 +1,2 @@ # Code your solution below +print('a.John Von Neuman') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py index abe91ec3..63bab332 100644 --- a/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py @@ -1 +1,2 @@ # Code your solution below +print('Gigabyte') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py index ee95bbbb..38b0c3cd 100644 --- a/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py @@ -1 +1,2 @@ -# Code your solution below \ No newline at end of file +# Code your solution below +print('Interpreter') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index e69de29b..279d1501 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -0,0 +1 @@ +print('Hexadecimal') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index e69de29b..f37988b4 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -0,0 +1 @@ +print('Boolean') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index e69de29b..378ee449 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -0,0 +1,14 @@ +x = 0 +y = 1 + +x & y = 0 +x | y = 1 +~ x, ~ y = 1, 0 + +Answer_and = 0 +Answer_or = 1 +Answer_not = 1, 0 + +print(Answer_and) +print(Answer_or) +print(Answer_not) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py index e69de29b..b3ac89c3 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py @@ -0,0 +1,10 @@ +x = 1 +y = 1 + +Answer_Xor = x ^ y +Answer_right_shift = x >> y +Answer_left_shift = x << y + +print(Answer_Xor) +print(Answer_right_shift) +print(Answer_left_shift) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py index e69de29b..c06b7320 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py @@ -0,0 +1,6 @@ +x = True +y = False + +Answer = bool(x and y) + +print(Answer) \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py index 27a67e60..fa9fd397 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = 'mkdir testdir | cd testdir' -TWO = 'grep and textfile.txt' -THREE = 'grep -r >> contents.txt' +ONE = '' +TWO = '' +THREE = '' FOUR = '' FIVE = '' SIX = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index cc3e9e7a..01c1d34c 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -1,7 +1,7 @@ # Assign the correct strings below ONE = 'mkdir testdir && cd testdir' -TWO = 'grep and textfile.txt' -THREE = 'grep -r >> contents.txt' -FOUR = 'cd current > current' -FIVE = 'ls > currentpath.txt' +TWO = 'cat textfile.txt | grep and' +THREE = 'ls >> contents.txt' +FOUR = 'cd current || mkdir current' +FIVE = 'pwd > currentpath.txt' diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt b/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt b/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt b/introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt b/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt new file mode 100644 index 00000000..3df9b92b --- /dev/null +++ b/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt @@ -0,0 +1 @@ +Darth Vader diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt b/introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt new file mode 100644 index 00000000..e69de29b From 937c95a1610fdacf0bca0718be69b1cabe229037 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 30 Jul 2020 20:11:09 -0400 Subject: [PATCH 11/65] Completed Exercises --- .../1_compare_check/Solution/solution.py | 5 +++++ .../1_even_odd/Solution/solution.py | 9 +++++++++ .../1_loop_divisibility/Solution/solution.py | 4 +++- .../1_string_convert/Solution/solution.py | 7 +++++++ .../1_string_length/Solution/solution.py | 3 +++ .../1_string_slice/Solution/solution.py | 4 ++++ .../2_add_item/Solution/solution.py | 4 ++++ .../2_append/Solution/solution.py | 3 +++ .../2_farm_area/Solution/solution.py | 5 +++++ .../2_remove_item/Solution/solution.py | 4 ++++ .../2_sum_list/Solution/solution.py | 3 +++ .../3_bitwise_operators_1/Solutions/solution.py | 9 +++------ .../3_logical_operators_2/Solutions/solution.py | 3 +++ 13 files changed, 56 insertions(+), 7 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py index ade03179..63f1d036 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +x = 200 +y = 201 + +result = x and y +print(bool(result)) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py index ade03179..9529b438 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +number = int(input()) +def Data(number): + if number % 2 == 0: + return Even + else: + return Odd + + +print(Data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py index cbc031aa..0d7bc458 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py @@ -1,2 +1,4 @@ # Code your solution here - \ No newline at end of file +for x in range(0, 51): + if x % 5 == 0 or x % 7 == 0: + print(x) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py index ade03179..ffd1a53e 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py @@ -1 +1,8 @@ # Code your solution here +string = str(input()) +def data(string): + if string.isupper(): + string.lower + else: + string.upper +print(data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py index ade03179..62059e37 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +string_1 = str(input()) +data = len(string_1) +print(data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py index ade03179..2f4be347 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_value = 'Hello Universe' +data = string_value[0:5] +data_val = data + 'World' +print(data_val) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py index ade03179..2e0a6d46 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +dict_a = {} +dict_a["key1"] = 2 +dict_val = dict_a +print(dict_val) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py index ade03179..2eef5e26 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_a = [] +list_b = list_a.append(3) +print(list_b) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index ade03179..294932c9 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +length = 6 +breadth = 4 + +data = length * breadth +print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py index ade03179..ab77c215 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +list_1 = [] +lister = list_1.remove() + +print(lister) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py index ade03179..8115ca30 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_a = [] +total = sum(list_a) +print(total) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index 378ee449..fbf8bbd8 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -1,13 +1,10 @@ x = 0 y = 1 -x & y = 0 -x | y = 1 -~ x, ~ y = 1, 0 -Answer_and = 0 -Answer_or = 1 -Answer_not = 1, 0 +Answer_and = x & y +Answer_or = x | y +Answer_not = ~ x print(Answer_and) print(Answer_or) diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index e69de29b..8d596bdc 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -0,0 +1,3 @@ +x = 1 +y = 2 + From 8625c8c7434f10285343fcbfaf687792262f1342 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 11:10:49 -0400 Subject: [PATCH 12/65] Pushing exercises --- .../1_list_max/solution/solution.py | 11 +++++++++++ .../2_except_letter/Solution/solution.py | 10 ++++++++++ .../2_vowel_consonant/Solution/solution.py | 12 ++++++++++++ .../3_grade/Solution/solution.py | 19 +++++++++++++++++++ .../3_set_difference/Solution/solution.py | 4 ++++ .../3_string_case/Solution/solution.py | 6 ++++++ 6 files changed, 62 insertions(+) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index e69de29b..31afbb01 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -0,0 +1,11 @@ +L = [152, 463, 1112, 1337, -10] +# def LIST_MAX(L): +# if L == []: +# LIST_MAX1 = None +# else: +# LIST_MAX1 = sorted(L)[-1] +# return LIST_MAX1 + +# print(LIST_MAX(L)) +LIST_MAX = sorted(L)[-1] +# print(LIST_MAX) diff --git a/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py index ade03179..e09d2c29 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py @@ -1 +1,11 @@ # Code your solution here +string = 'BYTE ACADEMY' +vowels = ['A', 'E', 'I', 'O', 'U'] +def data(x): + ans = False + for characters in string: + if characters != vowels: + ans = True + return ans +print(data) + \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py index ade03179..a00455dd 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py @@ -1 +1,13 @@ # Code your solution here +vowels = ['a', 'e', 'i', 'o', 'u'] +consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'] +letter = input() + +def data(x): + for characters in letter: + if characters == vowels: + return vowel + elif characters == consonants: + return consonant + +print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index ade03179..3389f4e0 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1 +1,20 @@ # Code your solution here +def grade(mark): + if mark >= 90: + # return 'A+ GRADE' + print('A+ GRADE') + elif mark >= 70: + # return 'B GRADE' + print('B GRADE') + elif mark >= 50: + # return 'C GRADE' + print('C GRADE') + elif mark >= 35: + # return 'D GRADE' + print('D GRADE') + else: + # return 'FAIL' + print('FAIL') +score = int(input("Enter your grade here:")) +print(grade(score)) +# grade(score) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py index ade03179..e13ac0ba 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +set_1 = set() +set_2 = set() +result = set_1 - set_2 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index ade03179..50b2220f 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1 +1,7 @@ # Code your solution here +string_val = str(input()) +upper_data = string_val.upper() +lower_data = string_val.lower() + +print(upper_data) +print(lower_data) \ No newline at end of file From b6a949d54ec918be27af1cd41ca81ec3dcd8312d Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 11:32:37 -0400 Subject: [PATCH 13/65] Completed --- .../3_count_duplicate/Solution/solution.py | 3 +++ .../3_grade/Solution/solution.py | 20 ++++++++----------- .../3_string_case/Solution/solution.py | 1 + .../2_ASCII/Solutions/solution.py | 3 ++- .../2_operators/Solutions/solution.py | 3 ++- .../Solutions/solution.py | 7 +++++-- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py index ade03179..e12307d6 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_dup = [] +tot = list_dup.count +print(tot) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index 3389f4e0..cc177132 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1,20 +1,16 @@ # Code your solution here def grade(mark): if mark >= 90: - # return 'A+ GRADE' - print('A+ GRADE') + return 'A+ GRADE' elif mark >= 70: - # return 'B GRADE' - print('B GRADE') + return 'B GRADE' elif mark >= 50: - # return 'C GRADE' - print('C GRADE') + return 'C GRADE' elif mark >= 35: - # return 'D GRADE' - print('D GRADE') + return 'D GRADE' else: - # return 'FAIL' - print('FAIL') -score = int(input("Enter your grade here:")) -print(grade(score)) + return 'FAIL' +# score = int(input("Enter your grade here:")) +mark = 80 +print(grade(mark)) # grade(score) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index 50b2220f..0c9227fb 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1,5 +1,6 @@ # Code your solution here string_val = str(input()) + upper_data = string_val.upper() lower_data = string_val.lower() diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index 279d1501..117c7cd9 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -1 +1,2 @@ -print('Hexadecimal') \ No newline at end of file +# print('Hexadecimal') +print('Boolean') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index f37988b4..e983d85b 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -1 +1,2 @@ -print('Boolean') \ No newline at end of file +# print('Boolean') +print('Hexadecimal') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index 8d596bdc..3cfc611d 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -1,3 +1,6 @@ -x = 1 -y = 2 +x = True +y = False +Answer = bool(x or y) + +print(Answer) \ No newline at end of file From 44800a1ba0ffe8da75e0b28c2352282cc011a918 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 16:53:18 -0400 Subject: [PATCH 14/65] Completed --- .../1_list_max/solution/solution.py | 26 ++++++++++++------- .../2_farm_area/Solution/solution.py | 3 ++- .../3_month_days/Solution/solution.py | 9 +++++++ .../3_palindrome/Solution/solution.py | 8 ++++++ .../3_shape_check/Solution/solution.py | 9 +++++++ 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index 31afbb01..a3cd5df7 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -1,11 +1,19 @@ -L = [152, 463, 1112, 1337, -10] -# def LIST_MAX(L): -# if L == []: -# LIST_MAX1 = None -# else: -# LIST_MAX1 = sorted(L)[-1] -# return LIST_MAX1 +# L = [152, 463, 1112, 1337, -10] +# LIST_MAX = sorted(L)[-1] # print(LIST_MAX(L)) -LIST_MAX = sorted(L)[-1] -# print(LIST_MAX) + +L = [152, 463, 1112, 1337, -10] +def LIST_MAX1(L): + current_max = L[0] + if L[1] > current_max: + current_max = L[1] + if L[2] > current_max: + current_max = L[2] + if L[3] > current_max: + current_max = L[3] + if L[4] > current_max: + current_max = L[4] + return current_max +LIST_MAX = LIST_MAX1(L) + diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index 294932c9..47344e65 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1,6 +1,7 @@ # Code your solution here +# length = len(input()) +# breadth = len(input()) length = 6 breadth = 4 - data = length * breadth print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py index ade03179..678676a5 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +month = input('Enter any month:') +month_dict = {'january':'31', 'february':'28, 29', 'march':'31', 'april':'30', 'may':'31', 'june':'30', 'july':'31', 'august':'31','september':'30', 'october':'31', 'november':'30', 'december':'31'} +def data(month): + if month in month_dict.keys(): + return month_dict[month] + else: + return None + +print(data(month)) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py index ade03179..b85e38d8 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py @@ -1 +1,9 @@ # Code your solution here +line = input('Enter any string value:') + +if line == line[::-1]: + is_palindrome = True +else: + is_palindrome = False + +print(is_palindrome) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py index ade03179..2b897c95 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +figure = input('Enter any geometric shape value:') +my_dict = {'3':'Triangle', '4':'Quadrilateral', '5':'Pentagon', '6':'Hexagon', '7':'Heptagon', '8':'Octagon', '9':'Nonagon'} + +def data(figure): + if figure in my_dict: + return my_dict[figure] + else: + return 'None' +print(data(figure)) \ No newline at end of file From e413068e20fe29724c599a5030349be779c5dac0 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Sun, 2 Aug 2020 15:00:48 -0400 Subject: [PATCH 15/65] Completed Exercises --- .DS_Store | Bin 0 -> 6148 bytes .../1_list_max/solution/solution.py | 3 +-- .../functions/1_range/Solution/solution.py | 6 ++++-- .../1_return_hello/Solution/solution.py | 4 ++-- .../functions/2_max_value/Solution/solution.py | 4 ++-- .../functions/2_shut_down/Solution/solution.py | 8 ++++++-- .../2_variable_argument/Solution/solution.py | 5 +---- .../functions/3_anonymous/Solution/solution.py | 5 +++++ .../functions/3_count_even/Solution/solution.py | 3 +-- .../functions/3_factorial/Solution/solution.py | 6 ++++-- .../functions/3_total/Solution/solution.py | 6 ++++-- 11 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 .DS_Store create mode 100644 introduction_to_python/functions/3_anonymous/Solution/solution.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..689e5e94266dbf9be05223eb9f20bdf3f316910d GIT binary patch literal 6148 zcmeHKO>Wab6n@hNaDq^>K!gPgZ;)72C>4P&Dx@@|i!P85L9hUn+O=scIiARN8l@q~ z8}3k!z)iRT2jKwly_o?ePRp(c&^+nQ_vYt&qxo#lc!)@JC&4yRgNPhBW2J`T9OHiW zHQO*P+$mI!lp@M$NF&PDM%xCffK}jcQ-HtS8hI4cF-cnbeh*@KN zUTnGZot+lPj~0un)4aR=_~39fJDtB@d^l69A%Xo%S>51I_=MnGeNOsm63gTm{miXX z02Ooi0DE5!B`0(QoFED*E2;SzjAb?NVBbs>OCpbEMtB|xvUw;2UdWZZ|tb%nI zsJTM4rZih+t2gXy=?z0NYnQ5kdFP$$mpY40ZWXW!{EG_k{@}tHI|d7lYU@Cut^mLa znw25u-v#El20I1|jp%_1O$BPIFjowr>1cP&xQ@X>qo$KEmk(iP7UqT`)a=Obs^KI$ z8f|G6unMdyu&JvJKL7VGzW=Y1Y|ScQ75J|d5S3oP*Ts^|*}AqkK5Je0A)JlJ6&e)< jg*lE@z(?_IxH9y)8~{583yo-j*&hKVgDtEAe^h}V*0i{c literal 0 HcmV?d00001 diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index a3cd5df7..84e25b8d 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -15,5 +15,4 @@ def LIST_MAX1(L): if L[4] > current_max: current_max = L[4] return current_max -LIST_MAX = LIST_MAX1(L) - +LIST_MAX = LIST_MAX1(L) \ No newline at end of file diff --git a/introduction_to_python/functions/1_range/Solution/solution.py b/introduction_to_python/functions/1_range/Solution/solution.py index c8900ad6..c5178908 100644 --- a/introduction_to_python/functions/1_range/Solution/solution.py +++ b/introduction_to_python/functions/1_range/Solution/solution.py @@ -1,3 +1,5 @@ -# Code your solution here def range_100(number): - return \ No newline at end of file + if number <= 100: + return 'GREATNESS' + else: + return 'OOPS' \ No newline at end of file diff --git a/introduction_to_python/functions/1_return_hello/Solution/solution.py b/introduction_to_python/functions/1_return_hello/Solution/solution.py index 2e0cba9b..de2a9519 100644 --- a/introduction_to_python/functions/1_return_hello/Solution/solution.py +++ b/introduction_to_python/functions/1_return_hello/Solution/solution.py @@ -1,3 +1,3 @@ -# Code your solution here def hello(name): - return \ No newline at end of file + val1 = 'Hello' + name + return val1 \ No newline at end of file diff --git a/introduction_to_python/functions/2_max_value/Solution/solution.py b/introduction_to_python/functions/2_max_value/Solution/solution.py index fec0f0a6..0f3cf2e3 100644 --- a/introduction_to_python/functions/2_max_value/Solution/solution.py +++ b/introduction_to_python/functions/2_max_value/Solution/solution.py @@ -1,3 +1,3 @@ -# Code your solution here def max_val(a, b, c): - return \ No newline at end of file + max_value = max(a, b, c) + return max_value \ No newline at end of file diff --git a/introduction_to_python/functions/2_shut_down/Solution/solution.py b/introduction_to_python/functions/2_shut_down/Solution/solution.py index 333edc82..f2f3f332 100644 --- a/introduction_to_python/functions/2_shut_down/Solution/solution.py +++ b/introduction_to_python/functions/2_shut_down/Solution/solution.py @@ -1,3 +1,7 @@ -# Code your solution here def shut_down(x): - return \ No newline at end of file + if x == True: + return 'SHUTDOWN' + elif x == False: + return 'SHUTDOWN ABORTED' + else: + return 'This is not a boolean value.' \ No newline at end of file diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index 0f6921b1..b5f907cd 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1,5 +1,2 @@ -# Code your solution here def concat_args(*args): - return - - + return sum(args) diff --git a/introduction_to_python/functions/3_anonymous/Solution/solution.py b/introduction_to_python/functions/3_anonymous/Solution/solution.py new file mode 100644 index 00000000..51abb9ed --- /dev/null +++ b/introduction_to_python/functions/3_anonymous/Solution/solution.py @@ -0,0 +1,5 @@ +# Code your solution here +def f(*args): + return list(map(lambda x: x % 13 == 0)) +result = f +print(result) \ No newline at end of file diff --git a/introduction_to_python/functions/3_count_even/Solution/solution.py b/introduction_to_python/functions/3_count_even/Solution/solution.py index abdfec29..a41423ea 100644 --- a/introduction_to_python/functions/3_count_even/Solution/solution.py +++ b/introduction_to_python/functions/3_count_even/Solution/solution.py @@ -1,3 +1,2 @@ -# Code your solution here def count_even(*args): - return \ No newline at end of file + return list(map(lambda x: x % 2== 0)) \ No newline at end of file diff --git a/introduction_to_python/functions/3_factorial/Solution/solution.py b/introduction_to_python/functions/3_factorial/Solution/solution.py index b733941e..9f87aa17 100644 --- a/introduction_to_python/functions/3_factorial/Solution/solution.py +++ b/introduction_to_python/functions/3_factorial/Solution/solution.py @@ -1,3 +1,5 @@ -# Code your solution here def factorial(n): - return \ No newline at end of file + factorial = 1 + if int(n) >= 1: + for i in range(1, int(n) + 1): + factorial = factorial * i \ No newline at end of file diff --git a/introduction_to_python/functions/3_total/Solution/solution.py b/introduction_to_python/functions/3_total/Solution/solution.py index 6162db4b..5d9a2e22 100644 --- a/introduction_to_python/functions/3_total/Solution/solution.py +++ b/introduction_to_python/functions/3_total/Solution/solution.py @@ -1,3 +1,5 @@ -# Code your solution here def sum_data(lst): - return \ No newline at end of file + summ = 0 + for i in l: + summ += i + return summ \ No newline at end of file From bce5b73c81bb06925f7835fe751783fb59a76673 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 3 Aug 2020 13:17:08 -0400 Subject: [PATCH 16/65] Working on these --- .../recursive_functions/1_array_sum/solutions/solution.py | 2 ++ .../recursive_functions/1_count_down/solutions/solution.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py index aeb50baa..4ee6cf73 100644 --- a/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py +++ b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py @@ -1 +1,3 @@ # Write your solution here +def sum_array(num_list): + return 0 if num_list == [] else num_list[0] + sum_array(num_list[1:]) diff --git a/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py b/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py index aeb50baa..4342bf27 100644 --- a/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py +++ b/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py @@ -1 +1,5 @@ # Write your solution here +def count_down_from(num): + return num + if num >= 1: + count_down_from(num - 1) \ No newline at end of file From 3f12b16450a1b2ee4e0083f2f90a45df5c98ed45 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 3 Aug 2020 15:20:59 -0400 Subject: [PATCH 17/65] Updated and completed --- .../1_default_args/Solution/solution.py | 2 +- .../functions/1_range/Solution/solution.py | 16 +------------ .../1_return_hello/Solution/solution.py | 15 ++---------- .../2_max_value/Solution/solution.py | 16 +------------ .../2_shut_down/Solution/solution.py | 15 +----------- .../2_variable_argument/Solution/solution.py | 13 ++++------- .../3_anonymous/Solution/solution.py | 4 +--- .../3_count_even/Solution/solution.py | 10 +------- .../Solution/solution.py | 2 +- .../3_factorial/Solution/solution.py | 23 ++++++------------- .../functions/3_total/Solution/solution.py | 19 ++------------- 11 files changed, 22 insertions(+), 113 deletions(-) diff --git a/introduction_to_python/functions/1_default_args/Solution/solution.py b/introduction_to_python/functions/1_default_args/Solution/solution.py index 55bdef79..4c64139d 100644 --- a/introduction_to_python/functions/1_default_args/Solution/solution.py +++ b/introduction_to_python/functions/1_default_args/Solution/solution.py @@ -1,3 +1,3 @@ # Code your solution here def concat_input(val_1="Hello ",val_2="World"): - return \ No newline at end of file + return val_1 + val_2 \ No newline at end of file diff --git a/introduction_to_python/functions/1_range/Solution/solution.py b/introduction_to_python/functions/1_range/Solution/solution.py index 57d83b7c..c5178908 100644 --- a/introduction_to_python/functions/1_range/Solution/solution.py +++ b/introduction_to_python/functions/1_range/Solution/solution.py @@ -1,19 +1,5 @@ -<<<<<<< HEAD def range_100(number): if number <= 100: return 'GREATNESS' else: - return 'OOPS' -======= -# Code your solution here - -# number = int(input('Enter any integer value:')) -number = 99 -def result(number): - if number <= 100: - return 'GREATNESS' - else: - return 'OOPS' - -print(result(number)) ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 + return 'OOPS' \ No newline at end of file diff --git a/introduction_to_python/functions/1_return_hello/Solution/solution.py b/introduction_to_python/functions/1_return_hello/Solution/solution.py index e91de2f5..e0e8b1a7 100644 --- a/introduction_to_python/functions/1_return_hello/Solution/solution.py +++ b/introduction_to_python/functions/1_return_hello/Solution/solution.py @@ -1,14 +1,3 @@ -<<<<<<< HEAD def hello(name): - val1 = 'Hello' + name - return val1 -======= -# Code your solution here -# name = input('Enter your name: ') -name = 'Newton' -def result(name): - val1 = 'Hello' + name - return val1 - -print(result(name)) ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 + val1 = 'Hello ' + name + return val1 \ No newline at end of file diff --git a/introduction_to_python/functions/2_max_value/Solution/solution.py b/introduction_to_python/functions/2_max_value/Solution/solution.py index ef7e0fae..0f3cf2e3 100644 --- a/introduction_to_python/functions/2_max_value/Solution/solution.py +++ b/introduction_to_python/functions/2_max_value/Solution/solution.py @@ -1,17 +1,3 @@ -<<<<<<< HEAD def max_val(a, b, c): max_value = max(a, b, c) - return max_value -======= -# Code your solution here -# a = int(input('Enter an integer value: ')) -# b = int(input('Enter another integer value: ')) -# c = int(input('Enter one last integer value: ')) -a = 1 -b = 2 -c = 3 -def result(a, b, c): - max_value = max(a, b, c) - return max_value -print(result(a, b, c)) ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 + return max_value \ No newline at end of file diff --git a/introduction_to_python/functions/2_shut_down/Solution/solution.py b/introduction_to_python/functions/2_shut_down/Solution/solution.py index e74ead75..f2f3f332 100644 --- a/introduction_to_python/functions/2_shut_down/Solution/solution.py +++ b/introduction_to_python/functions/2_shut_down/Solution/solution.py @@ -1,20 +1,7 @@ -<<<<<<< HEAD def shut_down(x): -======= -# Code your solution here -# x = bool(input('Enter a boolean value: ')) -x = 'false' -def data(x): ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 if x == True: return 'SHUTDOWN' elif x == False: return 'SHUTDOWN ABORTED' else: -<<<<<<< HEAD - return 'This is not a boolean value.' -======= - return 'This is not a boolean value.' -result = data(x) -print(result) ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 + return 'This is not a boolean value.' \ No newline at end of file diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index 3c585e5b..5d81cdf1 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1,10 +1,5 @@ -<<<<<<< HEAD +# def concat_args(*args): +# return sum(args) def concat_args(*args): - return sum(args) -======= -# Code your solution here -def f(*args): - return sum(args) -result = f -print(result) ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 + args.split([]) + return ' '.join(args) diff --git a/introduction_to_python/functions/3_anonymous/Solution/solution.py b/introduction_to_python/functions/3_anonymous/Solution/solution.py index 51abb9ed..f3496960 100644 --- a/introduction_to_python/functions/3_anonymous/Solution/solution.py +++ b/introduction_to_python/functions/3_anonymous/Solution/solution.py @@ -1,5 +1,3 @@ # Code your solution here def f(*args): - return list(map(lambda x: x % 13 == 0)) -result = f -print(result) \ No newline at end of file + return list(map(lambda x: x % 13 == 0)) \ No newline at end of file diff --git a/introduction_to_python/functions/3_count_even/Solution/solution.py b/introduction_to_python/functions/3_count_even/Solution/solution.py index c847132f..93ea2775 100644 --- a/introduction_to_python/functions/3_count_even/Solution/solution.py +++ b/introduction_to_python/functions/3_count_even/Solution/solution.py @@ -1,10 +1,2 @@ -<<<<<<< HEAD def count_even(*args): - return list(map(lambda x: x % 2== 0)) -======= -# Code your solution here -def f(*args): - return list(map(lambda x: x % 2== 0)) -result = f -print(result) ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 + return len(list(filter(lambda x: x % 2 == 0, args))) \ No newline at end of file diff --git a/introduction_to_python/functions/3_div_by_3_annonymous/Solution/solution.py b/introduction_to_python/functions/3_div_by_3_annonymous/Solution/solution.py index aadbaeb8..043c48b3 100644 --- a/introduction_to_python/functions/3_div_by_3_annonymous/Solution/solution.py +++ b/introduction_to_python/functions/3_div_by_3_annonymous/Solution/solution.py @@ -1,3 +1,3 @@ # Code your solution here def div_by_3(*args): - return \ No newline at end of file + return list(filter(lambda x: x % 3 == 0, args)) \ No newline at end of file diff --git a/introduction_to_python/functions/3_factorial/Solution/solution.py b/introduction_to_python/functions/3_factorial/Solution/solution.py index 154ec55d..ba7eaaa0 100644 --- a/introduction_to_python/functions/3_factorial/Solution/solution.py +++ b/introduction_to_python/functions/3_factorial/Solution/solution.py @@ -1,20 +1,11 @@ -<<<<<<< HEAD def factorial(n): factorial = 1 - if int(n) >= 1: + if n < 0: + return None + elif None == 0: + return None + # if int(n) >= 1: + else: for i in range(1, int(n) + 1): factorial = factorial * i -======= -# Code your solution here -# n = int(input(Enter any integer: )) -n = 4 - -def numbers(n): - factorial = 1 - if int(n) >= 1: - for i in range(1, int(n) + 1): - factorial = factorial * i - -result = numbers(n) -print(result) ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 + return factorial \ No newline at end of file diff --git a/introduction_to_python/functions/3_total/Solution/solution.py b/introduction_to_python/functions/3_total/Solution/solution.py index 4f7d0219..4065fc35 100644 --- a/introduction_to_python/functions/3_total/Solution/solution.py +++ b/introduction_to_python/functions/3_total/Solution/solution.py @@ -1,20 +1,5 @@ -<<<<<<< HEAD def sum_data(lst): summ = 0 - for i in l: + for i in lst: summ += i - return summ -======= -# Code your solution here -l = [10, 20, 30, 40, 50, 60] -# l = [1, 2, 3, 4, 5] -# used the list provided in test_solution.py for the test to work - -def a_list(l): - summ = 0 - for i in l: - summ += i - return summ -result = a_list(l) -print(result) ->>>>>>> b45b321e9ba4e515a32b73f55e49d05b1b0621f2 + return summ \ No newline at end of file From 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 3 Aug 2020 22:23:41 -0400 Subject: [PATCH 18/65] Completed --- .../functions/2_variable_argument/Solution/solution.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index 5d81cdf1..33eceb24 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1,5 +1,2 @@ -# def concat_args(*args): -# return sum(args) def concat_args(*args): - args.split([]) - return ' '.join(args) + return ''.join(args) \ No newline at end of file From 57dc055a28c182d75794a17aa5011d1e3eacd863 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 29 Jul 2020 14:54:27 -0400 Subject: [PATCH 19/65] Exercises completed --- .../1_creating_a_repository/Solution/solution.py | 2 +- .../git/1_remote_repository/Solution/solution.py | 2 +- .../git/1_staging_area/Solution/solution.py | 2 +- .../git/1_update_code/Solution/solution.py | 2 +- .../hello_world/1_arithmetic/solution/solution.py | 8 ++++++++ .../1_concantenation/Solution/solution.py | 4 ++++ .../1_name_bindings/solution/solution.py | 3 +++ .../hello_world/1_operators/solution/solution.py | 2 ++ .../2_capture_display/Solution/solution.py | 5 +++++ .../2_python_caches/solution/solution.py | 4 ++-- .../2_string_arithmetic/solution/solution.py | 5 +++++ .../2_string_duplication/Solution/solution.py | 4 ++++ .../hello_world/2_type_check/Solution/solution.py | 8 ++++++++ .../hello_world/3_type_change/Solution/solution.py | 5 +++++ .../hello_world/3_user_input/solution/solution.py | 6 ++++++ .../1_basic_commands/solution/solution.py | 12 ++++++------ .../1_commands_with_options/solution/solution.py | 14 +++++++------- .../1_commands_with_options_2/solution/solution.py | 12 ++++++------ .../2_bash_commands/solution/solution.py | 6 +++--- .../2_bash_operators/solution/solution.py | 10 +++++----- 20 files changed, 83 insertions(+), 33 deletions(-) diff --git a/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py b/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py index cccdee23..e7abe60c 100644 --- a/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py +++ b/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'a' diff --git a/introduction_and_environment/git/1_remote_repository/Solution/solution.py b/introduction_and_environment/git/1_remote_repository/Solution/solution.py index cccdee23..482a5499 100644 --- a/introduction_and_environment/git/1_remote_repository/Solution/solution.py +++ b/introduction_and_environment/git/1_remote_repository/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'd' diff --git a/introduction_and_environment/git/1_staging_area/Solution/solution.py b/introduction_and_environment/git/1_staging_area/Solution/solution.py index cccdee23..b8eb8f57 100644 --- a/introduction_and_environment/git/1_staging_area/Solution/solution.py +++ b/introduction_and_environment/git/1_staging_area/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'c' diff --git a/introduction_and_environment/git/1_update_code/Solution/solution.py b/introduction_and_environment/git/1_update_code/Solution/solution.py index cccdee23..ca9c8ca8 100644 --- a/introduction_and_environment/git/1_update_code/Solution/solution.py +++ b/introduction_and_environment/git/1_update_code/Solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here -answer = '' +answer = 'b' diff --git a/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py b/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py index 217b5003..5c4e4332 100644 --- a/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py +++ b/introduction_and_environment/hello_world/1_arithmetic/solution/solution.py @@ -1 +1,9 @@ from provided_code import x, y + +SUM = x + y +DIFF = x - y +MULT = x * y +DIV = x / y +POWER = x ** y +QUOTIENT = x // y +REMAINDER = x % y diff --git a/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py b/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py index ade03179..4f39a9d5 100644 --- a/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py +++ b/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_1 = "hello" +string_2 = "world!" +result = string_1 + string_2 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py b/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py index ade03179..6b02d8a7 100644 --- a/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py +++ b/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py @@ -1 +1,4 @@ # Code your solution here +x = 1337 +y = "hello world" +z = 13.5 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/1_operators/solution/solution.py b/introduction_and_environment/hello_world/1_operators/solution/solution.py index ade03179..f247d49c 100644 --- a/introduction_and_environment/hello_world/1_operators/solution/solution.py +++ b/introduction_and_environment/hello_world/1_operators/solution/solution.py @@ -1 +1,3 @@ # Code your solution here +x = 11 +y = 10 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py index ade03179..69d7ac2b 100644 --- a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +name = input("Enter your name:") +age = input("Enter your age:") + +print(name) +print(age) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_python_caches/solution/solution.py b/introduction_and_environment/hello_world/2_python_caches/solution/solution.py index 45a087b6..3e9db70e 100644 --- a/introduction_and_environment/hello_world/2_python_caches/solution/solution.py +++ b/introduction_and_environment/hello_world/2_python_caches/solution/solution.py @@ -1,2 +1,2 @@ -LOWER_BOUND = 0 -UPPER_BOUND = 0 +LOWER_BOUND = -5 +UPPER_BOUND = 256 diff --git a/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py b/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py index ade03179..92feda11 100644 --- a/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py +++ b/introduction_and_environment/hello_world/2_string_arithmetic/solution/solution.py @@ -1 +1,6 @@ # Code your solution here +x = 'Hello' +y = 'World!' +z = 3 + +STR_ARITHMETIC = 2 \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py b/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py index ade03179..123ed16b 100644 --- a/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_1 = 'Charlie' +dup_val = 5 +result = string_1 * dup_val +print(result) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/2_type_check/Solution/solution.py b/introduction_and_environment/hello_world/2_type_check/Solution/solution.py index 0ec5aa42..8e231d8e 100644 --- a/introduction_and_environment/hello_world/2_type_check/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_type_check/Solution/solution.py @@ -1 +1,9 @@ # Code your solution here... +input_1 = input("Store any data type value:") +input_2 = input("Store any other data type value:") + +result_1 = type(input_1) +result_2 = type(input_2) + +print(result_1) +print(result_2) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py index ade03179..428645c2 100644 --- a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +object_1 = 3.2 +object_2 = 2 + +print(str(object_1)) +print(int(object_2)) \ No newline at end of file diff --git a/introduction_and_environment/hello_world/3_user_input/solution/solution.py b/introduction_and_environment/hello_world/3_user_input/solution/solution.py index ade03179..79af3166 100644 --- a/introduction_and_environment/hello_world/3_user_input/solution/solution.py +++ b/introduction_and_environment/hello_world/3_user_input/solution/solution.py @@ -1 +1,7 @@ # Code your solution here +first_num = input("State one number:") +second_num = input("State another number:") +third_num = input("State a third number:") + +result = (first_num * second_num * third_num) / 3 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py index a19ce0a0..0373a93d 100644 --- a/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py @@ -2,9 +2,9 @@ ONE = 'man' # Assign the correct strings below -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' -SEVEN = '' +TWO = 'ls' +THREE = 'mkdir' +FOUR = 'touch' +FIVE = 'cp' +SIX = 'mv' +SEVEN = 'rm' \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py index fa9fd397..b904358d 100644 --- a/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py @@ -1,9 +1,9 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' -SEVEN = '' +ONE = 'cd exercises' +TWO = 'pwd' +THREE = 'cat textfile.txt' +FOUR = 'tail textfile.txt' +FIVE = 'ls -a' +SIX = 'head textfile.txt' +SEVEN = 'cp stackdata.json stockdata.json' \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py index fa9fd397..30820b11 100644 --- a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py @@ -1,9 +1,9 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' -SIX = '' +ONE = 'grep elephant book.txt' +TWO = 'mv notes.txt newdir' +THREE = 'grep -r string testdir' +FOUR = 'rm empty' +FIVE = 'cd' +SIX = 'rm -r Downloads' SEVEN = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py index fa9fd397..27a67e60 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' +ONE = 'mkdir testdir | cd testdir' +TWO = 'grep and textfile.txt' +THREE = 'grep -r >> contents.txt' FOUR = '' FIVE = '' SIX = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index f34e86b6..cc3e9e7a 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -1,7 +1,7 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' -FOUR = '' -FIVE = '' +ONE = 'mkdir testdir && cd testdir' +TWO = 'grep and textfile.txt' +THREE = 'grep -r >> contents.txt' +FOUR = 'cd current > current' +FIVE = 'ls > currentpath.txt' From 485ab8a7bfe983632e16068fb18682bad0a87bf9 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 30 Jul 2020 14:32:45 -0400 Subject: [PATCH 20/65] Exercises completed --- .../hello_world/3_type_change/Solution/solution.py | 2 +- .../1_DNS/solution/solution.py | 4 +++- .../1_architecture/solution/solution.py | 1 + .../1_bytes/solution/solution.py | 1 + .../1_languages/solution/solution.py | 3 ++- .../2_ASCII/Solutions/solution.py | 1 + .../2_operators/Solutions/solution.py | 1 + .../3_bitwise_operators_1/Solutions/solution.py | 14 ++++++++++++++ .../3_bitwise_operators_2/Solutions/solution.py | 10 ++++++++++ .../3_logical_operators_1/Solutions/solution.py | 6 ++++++ .../2_bash_commands/solution/solution.py | 6 +++--- .../2_bash_operators/solution/solution.py | 8 ++++---- .../3_star_wars/millenium_falcon/chewbacca.txt | 0 .../3_star_wars/millenium_falcon/han_solo.txt | 0 .../3_star_wars/the_rebellion/leia_organa.txt | 0 .../3_star_wars/tie_fighter/darth_vader.txt | 1 + .../3_star_wars/x_wing/luke_skywalker.txt | 0 17 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt create mode 100644 introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py index 428645c2..1480c6f8 100644 --- a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -1,6 +1,6 @@ # Code your solution here object_1 = 3.2 -object_2 = 2 +object_2 = '2' print(str(object_1)) print(int(object_2)) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py index ee95bbbb..fee1b0e9 100644 --- a/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py @@ -1 +1,3 @@ -# Code your solution below \ No newline at end of file +# Code your solution below + +print('Domain Name System') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py index abe91ec3..7ef8b2ba 100644 --- a/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py @@ -1 +1,2 @@ # Code your solution below +print('a.John Von Neuman') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py index abe91ec3..63bab332 100644 --- a/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py @@ -1 +1,2 @@ # Code your solution below +print('Gigabyte') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py index ee95bbbb..38b0c3cd 100644 --- a/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py +++ b/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py @@ -1 +1,2 @@ -# Code your solution below \ No newline at end of file +# Code your solution below +print('Interpreter') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index e69de29b..279d1501 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -0,0 +1 @@ +print('Hexadecimal') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index e69de29b..f37988b4 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -0,0 +1 @@ +print('Boolean') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index e69de29b..378ee449 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -0,0 +1,14 @@ +x = 0 +y = 1 + +x & y = 0 +x | y = 1 +~ x, ~ y = 1, 0 + +Answer_and = 0 +Answer_or = 1 +Answer_not = 1, 0 + +print(Answer_and) +print(Answer_or) +print(Answer_not) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py index e69de29b..b3ac89c3 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py @@ -0,0 +1,10 @@ +x = 1 +y = 1 + +Answer_Xor = x ^ y +Answer_right_shift = x >> y +Answer_left_shift = x << y + +print(Answer_Xor) +print(Answer_right_shift) +print(Answer_left_shift) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py index e69de29b..c06b7320 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py @@ -0,0 +1,6 @@ +x = True +y = False + +Answer = bool(x and y) + +print(Answer) \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py index 27a67e60..fa9fd397 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = 'mkdir testdir | cd testdir' -TWO = 'grep and textfile.txt' -THREE = 'grep -r >> contents.txt' +ONE = '' +TWO = '' +THREE = '' FOUR = '' FIVE = '' SIX = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index cc3e9e7a..01c1d34c 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -1,7 +1,7 @@ # Assign the correct strings below ONE = 'mkdir testdir && cd testdir' -TWO = 'grep and textfile.txt' -THREE = 'grep -r >> contents.txt' -FOUR = 'cd current > current' -FIVE = 'ls > currentpath.txt' +TWO = 'cat textfile.txt | grep and' +THREE = 'ls >> contents.txt' +FOUR = 'cd current || mkdir current' +FIVE = 'pwd > currentpath.txt' diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt b/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/chewbacca.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt b/introduction_and_environment/unix_and_bash/3_star_wars/millenium_falcon/han_solo.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt b/introduction_and_environment/unix_and_bash/3_star_wars/the_rebellion/leia_organa.txt new file mode 100644 index 00000000..e69de29b diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt b/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt new file mode 100644 index 00000000..3df9b92b --- /dev/null +++ b/introduction_and_environment/unix_and_bash/3_star_wars/tie_fighter/darth_vader.txt @@ -0,0 +1 @@ +Darth Vader diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt b/introduction_and_environment/unix_and_bash/3_star_wars/x_wing/luke_skywalker.txt new file mode 100644 index 00000000..e69de29b From 6ce55cdb0a471dcad7e8e728b717e0c6ce97dbd2 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 30 Jul 2020 20:11:09 -0400 Subject: [PATCH 21/65] Completed Exercises --- .../1_compare_check/Solution/solution.py | 5 +++++ .../1_even_odd/Solution/solution.py | 9 +++++++++ .../1_loop_divisibility/Solution/solution.py | 4 +++- .../1_string_convert/Solution/solution.py | 7 +++++++ .../1_string_length/Solution/solution.py | 3 +++ .../1_string_slice/Solution/solution.py | 4 ++++ .../2_add_item/Solution/solution.py | 4 ++++ .../2_append/Solution/solution.py | 3 +++ .../2_farm_area/Solution/solution.py | 5 +++++ .../2_remove_item/Solution/solution.py | 4 ++++ .../2_sum_list/Solution/solution.py | 3 +++ .../3_bitwise_operators_1/Solutions/solution.py | 9 +++------ .../3_logical_operators_2/Solutions/solution.py | 3 +++ 13 files changed, 56 insertions(+), 7 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py index ade03179..63f1d036 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +x = 200 +y = 201 + +result = x and y +print(bool(result)) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py index ade03179..9529b438 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +number = int(input()) +def Data(number): + if number % 2 == 0: + return Even + else: + return Odd + + +print(Data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py index cbc031aa..0d7bc458 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py @@ -1,2 +1,4 @@ # Code your solution here - \ No newline at end of file +for x in range(0, 51): + if x % 5 == 0 or x % 7 == 0: + print(x) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py index ade03179..ffd1a53e 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py @@ -1 +1,8 @@ # Code your solution here +string = str(input()) +def data(string): + if string.isupper(): + string.lower + else: + string.upper +print(data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py index ade03179..62059e37 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +string_1 = str(input()) +data = len(string_1) +print(data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py index ade03179..2f4be347 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +string_value = 'Hello Universe' +data = string_value[0:5] +data_val = data + 'World' +print(data_val) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py index ade03179..2e0a6d46 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +dict_a = {} +dict_a["key1"] = 2 +dict_val = dict_a +print(dict_val) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py index ade03179..2eef5e26 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_a = [] +list_b = list_a.append(3) +print(list_b) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index ade03179..294932c9 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1 +1,6 @@ # Code your solution here +length = 6 +breadth = 4 + +data = length * breadth +print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py index ade03179..ab77c215 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +list_1 = [] +lister = list_1.remove() + +print(lister) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py index ade03179..8115ca30 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_a = [] +total = sum(list_a) +print(total) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index 378ee449..fbf8bbd8 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -1,13 +1,10 @@ x = 0 y = 1 -x & y = 0 -x | y = 1 -~ x, ~ y = 1, 0 -Answer_and = 0 -Answer_or = 1 -Answer_not = 1, 0 +Answer_and = x & y +Answer_or = x | y +Answer_not = ~ x print(Answer_and) print(Answer_or) diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index e69de29b..8d596bdc 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -0,0 +1,3 @@ +x = 1 +y = 2 + From 68fe6b106aa65fffc3fb9a2e8108741bd7113a45 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 11:10:49 -0400 Subject: [PATCH 22/65] Pushing exercises --- .../1_list_max/solution/solution.py | 11 +++++++++++ .../2_except_letter/Solution/solution.py | 10 ++++++++++ .../2_vowel_consonant/Solution/solution.py | 12 ++++++++++++ .../3_grade/Solution/solution.py | 19 +++++++++++++++++++ .../3_set_difference/Solution/solution.py | 4 ++++ .../3_string_case/Solution/solution.py | 6 ++++++ 6 files changed, 62 insertions(+) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index e69de29b..31afbb01 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -0,0 +1,11 @@ +L = [152, 463, 1112, 1337, -10] +# def LIST_MAX(L): +# if L == []: +# LIST_MAX1 = None +# else: +# LIST_MAX1 = sorted(L)[-1] +# return LIST_MAX1 + +# print(LIST_MAX(L)) +LIST_MAX = sorted(L)[-1] +# print(LIST_MAX) diff --git a/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py index ade03179..e09d2c29 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py @@ -1 +1,11 @@ # Code your solution here +string = 'BYTE ACADEMY' +vowels = ['A', 'E', 'I', 'O', 'U'] +def data(x): + ans = False + for characters in string: + if characters != vowels: + ans = True + return ans +print(data) + \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py index ade03179..a00455dd 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py @@ -1 +1,13 @@ # Code your solution here +vowels = ['a', 'e', 'i', 'o', 'u'] +consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'] +letter = input() + +def data(x): + for characters in letter: + if characters == vowels: + return vowel + elif characters == consonants: + return consonant + +print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index ade03179..3389f4e0 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1 +1,20 @@ # Code your solution here +def grade(mark): + if mark >= 90: + # return 'A+ GRADE' + print('A+ GRADE') + elif mark >= 70: + # return 'B GRADE' + print('B GRADE') + elif mark >= 50: + # return 'C GRADE' + print('C GRADE') + elif mark >= 35: + # return 'D GRADE' + print('D GRADE') + else: + # return 'FAIL' + print('FAIL') +score = int(input("Enter your grade here:")) +print(grade(score)) +# grade(score) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py index ade03179..e13ac0ba 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py @@ -1 +1,5 @@ # Code your solution here +set_1 = set() +set_2 = set() +result = set_1 - set_2 +print(result) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index ade03179..50b2220f 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1 +1,7 @@ # Code your solution here +string_val = str(input()) +upper_data = string_val.upper() +lower_data = string_val.lower() + +print(upper_data) +print(lower_data) \ No newline at end of file From af9b4bf61d603fa254bd56a0475c0cfda7e53519 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 11:32:37 -0400 Subject: [PATCH 23/65] Completed --- .../3_count_duplicate/Solution/solution.py | 3 +++ .../3_grade/Solution/solution.py | 20 ++++++++----------- .../3_string_case/Solution/solution.py | 1 + .../2_ASCII/Solutions/solution.py | 3 ++- .../2_operators/Solutions/solution.py | 3 ++- .../Solutions/solution.py | 7 +++++-- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py index ade03179..e12307d6 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py @@ -1 +1,4 @@ # Code your solution here +list_dup = [] +tot = list_dup.count +print(tot) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index 3389f4e0..cc177132 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1,20 +1,16 @@ # Code your solution here def grade(mark): if mark >= 90: - # return 'A+ GRADE' - print('A+ GRADE') + return 'A+ GRADE' elif mark >= 70: - # return 'B GRADE' - print('B GRADE') + return 'B GRADE' elif mark >= 50: - # return 'C GRADE' - print('C GRADE') + return 'C GRADE' elif mark >= 35: - # return 'D GRADE' - print('D GRADE') + return 'D GRADE' else: - # return 'FAIL' - print('FAIL') -score = int(input("Enter your grade here:")) -print(grade(score)) + return 'FAIL' +# score = int(input("Enter your grade here:")) +mark = 80 +print(grade(mark)) # grade(score) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index 50b2220f..0c9227fb 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1,5 +1,6 @@ # Code your solution here string_val = str(input()) + upper_data = string_val.upper() lower_data = string_val.lower() diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index 279d1501..117c7cd9 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -1 +1,2 @@ -print('Hexadecimal') \ No newline at end of file +# print('Hexadecimal') +print('Boolean') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index f37988b4..e983d85b 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -1 +1,2 @@ -print('Boolean') \ No newline at end of file +# print('Boolean') +print('Hexadecimal') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index 8d596bdc..3cfc611d 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -1,3 +1,6 @@ -x = 1 -y = 2 +x = True +y = False +Answer = bool(x or y) + +print(Answer) \ No newline at end of file From d6f3670ba74c29b3977a49664300dd1080e65553 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 16:53:18 -0400 Subject: [PATCH 24/65] Completed --- .../1_list_max/solution/solution.py | 26 ++++++++++++------- .../2_farm_area/Solution/solution.py | 3 ++- .../3_month_days/Solution/solution.py | 9 +++++++ .../3_palindrome/Solution/solution.py | 8 ++++++ .../3_shape_check/Solution/solution.py | 9 +++++++ 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index 31afbb01..a3cd5df7 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -1,11 +1,19 @@ -L = [152, 463, 1112, 1337, -10] -# def LIST_MAX(L): -# if L == []: -# LIST_MAX1 = None -# else: -# LIST_MAX1 = sorted(L)[-1] -# return LIST_MAX1 +# L = [152, 463, 1112, 1337, -10] +# LIST_MAX = sorted(L)[-1] # print(LIST_MAX(L)) -LIST_MAX = sorted(L)[-1] -# print(LIST_MAX) + +L = [152, 463, 1112, 1337, -10] +def LIST_MAX1(L): + current_max = L[0] + if L[1] > current_max: + current_max = L[1] + if L[2] > current_max: + current_max = L[2] + if L[3] > current_max: + current_max = L[3] + if L[4] > current_max: + current_max = L[4] + return current_max +LIST_MAX = LIST_MAX1(L) + diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index 294932c9..47344e65 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1,6 +1,7 @@ # Code your solution here +# length = len(input()) +# breadth = len(input()) length = 6 breadth = 4 - data = length * breadth print(data) diff --git a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py index ade03179..678676a5 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +month = input('Enter any month:') +month_dict = {'january':'31', 'february':'28, 29', 'march':'31', 'april':'30', 'may':'31', 'june':'30', 'july':'31', 'august':'31','september':'30', 'october':'31', 'november':'30', 'december':'31'} +def data(month): + if month in month_dict.keys(): + return month_dict[month] + else: + return None + +print(data(month)) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py index ade03179..b85e38d8 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py @@ -1 +1,9 @@ # Code your solution here +line = input('Enter any string value:') + +if line == line[::-1]: + is_palindrome = True +else: + is_palindrome = False + +print(is_palindrome) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py index ade03179..2b897c95 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py @@ -1 +1,10 @@ # Code your solution here +figure = input('Enter any geometric shape value:') +my_dict = {'3':'Triangle', '4':'Quadrilateral', '5':'Pentagon', '6':'Hexagon', '7':'Heptagon', '8':'Octagon', '9':'Nonagon'} + +def data(figure): + if figure in my_dict: + return my_dict[figure] + else: + return 'None' +print(data(figure)) \ No newline at end of file From 12ca51570da5edb8e74b561403da0d098d04e9de Mon Sep 17 00:00:00 2001 From: PC-coding Date: Sun, 2 Aug 2020 15:00:48 -0400 Subject: [PATCH 25/65] Completed Exercises --- .DS_Store | Bin 0 -> 6148 bytes .../1_list_max/solution/solution.py | 3 +-- .../functions/1_range/Solution/solution.py | 6 ++++-- .../1_return_hello/Solution/solution.py | 4 ++-- .../functions/2_max_value/Solution/solution.py | 4 ++-- .../functions/2_shut_down/Solution/solution.py | 8 ++++++-- .../2_variable_argument/Solution/solution.py | 5 +---- .../functions/3_anonymous/Solution/solution.py | 5 +++++ .../functions/3_count_even/Solution/solution.py | 3 +-- .../functions/3_factorial/Solution/solution.py | 6 ++++-- .../functions/3_total/Solution/solution.py | 6 ++++-- 11 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 .DS_Store create mode 100644 introduction_to_python/functions/3_anonymous/Solution/solution.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..689e5e94266dbf9be05223eb9f20bdf3f316910d GIT binary patch literal 6148 zcmeHKO>Wab6n@hNaDq^>K!gPgZ;)72C>4P&Dx@@|i!P85L9hUn+O=scIiARN8l@q~ z8}3k!z)iRT2jKwly_o?ePRp(c&^+nQ_vYt&qxo#lc!)@JC&4yRgNPhBW2J`T9OHiW zHQO*P+$mI!lp@M$NF&PDM%xCffK}jcQ-HtS8hI4cF-cnbeh*@KN zUTnGZot+lPj~0un)4aR=_~39fJDtB@d^l69A%Xo%S>51I_=MnGeNOsm63gTm{miXX z02Ooi0DE5!B`0(QoFED*E2;SzjAb?NVBbs>OCpbEMtB|xvUw;2UdWZZ|tb%nI zsJTM4rZih+t2gXy=?z0NYnQ5kdFP$$mpY40ZWXW!{EG_k{@}tHI|d7lYU@Cut^mLa znw25u-v#El20I1|jp%_1O$BPIFjowr>1cP&xQ@X>qo$KEmk(iP7UqT`)a=Obs^KI$ z8f|G6unMdyu&JvJKL7VGzW=Y1Y|ScQ75J|d5S3oP*Ts^|*}AqkK5Je0A)JlJ6&e)< jg*lE@z(?_IxH9y)8~{583yo-j*&hKVgDtEAe^h}V*0i{c literal 0 HcmV?d00001 diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index a3cd5df7..84e25b8d 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -15,5 +15,4 @@ def LIST_MAX1(L): if L[4] > current_max: current_max = L[4] return current_max -LIST_MAX = LIST_MAX1(L) - +LIST_MAX = LIST_MAX1(L) \ No newline at end of file diff --git a/introduction_to_python/functions/1_range/Solution/solution.py b/introduction_to_python/functions/1_range/Solution/solution.py index c8900ad6..c5178908 100644 --- a/introduction_to_python/functions/1_range/Solution/solution.py +++ b/introduction_to_python/functions/1_range/Solution/solution.py @@ -1,3 +1,5 @@ -# Code your solution here def range_100(number): - return \ No newline at end of file + if number <= 100: + return 'GREATNESS' + else: + return 'OOPS' \ No newline at end of file diff --git a/introduction_to_python/functions/1_return_hello/Solution/solution.py b/introduction_to_python/functions/1_return_hello/Solution/solution.py index 2e0cba9b..de2a9519 100644 --- a/introduction_to_python/functions/1_return_hello/Solution/solution.py +++ b/introduction_to_python/functions/1_return_hello/Solution/solution.py @@ -1,3 +1,3 @@ -# Code your solution here def hello(name): - return \ No newline at end of file + val1 = 'Hello' + name + return val1 \ No newline at end of file diff --git a/introduction_to_python/functions/2_max_value/Solution/solution.py b/introduction_to_python/functions/2_max_value/Solution/solution.py index fec0f0a6..0f3cf2e3 100644 --- a/introduction_to_python/functions/2_max_value/Solution/solution.py +++ b/introduction_to_python/functions/2_max_value/Solution/solution.py @@ -1,3 +1,3 @@ -# Code your solution here def max_val(a, b, c): - return \ No newline at end of file + max_value = max(a, b, c) + return max_value \ No newline at end of file diff --git a/introduction_to_python/functions/2_shut_down/Solution/solution.py b/introduction_to_python/functions/2_shut_down/Solution/solution.py index 333edc82..f2f3f332 100644 --- a/introduction_to_python/functions/2_shut_down/Solution/solution.py +++ b/introduction_to_python/functions/2_shut_down/Solution/solution.py @@ -1,3 +1,7 @@ -# Code your solution here def shut_down(x): - return \ No newline at end of file + if x == True: + return 'SHUTDOWN' + elif x == False: + return 'SHUTDOWN ABORTED' + else: + return 'This is not a boolean value.' \ No newline at end of file diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index 0f6921b1..b5f907cd 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1,5 +1,2 @@ -# Code your solution here def concat_args(*args): - return - - + return sum(args) diff --git a/introduction_to_python/functions/3_anonymous/Solution/solution.py b/introduction_to_python/functions/3_anonymous/Solution/solution.py new file mode 100644 index 00000000..51abb9ed --- /dev/null +++ b/introduction_to_python/functions/3_anonymous/Solution/solution.py @@ -0,0 +1,5 @@ +# Code your solution here +def f(*args): + return list(map(lambda x: x % 13 == 0)) +result = f +print(result) \ No newline at end of file diff --git a/introduction_to_python/functions/3_count_even/Solution/solution.py b/introduction_to_python/functions/3_count_even/Solution/solution.py index abdfec29..a41423ea 100644 --- a/introduction_to_python/functions/3_count_even/Solution/solution.py +++ b/introduction_to_python/functions/3_count_even/Solution/solution.py @@ -1,3 +1,2 @@ -# Code your solution here def count_even(*args): - return \ No newline at end of file + return list(map(lambda x: x % 2== 0)) \ No newline at end of file diff --git a/introduction_to_python/functions/3_factorial/Solution/solution.py b/introduction_to_python/functions/3_factorial/Solution/solution.py index b733941e..9f87aa17 100644 --- a/introduction_to_python/functions/3_factorial/Solution/solution.py +++ b/introduction_to_python/functions/3_factorial/Solution/solution.py @@ -1,3 +1,5 @@ -# Code your solution here def factorial(n): - return \ No newline at end of file + factorial = 1 + if int(n) >= 1: + for i in range(1, int(n) + 1): + factorial = factorial * i \ No newline at end of file diff --git a/introduction_to_python/functions/3_total/Solution/solution.py b/introduction_to_python/functions/3_total/Solution/solution.py index 6162db4b..5d9a2e22 100644 --- a/introduction_to_python/functions/3_total/Solution/solution.py +++ b/introduction_to_python/functions/3_total/Solution/solution.py @@ -1,3 +1,5 @@ -# Code your solution here def sum_data(lst): - return \ No newline at end of file + summ = 0 + for i in l: + summ += i + return summ \ No newline at end of file From 44469f0714f1c710710036840607a52afd8eb755 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 3 Aug 2020 13:17:08 -0400 Subject: [PATCH 26/65] Working on these --- .../recursive_functions/1_array_sum/solutions/solution.py | 3 +++ .../recursive_functions/1_count_down/solutions/solution.py | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py create mode 100644 introduction_to_python/recursive_functions/1_count_down/solutions/solution.py diff --git a/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py new file mode 100644 index 00000000..4ee6cf73 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py @@ -0,0 +1,3 @@ +# Write your solution here +def sum_array(num_list): + return 0 if num_list == [] else num_list[0] + sum_array(num_list[1:]) diff --git a/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py b/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py new file mode 100644 index 00000000..4342bf27 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py @@ -0,0 +1,5 @@ +# Write your solution here +def count_down_from(num): + return num + if num >= 1: + count_down_from(num - 1) \ No newline at end of file From c05fa28af3e73ad289403fe37f318ea706007c40 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Tue, 4 Aug 2020 13:11:46 -0400 Subject: [PATCH 27/65] mid merge --- .../hello_world/3_type_change/Solution/solution.py | 4 ++++ .../unix_and_bash/2_bash_commands/solution/solution.py | 6 +++--- .../unix_and_bash/2_bash_operators/solution/solution.py | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py index 1480c6f8..465a0860 100644 --- a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -1,6 +1,10 @@ # Code your solution here object_1 = 3.2 +<<<<<<< HEAD object_2 = '2' +======= +object_2 = 2 +>>>>>>> 3b8cef1... Exercises completed print(str(object_1)) print(int(object_2)) \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py index fa9fd397..27a67e60 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = '' -TWO = '' -THREE = '' +ONE = 'mkdir testdir | cd testdir' +TWO = 'grep and textfile.txt' +THREE = 'grep -r >> contents.txt' FOUR = '' FIVE = '' SIX = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index 01c1d34c..833fa4dd 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -1,7 +1,14 @@ # Assign the correct strings below ONE = 'mkdir testdir && cd testdir' +<<<<<<< HEAD TWO = 'cat textfile.txt | grep and' THREE = 'ls >> contents.txt' FOUR = 'cd current || mkdir current' FIVE = 'pwd > currentpath.txt' +======= +TWO = 'grep and textfile.txt' +THREE = 'grep -r >> contents.txt' +FOUR = 'cd current > current' +FIVE = 'ls > currentpath.txt' +>>>>>>> 3b8cef1... Exercises completed From 9ec4c2fc04c85c428258864fb2bcc34a1de2da4b Mon Sep 17 00:00:00 2001 From: PC-coding Date: Tue, 4 Aug 2020 13:13:20 -0400 Subject: [PATCH 28/65] mid merge --- .../hello_world/3_type_change/Solution/solution.py | 4 ++++ .../2_ASCII/Solutions/solution.py | 6 +++++- .../2_operators/Solutions/solution.py | 6 +++++- .../3_bitwise_operators_1/Solutions/solution.py | 10 ++++++++++ .../unix_and_bash/2_bash_commands/solution/solution.py | 6 +++--- .../2_bash_operators/solution/solution.py | 6 ++++++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py index 465a0860..16a39845 100644 --- a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -1,10 +1,14 @@ # Code your solution here object_1 = 3.2 <<<<<<< HEAD +<<<<<<< HEAD object_2 = '2' ======= object_2 = 2 >>>>>>> 3b8cef1... Exercises completed +======= +object_2 = '2' +>>>>>>> 3569546... Exercises completed print(str(object_1)) print(int(object_2)) \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index 117c7cd9..b5f49997 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -1,2 +1,6 @@ +<<<<<<< HEAD # print('Hexadecimal') -print('Boolean') \ No newline at end of file +print('Boolean') +======= +print('Hexadecimal') +>>>>>>> 3569546... Exercises completed diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index e983d85b..ad9a36e9 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -1,2 +1,6 @@ +<<<<<<< HEAD # print('Boolean') -print('Hexadecimal') \ No newline at end of file +print('Hexadecimal') +======= +print('Boolean') +>>>>>>> 3569546... Exercises completed diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index fbf8bbd8..acd2a6b8 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -1,10 +1,20 @@ x = 0 y = 1 +<<<<<<< HEAD Answer_and = x & y Answer_or = x | y Answer_not = ~ x +======= +x & y = 0 +x | y = 1 +~ x, ~ y = 1, 0 + +Answer_and = 0 +Answer_or = 1 +Answer_not = 1, 0 +>>>>>>> 3569546... Exercises completed print(Answer_and) print(Answer_or) diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py index 27a67e60..fa9fd397 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = 'mkdir testdir | cd testdir' -TWO = 'grep and textfile.txt' -THREE = 'grep -r >> contents.txt' +ONE = '' +TWO = '' +THREE = '' FOUR = '' FIVE = '' SIX = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index 833fa4dd..2e232d71 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -2,13 +2,19 @@ # Assign the correct strings below ONE = 'mkdir testdir && cd testdir' <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> 3569546... Exercises completed TWO = 'cat textfile.txt | grep and' THREE = 'ls >> contents.txt' FOUR = 'cd current || mkdir current' FIVE = 'pwd > currentpath.txt' +<<<<<<< HEAD ======= TWO = 'grep and textfile.txt' THREE = 'grep -r >> contents.txt' FOUR = 'cd current > current' FIVE = 'ls > currentpath.txt' >>>>>>> 3b8cef1... Exercises completed +======= +>>>>>>> 3569546... Exercises completed From 73b1f9527c0a5d5e01b97618823696091c5792e3 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Tue, 4 Aug 2020 13:13:53 -0400 Subject: [PATCH 29/65] mid merge --- .../2_farm_area/Solution/solution.py | 6 ++++++ .../3_bitwise_operators_1/Solutions/solution.py | 7 +++++++ .../3_logical_operators_2/Solutions/solution.py | 8 +++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index 47344e65..a93b81b2 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1,7 +1,13 @@ # Code your solution here +<<<<<<< HEAD # length = len(input()) # breadth = len(input()) length = 6 breadth = 4 +======= +length = 6 +breadth = 4 + +>>>>>>> 39354d0... Completed Exercises data = length * breadth print(data) diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index acd2a6b8..de77bedf 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -1,6 +1,7 @@ x = 0 y = 1 +<<<<<<< HEAD <<<<<<< HEAD Answer_and = x & y @@ -15,6 +16,12 @@ Answer_or = 1 Answer_not = 1, 0 >>>>>>> 3569546... Exercises completed +======= + +Answer_and = x & y +Answer_or = x | y +Answer_not = ~ x +>>>>>>> 39354d0... Completed Exercises print(Answer_and) print(Answer_or) diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index 3cfc611d..f9f82fe4 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -1,6 +1,12 @@ +<<<<<<< HEAD x = True y = False Answer = bool(x or y) -print(Answer) \ No newline at end of file +print(Answer) +======= +x = 1 +y = 2 + +>>>>>>> 39354d0... Completed Exercises From bfdfc404ebf0d6aecb16cb68a00bb6efbda4a770 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Tue, 4 Aug 2020 13:14:23 -0400 Subject: [PATCH 30/65] mid merge --- .../1_list_max/solution/solution.py | 16 +++++++++++++++- .../3_grade/Solution/solution.py | 19 +++++++++++++++++++ .../3_string_case/Solution/solution.py | 3 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index 84e25b8d..d44faccd 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -1,3 +1,4 @@ +<<<<<<< HEAD # L = [152, 463, 1112, 1337, -10] # LIST_MAX = sorted(L)[-1] @@ -15,4 +16,17 @@ def LIST_MAX1(L): if L[4] > current_max: current_max = L[4] return current_max -LIST_MAX = LIST_MAX1(L) \ No newline at end of file +LIST_MAX = LIST_MAX1(L) +======= +L = [152, 463, 1112, 1337, -10] +# def LIST_MAX(L): +# if L == []: +# LIST_MAX1 = None +# else: +# LIST_MAX1 = sorted(L)[-1] +# return LIST_MAX1 + +# print(LIST_MAX(L)) +LIST_MAX = sorted(L)[-1] +# print(LIST_MAX) +>>>>>>> d536594... Pushing exercises diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index cc177132..6d07e662 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1,6 +1,7 @@ # Code your solution here def grade(mark): if mark >= 90: +<<<<<<< HEAD return 'A+ GRADE' elif mark >= 70: return 'B GRADE' @@ -13,4 +14,22 @@ def grade(mark): # score = int(input("Enter your grade here:")) mark = 80 print(grade(mark)) +======= + # return 'A+ GRADE' + print('A+ GRADE') + elif mark >= 70: + # return 'B GRADE' + print('B GRADE') + elif mark >= 50: + # return 'C GRADE' + print('C GRADE') + elif mark >= 35: + # return 'D GRADE' + print('D GRADE') + else: + # return 'FAIL' + print('FAIL') +score = int(input("Enter your grade here:")) +print(grade(score)) +>>>>>>> d536594... Pushing exercises # grade(score) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index 0c9227fb..eb5e9656 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1,6 +1,9 @@ # Code your solution here string_val = str(input()) +<<<<<<< HEAD +======= +>>>>>>> d536594... Pushing exercises upper_data = string_val.upper() lower_data = string_val.lower() From 352b10f5138a05246b6da56772451af0228ed3b8 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 11:32:37 -0400 Subject: [PATCH 31/65] Completed --- .../3_grade/Solution/solution.py | 20 +++++++++++++------ .../3_string_case/Solution/solution.py | 4 ++++ .../2_ASCII/Solutions/solution.py | 5 +++++ .../2_operators/Solutions/solution.py | 5 +++++ .../Solutions/solution.py | 9 +++++++++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index 6d07e662..56177324 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1,6 +1,7 @@ # Code your solution here def grade(mark): if mark >= 90: +<<<<<<< HEAD <<<<<<< HEAD return 'A+ GRADE' elif mark >= 70: @@ -17,19 +18,26 @@ def grade(mark): ======= # return 'A+ GRADE' print('A+ GRADE') +======= + return 'A+ GRADE' +>>>>>>> 9784d40... Completed elif mark >= 70: - # return 'B GRADE' - print('B GRADE') + return 'B GRADE' elif mark >= 50: - # return 'C GRADE' - print('C GRADE') + return 'C GRADE' elif mark >= 35: - # return 'D GRADE' - print('D GRADE') + return 'D GRADE' else: +<<<<<<< HEAD # return 'FAIL' print('FAIL') score = int(input("Enter your grade here:")) print(grade(score)) >>>>>>> d536594... Pushing exercises +======= + return 'FAIL' +# score = int(input("Enter your grade here:")) +mark = 80 +print(grade(mark)) +>>>>>>> 9784d40... Completed # grade(score) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index eb5e9656..4591c181 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1,9 +1,13 @@ # Code your solution here string_val = str(input()) <<<<<<< HEAD +<<<<<<< HEAD ======= >>>>>>> d536594... Pushing exercises +======= + +>>>>>>> 9784d40... Completed upper_data = string_val.upper() lower_data = string_val.lower() diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index b5f49997..bfc9e095 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -1,6 +1,11 @@ <<<<<<< HEAD +<<<<<<< HEAD # print('Hexadecimal') print('Boolean') ======= print('Hexadecimal') >>>>>>> 3569546... Exercises completed +======= +# print('Hexadecimal') +print('Boolean') +>>>>>>> 9784d40... Completed diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index ad9a36e9..4dc9e814 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -1,6 +1,11 @@ <<<<<<< HEAD +<<<<<<< HEAD # print('Boolean') print('Hexadecimal') ======= print('Boolean') >>>>>>> 3569546... Exercises completed +======= +# print('Boolean') +print('Hexadecimal') +>>>>>>> 9784d40... Completed diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index f9f82fe4..23f2bf86 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -1,4 +1,5 @@ <<<<<<< HEAD +<<<<<<< HEAD x = True y = False @@ -10,3 +11,11 @@ y = 2 >>>>>>> 39354d0... Completed Exercises +======= +x = True +y = False + +Answer = bool(x or y) + +print(Answer) +>>>>>>> 9784d40... Completed From a1dfc79c454c7a924ded0b29d6e8789ffcecf47c Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 31 Jul 2020 16:53:18 -0400 Subject: [PATCH 32/65] Completed --- .../1_list_max/solution/solution.py | 22 +++++++++++++++++++ .../2_farm_area/Solution/solution.py | 7 ++++++ 2 files changed, 29 insertions(+) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index d44faccd..3b3183c6 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -1,4 +1,5 @@ <<<<<<< HEAD +<<<<<<< HEAD # L = [152, 463, 1112, 1337, -10] # LIST_MAX = sorted(L)[-1] @@ -30,3 +31,24 @@ def LIST_MAX1(L): LIST_MAX = sorted(L)[-1] # print(LIST_MAX) >>>>>>> d536594... Pushing exercises +======= +# L = [152, 463, 1112, 1337, -10] +# LIST_MAX = sorted(L)[-1] + +# print(LIST_MAX(L)) + +L = [152, 463, 1112, 1337, -10] +def LIST_MAX1(L): + current_max = L[0] + if L[1] > current_max: + current_max = L[1] + if L[2] > current_max: + current_max = L[2] + if L[3] > current_max: + current_max = L[3] + if L[4] > current_max: + current_max = L[4] + return current_max +LIST_MAX = LIST_MAX1(L) + +>>>>>>> f07cce6... Completed diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index a93b81b2..dee3ba69 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1,5 +1,6 @@ # Code your solution here <<<<<<< HEAD +<<<<<<< HEAD # length = len(input()) # breadth = len(input()) length = 6 @@ -9,5 +10,11 @@ breadth = 4 >>>>>>> 39354d0... Completed Exercises +======= +# length = len(input()) +# breadth = len(input()) +length = 6 +breadth = 4 +>>>>>>> f07cce6... Completed data = length * breadth print(data) From fd9249cc94b0991bcae9cb5b44c727da3c1945c6 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Sun, 2 Aug 2020 15:00:48 -0400 Subject: [PATCH 33/65] Completed Exercises --- .../1_list_max/solution/solution.py | 4 ++++ .../functions/1_range/Solution/solution.py | 16 +++++++++++++++- .../1_return_hello/Solution/solution.py | 13 ++++++++++++- .../functions/2_max_value/Solution/solution.py | 16 +++++++++++++++- .../functions/2_shut_down/Solution/solution.py | 15 ++++++++++++++- .../2_variable_argument/Solution/solution.py | 8 ++++++++ .../functions/3_count_even/Solution/solution.py | 10 +++++++++- .../functions/3_factorial/Solution/solution.py | 17 ++++++++++++++++- .../functions/3_total/Solution/solution.py | 17 ++++++++++++++++- 9 files changed, 109 insertions(+), 7 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index 3b3183c6..b13396f2 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -49,6 +49,10 @@ def LIST_MAX1(L): if L[4] > current_max: current_max = L[4] return current_max +<<<<<<< HEAD LIST_MAX = LIST_MAX1(L) >>>>>>> f07cce6... Completed +======= +LIST_MAX = LIST_MAX1(L) +>>>>>>> 6cffc71... Completed Exercises diff --git a/introduction_to_python/functions/1_range/Solution/solution.py b/introduction_to_python/functions/1_range/Solution/solution.py index c5178908..4bc401f9 100644 --- a/introduction_to_python/functions/1_range/Solution/solution.py +++ b/introduction_to_python/functions/1_range/Solution/solution.py @@ -1,5 +1,19 @@ +<<<<<<< HEAD def range_100(number): if number <= 100: return 'GREATNESS' else: - return 'OOPS' \ No newline at end of file + return 'OOPS' +======= +# Code your solution here + +# number = int(input('Enter any integer value:')) +number = 99 +def result(number): + if number <= 100: + return 'GREATNESS' + else: + return 'OOPS' + +print(result(number)) +>>>>>>> 6cffc71... Completed Exercises diff --git a/introduction_to_python/functions/1_return_hello/Solution/solution.py b/introduction_to_python/functions/1_return_hello/Solution/solution.py index de2a9519..8f7b73d3 100644 --- a/introduction_to_python/functions/1_return_hello/Solution/solution.py +++ b/introduction_to_python/functions/1_return_hello/Solution/solution.py @@ -1,3 +1,14 @@ +<<<<<<< HEAD def hello(name): val1 = 'Hello' + name - return val1 \ No newline at end of file + return val1 +======= +# Code your solution here +# name = input('Enter your name: ') +name = 'Newton' +def result(name): + val1 = 'Hello' + name + return val1 + +print(result(name)) +>>>>>>> 6cffc71... Completed Exercises diff --git a/introduction_to_python/functions/2_max_value/Solution/solution.py b/introduction_to_python/functions/2_max_value/Solution/solution.py index 0f3cf2e3..82dd4921 100644 --- a/introduction_to_python/functions/2_max_value/Solution/solution.py +++ b/introduction_to_python/functions/2_max_value/Solution/solution.py @@ -1,3 +1,17 @@ +<<<<<<< HEAD def max_val(a, b, c): max_value = max(a, b, c) - return max_value \ No newline at end of file + return max_value +======= +# Code your solution here +# a = int(input('Enter an integer value: ')) +# b = int(input('Enter another integer value: ')) +# c = int(input('Enter one last integer value: ')) +a = 1 +b = 2 +c = 3 +def result(a, b, c): + max_value = max(a, b, c) + return max_value +print(result(a, b, c)) +>>>>>>> 6cffc71... Completed Exercises diff --git a/introduction_to_python/functions/2_shut_down/Solution/solution.py b/introduction_to_python/functions/2_shut_down/Solution/solution.py index f2f3f332..b48fc1e7 100644 --- a/introduction_to_python/functions/2_shut_down/Solution/solution.py +++ b/introduction_to_python/functions/2_shut_down/Solution/solution.py @@ -1,7 +1,20 @@ +<<<<<<< HEAD def shut_down(x): +======= +# Code your solution here +# x = bool(input('Enter a boolean value: ')) +x = 'false' +def data(x): +>>>>>>> 6cffc71... Completed Exercises if x == True: return 'SHUTDOWN' elif x == False: return 'SHUTDOWN ABORTED' else: - return 'This is not a boolean value.' \ No newline at end of file +<<<<<<< HEAD + return 'This is not a boolean value.' +======= + return 'This is not a boolean value.' +result = data(x) +print(result) +>>>>>>> 6cffc71... Completed Exercises diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index b5f907cd..c79f21ee 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1,2 +1,10 @@ +<<<<<<< HEAD def concat_args(*args): return sum(args) +======= +# Code your solution here +def f(*args): + return sum(args) +result = f +print(result) +>>>>>>> 6cffc71... Completed Exercises diff --git a/introduction_to_python/functions/3_count_even/Solution/solution.py b/introduction_to_python/functions/3_count_even/Solution/solution.py index a41423ea..35b83fc3 100644 --- a/introduction_to_python/functions/3_count_even/Solution/solution.py +++ b/introduction_to_python/functions/3_count_even/Solution/solution.py @@ -1,2 +1,10 @@ +<<<<<<< HEAD def count_even(*args): - return list(map(lambda x: x % 2== 0)) \ No newline at end of file + return list(map(lambda x: x % 2== 0)) +======= +# Code your solution here +def f(*args): + return list(map(lambda x: x % 2== 0)) +result = f +print(result) +>>>>>>> 6cffc71... Completed Exercises diff --git a/introduction_to_python/functions/3_factorial/Solution/solution.py b/introduction_to_python/functions/3_factorial/Solution/solution.py index 9f87aa17..3ef26019 100644 --- a/introduction_to_python/functions/3_factorial/Solution/solution.py +++ b/introduction_to_python/functions/3_factorial/Solution/solution.py @@ -1,5 +1,20 @@ +<<<<<<< HEAD def factorial(n): factorial = 1 if int(n) >= 1: for i in range(1, int(n) + 1): - factorial = factorial * i \ No newline at end of file + factorial = factorial * i +======= +# Code your solution here +# n = int(input(Enter any integer: )) +n = 4 + +def numbers(n): + factorial = 1 + if int(n) >= 1: + for i in range(1, int(n) + 1): + factorial = factorial * i + +result = numbers(n) +print(result) +>>>>>>> 6cffc71... Completed Exercises diff --git a/introduction_to_python/functions/3_total/Solution/solution.py b/introduction_to_python/functions/3_total/Solution/solution.py index 5d9a2e22..544c3780 100644 --- a/introduction_to_python/functions/3_total/Solution/solution.py +++ b/introduction_to_python/functions/3_total/Solution/solution.py @@ -1,5 +1,20 @@ +<<<<<<< HEAD def sum_data(lst): summ = 0 for i in l: summ += i - return summ \ No newline at end of file + return summ +======= +# Code your solution here +l = [10, 20, 30, 40, 50, 60] +# l = [1, 2, 3, 4, 5] +# used the list provided in test_solution.py for the test to work + +def a_list(l): + summ = 0 + for i in l: + summ += i + return summ +result = a_list(l) +print(result) +>>>>>>> 6cffc71... Completed Exercises From 6b4c0cf256e61eed3e61671a10f53e1f8187e688 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 3 Aug 2020 15:20:59 -0400 Subject: [PATCH 34/65] Updated and completed --- .../functions/1_default_args/Solution/solution.py | 2 +- .../functions/1_range/Solution/solution.py | 5 ++++- .../functions/1_return_hello/Solution/solution.py | 6 +++++- .../functions/2_max_value/Solution/solution.py | 5 ++++- .../functions/2_shut_down/Solution/solution.py | 8 +++++++- .../2_variable_argument/Solution/solution.py | 8 +++++++- .../functions/3_anonymous/Solution/solution.py | 4 +--- .../functions/3_count_even/Solution/solution.py | 5 ++++- .../3_div_by_3_annonymous/Solution/solution.py | 2 +- .../functions/3_factorial/Solution/solution.py | 12 ++++++++++-- .../functions/3_total/Solution/solution.py | 7 +++++-- 11 files changed, 49 insertions(+), 15 deletions(-) diff --git a/introduction_to_python/functions/1_default_args/Solution/solution.py b/introduction_to_python/functions/1_default_args/Solution/solution.py index 55bdef79..4c64139d 100644 --- a/introduction_to_python/functions/1_default_args/Solution/solution.py +++ b/introduction_to_python/functions/1_default_args/Solution/solution.py @@ -1,3 +1,3 @@ # Code your solution here def concat_input(val_1="Hello ",val_2="World"): - return \ No newline at end of file + return val_1 + val_2 \ No newline at end of file diff --git a/introduction_to_python/functions/1_range/Solution/solution.py b/introduction_to_python/functions/1_range/Solution/solution.py index 4bc401f9..43f0d5a5 100644 --- a/introduction_to_python/functions/1_range/Solution/solution.py +++ b/introduction_to_python/functions/1_range/Solution/solution.py @@ -1,8 +1,8 @@ -<<<<<<< HEAD def range_100(number): if number <= 100: return 'GREATNESS' else: +<<<<<<< HEAD return 'OOPS' ======= # Code your solution here @@ -17,3 +17,6 @@ def result(number): print(result(number)) >>>>>>> 6cffc71... Completed Exercises +======= + return 'OOPS' +>>>>>>> 3f12b16... Updated and completed diff --git a/introduction_to_python/functions/1_return_hello/Solution/solution.py b/introduction_to_python/functions/1_return_hello/Solution/solution.py index 8f7b73d3..9b622510 100644 --- a/introduction_to_python/functions/1_return_hello/Solution/solution.py +++ b/introduction_to_python/functions/1_return_hello/Solution/solution.py @@ -1,5 +1,5 @@ -<<<<<<< HEAD def hello(name): +<<<<<<< HEAD val1 = 'Hello' + name return val1 ======= @@ -12,3 +12,7 @@ def result(name): print(result(name)) >>>>>>> 6cffc71... Completed Exercises +======= + val1 = 'Hello ' + name + return val1 +>>>>>>> 3f12b16... Updated and completed diff --git a/introduction_to_python/functions/2_max_value/Solution/solution.py b/introduction_to_python/functions/2_max_value/Solution/solution.py index 82dd4921..f296d700 100644 --- a/introduction_to_python/functions/2_max_value/Solution/solution.py +++ b/introduction_to_python/functions/2_max_value/Solution/solution.py @@ -1,6 +1,6 @@ -<<<<<<< HEAD def max_val(a, b, c): max_value = max(a, b, c) +<<<<<<< HEAD return max_value ======= # Code your solution here @@ -15,3 +15,6 @@ def result(a, b, c): return max_value print(result(a, b, c)) >>>>>>> 6cffc71... Completed Exercises +======= + return max_value +>>>>>>> 3f12b16... Updated and completed diff --git a/introduction_to_python/functions/2_shut_down/Solution/solution.py b/introduction_to_python/functions/2_shut_down/Solution/solution.py index b48fc1e7..fd818549 100644 --- a/introduction_to_python/functions/2_shut_down/Solution/solution.py +++ b/introduction_to_python/functions/2_shut_down/Solution/solution.py @@ -1,16 +1,19 @@ -<<<<<<< HEAD def shut_down(x): +<<<<<<< HEAD ======= # Code your solution here # x = bool(input('Enter a boolean value: ')) x = 'false' def data(x): >>>>>>> 6cffc71... Completed Exercises +======= +>>>>>>> 3f12b16... Updated and completed if x == True: return 'SHUTDOWN' elif x == False: return 'SHUTDOWN ABORTED' else: +<<<<<<< HEAD <<<<<<< HEAD return 'This is not a boolean value.' ======= @@ -18,3 +21,6 @@ def data(x): result = data(x) print(result) >>>>>>> 6cffc71... Completed Exercises +======= + return 'This is not a boolean value.' +>>>>>>> 3f12b16... Updated and completed diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index c79f21ee..3149a9d1 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1,5 +1,7 @@ -<<<<<<< HEAD +# def concat_args(*args): +# return sum(args) def concat_args(*args): +<<<<<<< HEAD return sum(args) ======= # Code your solution here @@ -8,3 +10,7 @@ def f(*args): result = f print(result) >>>>>>> 6cffc71... Completed Exercises +======= + args.split([]) + return ' '.join(args) +>>>>>>> 3f12b16... Updated and completed diff --git a/introduction_to_python/functions/3_anonymous/Solution/solution.py b/introduction_to_python/functions/3_anonymous/Solution/solution.py index 51abb9ed..f3496960 100644 --- a/introduction_to_python/functions/3_anonymous/Solution/solution.py +++ b/introduction_to_python/functions/3_anonymous/Solution/solution.py @@ -1,5 +1,3 @@ # Code your solution here def f(*args): - return list(map(lambda x: x % 13 == 0)) -result = f -print(result) \ No newline at end of file + return list(map(lambda x: x % 13 == 0)) \ No newline at end of file diff --git a/introduction_to_python/functions/3_count_even/Solution/solution.py b/introduction_to_python/functions/3_count_even/Solution/solution.py index 35b83fc3..36d7adb5 100644 --- a/introduction_to_python/functions/3_count_even/Solution/solution.py +++ b/introduction_to_python/functions/3_count_even/Solution/solution.py @@ -1,5 +1,5 @@ -<<<<<<< HEAD def count_even(*args): +<<<<<<< HEAD return list(map(lambda x: x % 2== 0)) ======= # Code your solution here @@ -8,3 +8,6 @@ def f(*args): result = f print(result) >>>>>>> 6cffc71... Completed Exercises +======= + return len(list(filter(lambda x: x % 2 == 0, args))) +>>>>>>> 3f12b16... Updated and completed diff --git a/introduction_to_python/functions/3_div_by_3_annonymous/Solution/solution.py b/introduction_to_python/functions/3_div_by_3_annonymous/Solution/solution.py index aadbaeb8..043c48b3 100644 --- a/introduction_to_python/functions/3_div_by_3_annonymous/Solution/solution.py +++ b/introduction_to_python/functions/3_div_by_3_annonymous/Solution/solution.py @@ -1,3 +1,3 @@ # Code your solution here def div_by_3(*args): - return \ No newline at end of file + return list(filter(lambda x: x % 3 == 0, args)) \ No newline at end of file diff --git a/introduction_to_python/functions/3_factorial/Solution/solution.py b/introduction_to_python/functions/3_factorial/Solution/solution.py index 3ef26019..21cabb12 100644 --- a/introduction_to_python/functions/3_factorial/Solution/solution.py +++ b/introduction_to_python/functions/3_factorial/Solution/solution.py @@ -1,9 +1,14 @@ -<<<<<<< HEAD def factorial(n): factorial = 1 - if int(n) >= 1: + if n < 0: + return None + elif None == 0: + return None + # if int(n) >= 1: + else: for i in range(1, int(n) + 1): factorial = factorial * i +<<<<<<< HEAD ======= # Code your solution here # n = int(input(Enter any integer: )) @@ -18,3 +23,6 @@ def numbers(n): result = numbers(n) print(result) >>>>>>> 6cffc71... Completed Exercises +======= + return factorial +>>>>>>> 3f12b16... Updated and completed diff --git a/introduction_to_python/functions/3_total/Solution/solution.py b/introduction_to_python/functions/3_total/Solution/solution.py index 544c3780..893504e5 100644 --- a/introduction_to_python/functions/3_total/Solution/solution.py +++ b/introduction_to_python/functions/3_total/Solution/solution.py @@ -1,8 +1,8 @@ -<<<<<<< HEAD def sum_data(lst): summ = 0 - for i in l: + for i in lst: summ += i +<<<<<<< HEAD return summ ======= # Code your solution here @@ -18,3 +18,6 @@ def a_list(l): result = a_list(l) print(result) >>>>>>> 6cffc71... Completed Exercises +======= + return summ +>>>>>>> 3f12b16... Updated and completed From cb2d917ac14da8f4f23d09c78c9de158bff5ca6c Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 3 Aug 2020 22:23:41 -0400 Subject: [PATCH 35/65] Completed --- .../functions/2_variable_argument/Solution/solution.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index 3149a9d1..8f36e726 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1,6 +1,5 @@ -# def concat_args(*args): -# return sum(args) def concat_args(*args): +<<<<<<< HEAD <<<<<<< HEAD return sum(args) ======= @@ -14,3 +13,6 @@ def f(*args): args.split([]) return ' '.join(args) >>>>>>> 3f12b16... Updated and completed +======= + return ''.join(args) +>>>>>>> 95a635a... Completed From c077c8e1ac2a242736b55095c315acd47675f3df Mon Sep 17 00:00:00 2001 From: PC-coding Date: Tue, 4 Aug 2020 16:41:19 -0400 Subject: [PATCH 36/65] Completed exercises --- .../recursive_functions/1_array_sum/solution/solution.py | 5 ++++- .../recursive_functions/1_array_sum/solutions/solution.py | 2 +- .../recursive_functions/1_count_down/solution/solution.py | 4 +++- .../recursive_functions/1_find_power/solution/solution.py | 7 ++++++- .../1_reverse_string/solution/solution.py | 5 ++++- .../recursive_functions/2_count_ways/solution/solution.py | 7 ++++++- .../2_find_factorial/solution/solution.py | 5 ++++- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/introduction_to_python/recursive_functions/1_array_sum/solution/solution.py b/introduction_to_python/recursive_functions/1_array_sum/solution/solution.py index 8fd0f657..98755e88 100644 --- a/introduction_to_python/recursive_functions/1_array_sum/solution/solution.py +++ b/introduction_to_python/recursive_functions/1_array_sum/solution/solution.py @@ -1,3 +1,6 @@ # Write your solution here def sum_array(num_list): - return \ No newline at end of file + if num_list == []: + return 0 + else: + return num_list.pop() + sum_array(num_list) \ No newline at end of file diff --git a/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py index 4ee6cf73..f99e96e7 100644 --- a/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py +++ b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py @@ -1,3 +1,3 @@ # Write your solution here def sum_array(num_list): - return 0 if num_list == [] else num_list[0] + sum_array(num_list[1:]) + return 0 if num_list == [] else num_list[0] + sum_array(num_list[1:]) \ No newline at end of file diff --git a/introduction_to_python/recursive_functions/1_count_down/solution/solution.py b/introduction_to_python/recursive_functions/1_count_down/solution/solution.py index 309e8ed7..b6ce9f00 100644 --- a/introduction_to_python/recursive_functions/1_count_down/solution/solution.py +++ b/introduction_to_python/recursive_functions/1_count_down/solution/solution.py @@ -1,3 +1,5 @@ # Write your solution here def count_down_from(num): - return \ No newline at end of file + if num >= 1: + print(num) + count_down_from(num-1) \ No newline at end of file diff --git a/introduction_to_python/recursive_functions/1_find_power/solution/solution.py b/introduction_to_python/recursive_functions/1_find_power/solution/solution.py index 7aa17747..fcc11c10 100644 --- a/introduction_to_python/recursive_functions/1_find_power/solution/solution.py +++ b/introduction_to_python/recursive_functions/1_find_power/solution/solution.py @@ -1,3 +1,8 @@ # Write your solution here def power(a, b): - return \ No newline at end of file + if a == 0: + return 0 + elif b == 0: + return 1 + else: + return a*power(a,b-1) \ No newline at end of file diff --git a/introduction_to_python/recursive_functions/1_reverse_string/solution/solution.py b/introduction_to_python/recursive_functions/1_reverse_string/solution/solution.py index 4b4c9b1d..445f3475 100644 --- a/introduction_to_python/recursive_functions/1_reverse_string/solution/solution.py +++ b/introduction_to_python/recursive_functions/1_reverse_string/solution/solution.py @@ -1,3 +1,6 @@ # Write your solution here def reverse(string): - return \ No newline at end of file + if string == '': + return '' + else: + return reverse(string[1:]) + string[0] \ No newline at end of file diff --git a/introduction_to_python/recursive_functions/2_count_ways/solution/solution.py b/introduction_to_python/recursive_functions/2_count_ways/solution/solution.py index 4921b2c4..66d9207c 100644 --- a/introduction_to_python/recursive_functions/2_count_ways/solution/solution.py +++ b/introduction_to_python/recursive_functions/2_count_ways/solution/solution.py @@ -1,3 +1,8 @@ # Write your solution here +def stairs(n): + if n <= 1: + return n + else: + return stairs(n - 1) + stairs(n - 2) def count_ways(steps): - return + return stairs(steps + 1) diff --git a/introduction_to_python/recursive_functions/2_find_factorial/solution/solution.py b/introduction_to_python/recursive_functions/2_find_factorial/solution/solution.py index 41e8caef..894cbb9f 100644 --- a/introduction_to_python/recursive_functions/2_find_factorial/solution/solution.py +++ b/introduction_to_python/recursive_functions/2_find_factorial/solution/solution.py @@ -1,3 +1,6 @@ # Write your solution here def factorial_recursive(n): - return \ No newline at end of file + if n <= 1: + return 1 + else: + return n * factorial_recursive(n-1) \ No newline at end of file From 3cdad4e8d56763d057bbafa05e6a498b6773cedd Mon Sep 17 00:00:00 2001 From: PC-coding Date: Tue, 4 Aug 2020 21:28:25 -0400 Subject: [PATCH 37/65] Exercises completed --- .../2_fibonacci/solution/solution.py | 7 ++++- .../3_merge_sort/solution/solution.py | 27 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/introduction_to_python/recursive_functions/2_fibonacci/solution/solution.py b/introduction_to_python/recursive_functions/2_fibonacci/solution/solution.py index 129c4332..e44b28ad 100644 --- a/introduction_to_python/recursive_functions/2_fibonacci/solution/solution.py +++ b/introduction_to_python/recursive_functions/2_fibonacci/solution/solution.py @@ -1,3 +1,8 @@ # Write your solution here def fibonacci(n): - return + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return (fibonacci(n-1) + fibonacci(n-2)) diff --git a/introduction_to_python/recursive_functions/3_merge_sort/solution/solution.py b/introduction_to_python/recursive_functions/3_merge_sort/solution/solution.py index a66e3e81..d3e47862 100644 --- a/introduction_to_python/recursive_functions/3_merge_sort/solution/solution.py +++ b/introduction_to_python/recursive_functions/3_merge_sort/solution/solution.py @@ -1,3 +1,28 @@ # Write your solution here def custom_sort(num_list): - return \ No newline at end of file + if len(num_list)>1: + mid = len(num_list) // 2 + left = num_list[:mid] + right = num_list[mid:] + custom_sort(left) + custom_sort(right) + a = b = c = 0 + + while a < len(left) and b < len(right): + if left[a] < right[b]: + num_list[c] = left[a] + a += 1 + c += 1 + else: + num_list[c] = right[b] + b += 1 + c += 1 + while a < len(left): + num_list[c] = left[a] + a += 1 + c += 1 + while b < len(right): + num_list[c] = right[b] + b += 1 + c += 1 + return num_list \ No newline at end of file From c110075eee5a9d20d5f6e0ac6cce48f07abb5bfb Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 5 Aug 2020 13:03:53 -0400 Subject: [PATCH 38/65] completed --- .../3_towers_of_hanoi/solution/solution.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/introduction_to_python/recursive_functions/3_towers_of_hanoi/solution/solution.py b/introduction_to_python/recursive_functions/3_towers_of_hanoi/solution/solution.py index b2ab499c..68d0b4c2 100644 --- a/introduction_to_python/recursive_functions/3_towers_of_hanoi/solution/solution.py +++ b/introduction_to_python/recursive_functions/3_towers_of_hanoi/solution/solution.py @@ -1,3 +1,10 @@ # Write your solution here def tower_of_hanoi(n , from_rod, to_rod, aux_rod): - return + if n <= 1: + return n + else: + counter = tower_of_hanoi(n-1, from_rod, aux_rod, to_rod) + to_rod.append(from_rod.pop()) + counter += 1 + counter += tower_of_hanoi(n-1, aux_rod, to_rod, from_rod) + return counter From 25b1ea695b7364166f31b05b2d42c78871039bfe Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 5 Aug 2020 19:28:18 -0400 Subject: [PATCH 39/65] completed --- .../classes/2_unique_subsets/solution/solution.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/introduction_to_python/classes/2_unique_subsets/solution/solution.py b/introduction_to_python/classes/2_unique_subsets/solution/solution.py index ff5e3a7d..0e50eeb1 100644 --- a/introduction_to_python/classes/2_unique_subsets/solution/solution.py +++ b/introduction_to_python/classes/2_unique_subsets/solution/solution.py @@ -1,3 +1,7 @@ class py_solution: def sub_sets(self, sset): - return + return self.subsets1([], sorted(sset)) + def subsets1(self, current, sset): + if sset: + return self.subsets1(current, sset[1:]) + self.subsets1(current + [sset[0]], sset[1:]) + return [current] \ No newline at end of file From d76cd1f5b86b80aa356a606a0cdce1491bb604c8 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 5 Aug 2020 19:29:14 -0400 Subject: [PATCH 40/65] completed --- .../1_convert_to_upper/solution/solution.py | 10 ++++++++- .../1_implement_pow/solution/solution.py | 16 +++++++++++++- .../1_reverse_string/solution/solution.py | 4 +++- .../2_roman_to_int/solution/solution.py | 9 +++++++- .../2_string_parenthesis/solution/solution.py | 8 ++++++- .../solution/solution.py | 21 +++++++++++++------ 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/introduction_to_python/classes/1_convert_to_upper/solution/solution.py b/introduction_to_python/classes/1_convert_to_upper/solution/solution.py index 29b766c0..5b7f482e 100644 --- a/introduction_to_python/classes/1_convert_to_upper/solution/solution.py +++ b/introduction_to_python/classes/1_convert_to_upper/solution/solution.py @@ -1,3 +1,11 @@ # Write your solution here class MyString(): - ... \ No newline at end of file + def __init__(self): + self.input_string = None + def set_string(self, input_string): + self.input_string = input_string + def upper_string(self): + if self.input_string == None: + return 'undefined' + else: + return self.input_string.upper() \ No newline at end of file diff --git a/introduction_to_python/classes/1_implement_pow/solution/solution.py b/introduction_to_python/classes/1_implement_pow/solution/solution.py index d33cf4ad..8cf8670e 100644 --- a/introduction_to_python/classes/1_implement_pow/solution/solution.py +++ b/introduction_to_python/classes/1_implement_pow/solution/solution.py @@ -1,3 +1,17 @@ class py_solution: def pow(self, x, n): - ... \ No newline at end of file + if x == 0 or x == 1 or n == 1: + return x + if x == -1: + if n % 2 == 0: + return 1 + else: + return -1 + if n == 0: + return 1 + if n < 0: + return 1 / self.pow(x, -n) + val = self.pow(x, n //2) + if n % 2 == 0: + return val * val + return val * val * x \ No newline at end of file diff --git a/introduction_to_python/classes/1_reverse_string/solution/solution.py b/introduction_to_python/classes/1_reverse_string/solution/solution.py index 34d5e5b4..651a3861 100644 --- a/introduction_to_python/classes/1_reverse_string/solution/solution.py +++ b/introduction_to_python/classes/1_reverse_string/solution/solution.py @@ -1,3 +1,5 @@ class py_solution: def reverse_words(self, str): - return ... \ No newline at end of file + words = str.split() + words = words[::-1] + return ' '.join(words) \ No newline at end of file diff --git a/introduction_to_python/classes/2_roman_to_int/solution/solution.py b/introduction_to_python/classes/2_roman_to_int/solution/solution.py index 066c943d..026544a6 100644 --- a/introduction_to_python/classes/2_roman_to_int/solution/solution.py +++ b/introduction_to_python/classes/2_roman_to_int/solution/solution.py @@ -1,3 +1,10 @@ class py_solution: def roman_to_int(self, s): - return \ No newline at end of file + rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} + int_val = 0 + for i in range(len(s)): + if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]: + int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]] + else: + int_val += rom_val[s[i]] + return int_val \ No newline at end of file diff --git a/introduction_to_python/classes/2_string_parenthesis/solution/solution.py b/introduction_to_python/classes/2_string_parenthesis/solution/solution.py index 9fabcbf8..2a852a63 100644 --- a/introduction_to_python/classes/2_string_parenthesis/solution/solution.py +++ b/introduction_to_python/classes/2_string_parenthesis/solution/solution.py @@ -1,3 +1,9 @@ class py_solution: def is_valid_parenthese(self, str): - return \ No newline at end of file + stack, pchar = [], {"(": ")", "{": "}", "[": "]"} + for parentheses in str: + if parentheses in pchar: + stack.append(parentheses) + elif len(stack) == 0 or pchar[stack.pop()] != parentheses: + return False + return len(stack) == 0 \ No newline at end of file diff --git a/introduction_to_python/classes/3_multiple_inheritance/solution/solution.py b/introduction_to_python/classes/3_multiple_inheritance/solution/solution.py index de242a02..302c2ecd 100644 --- a/introduction_to_python/classes/3_multiple_inheritance/solution/solution.py +++ b/introduction_to_python/classes/3_multiple_inheritance/solution/solution.py @@ -1,21 +1,30 @@ class Clock(object): def __init__(self, hrs=0, mins=0, secs=0): - pass + self.hrs = hrs + self.mins = mins + self.secs = secs def __str__(self): - return + return "{0:02d}:{1:02d}:{2:02d}".format(self.hrs, self.mins, self.secs) class Calendar(object): def __init__(self, day=1, month=1, year=2020): - pass + self.day = day + self.month = month + self.year = year def __str__(self): - return + return "{0:02d}/{1:02d}/{2:4d}".format(self.day, self.month, self.year) class CalendarClock(Clock, Calendar): def __init__(self, day, month, year, hrs, mins, secs): - pass + self.day = day + self.month = month + self.year = year + self.hrs = hrs + self.mins = mins + self.secs = secs def __str__(self): - return \ No newline at end of file + return "{0:02d}/{1:02d}/{2:4d}".format(self.day, self.month, self.year) + ', ' + "{0:02d}:{1:02d}:{2:02d}".format(self.hrs, self.mins, self.secs) \ No newline at end of file From a4ef3ab624f4b141d8606d66ba41f99c675a1ae5 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 6 Aug 2020 16:26:08 -0400 Subject: [PATCH 41/65] Completed Exercises --- .../1_print_vector/solution/solution.py | 6 +++-- .../solution/solution.py | 5 +++- .../2_add_vectors/solution/solution.py | 6 +++-- .../2_dot_product/solution/solution.py | 6 +++-- .../2_equal_comparison/solution/solution.py | 6 +++-- .../2_magnitude/solution/solution.py | 6 +++-- .../2_sub_vectors/solution/solution.py | 6 +++-- .../3_comparison_lt_gt/solution/solution.py | 10 ++++---- .../3_sort_vectors/solution/solution.py | 16 +++++++------ .../1_implement_pow/solution/solution.py | 23 ++++++------------- 10 files changed, 50 insertions(+), 40 deletions(-) diff --git a/introduction_to_python/class_protocols/1_print_vector/solution/solution.py b/introduction_to_python/class_protocols/1_print_vector/solution/solution.py index 4be32358..db0a7a40 100644 --- a/introduction_to_python/class_protocols/1_print_vector/solution/solution.py +++ b/introduction_to_python/class_protocols/1_print_vector/solution/solution.py @@ -1,6 +1,8 @@ class Vector3D: def __init__(self, x=0, y=0, z=0): - pass + self.x = x + self.y = y + self.z = z def __str__(self): - return \ No newline at end of file + return f'(x = {str(self.x)}, y = {str(self.y)}, z = {str(self.z)})' \ No newline at end of file diff --git a/introduction_to_python/class_protocols/1_vector_class_constructor/solution/solution.py b/introduction_to_python/class_protocols/1_vector_class_constructor/solution/solution.py index 77118a08..e135d5a4 100644 --- a/introduction_to_python/class_protocols/1_vector_class_constructor/solution/solution.py +++ b/introduction_to_python/class_protocols/1_vector_class_constructor/solution/solution.py @@ -1,2 +1,5 @@ class Vector3D: - pass + def __init__(self, x=0, y=0, z=0): + self.x = x + self.y = y + self.z = z diff --git a/introduction_to_python/class_protocols/2_add_vectors/solution/solution.py b/introduction_to_python/class_protocols/2_add_vectors/solution/solution.py index 468bcf31..2bab55fe 100644 --- a/introduction_to_python/class_protocols/2_add_vectors/solution/solution.py +++ b/introduction_to_python/class_protocols/2_add_vectors/solution/solution.py @@ -1,6 +1,8 @@ class Vector3D: def __init__(self, x=0, y=0, z=0): - pass + self.x = x + self.y = y + self.z = z def __add__(self, other): - return + return Vector3D(self.x + other.x, self.y + other.y, self.z + other.z) diff --git a/introduction_to_python/class_protocols/2_dot_product/solution/solution.py b/introduction_to_python/class_protocols/2_dot_product/solution/solution.py index 60007f82..9523afdd 100644 --- a/introduction_to_python/class_protocols/2_dot_product/solution/solution.py +++ b/introduction_to_python/class_protocols/2_dot_product/solution/solution.py @@ -1,6 +1,8 @@ class Vector3D: def __init__(self, x=0, y=0, z=0): - pass + self.x = x + self.y = y + self.z = z def __mul__(self, other): - return + return (self.x*other.x) + (self.y*other.y) + (self.z*other.z) diff --git a/introduction_to_python/class_protocols/2_equal_comparison/solution/solution.py b/introduction_to_python/class_protocols/2_equal_comparison/solution/solution.py index 82778c46..d5e6398e 100644 --- a/introduction_to_python/class_protocols/2_equal_comparison/solution/solution.py +++ b/introduction_to_python/class_protocols/2_equal_comparison/solution/solution.py @@ -1,6 +1,8 @@ class Vector3D: def __init__(self, x=0, y=0, z=0): - pass + self.x = x + self.y = y + self.z = z def __eq__(self, other): - return + return self.x == other.x and self.y == other.y and self.z == other.z \ No newline at end of file diff --git a/introduction_to_python/class_protocols/2_magnitude/solution/solution.py b/introduction_to_python/class_protocols/2_magnitude/solution/solution.py index afd886cb..6c4f716f 100644 --- a/introduction_to_python/class_protocols/2_magnitude/solution/solution.py +++ b/introduction_to_python/class_protocols/2_magnitude/solution/solution.py @@ -1,7 +1,9 @@ import math class Vector3D: def __init__(self, x=0, y=0, z=0): - pass + self.x = x + self.y = y + self.z = z def magnitude(self): - return + return math.sqrt(self.x**2 + self.y**2 + self.z**2) diff --git a/introduction_to_python/class_protocols/2_sub_vectors/solution/solution.py b/introduction_to_python/class_protocols/2_sub_vectors/solution/solution.py index a44d8c1d..e2354a2c 100644 --- a/introduction_to_python/class_protocols/2_sub_vectors/solution/solution.py +++ b/introduction_to_python/class_protocols/2_sub_vectors/solution/solution.py @@ -1,6 +1,8 @@ class Vector3D: def __init__(self, x=0, y=0, z=0): - pass + self.x = x + self.y = y + self.z = z def __sub__(self, other): - return + return Vector3D(self.x-other.x, self.y-other.y, self.z-other.z) \ No newline at end of file diff --git a/introduction_to_python/class_protocols/3_comparison_lt_gt/solution/solution.py b/introduction_to_python/class_protocols/3_comparison_lt_gt/solution/solution.py index a82925e2..146ee698 100644 --- a/introduction_to_python/class_protocols/3_comparison_lt_gt/solution/solution.py +++ b/introduction_to_python/class_protocols/3_comparison_lt_gt/solution/solution.py @@ -1,13 +1,15 @@ import math class Vector3D: def __init__(self, x=0, y=0, z=0): - pass + self.x = x + self.y = y + self.z = z def magnitude(self): - return + return math.sqrt(self.x**2 + self.y**2 + self.z**2) def __lt__(self, other): - return + return self.magnitude() < other.magnitude() def __gt__(self, other): - return + return self.magnitude() > other.magnitude() diff --git a/introduction_to_python/class_protocols/3_sort_vectors/solution/solution.py b/introduction_to_python/class_protocols/3_sort_vectors/solution/solution.py index 812b5bc6..fed2065f 100644 --- a/introduction_to_python/class_protocols/3_sort_vectors/solution/solution.py +++ b/introduction_to_python/class_protocols/3_sort_vectors/solution/solution.py @@ -1,23 +1,25 @@ import math class Vector3D: def __init__(self, x=0, y=0, z=0): - pass + self.x = x + self.y = y + self.z = z def __str__(self): - return + return f'(x = {str(self.x)}, y = {str(self.y)}, z = {str(self.z)})' def magnitude(self): - return + return math.sqrt(self.x**2 + self.y**2 + self.z**2) def __lt__(self, other): - return + return self.magnitude() < other.magnitude() def __gt__(self, other): - return + return self.magnitude() > other.magnitude() def __eq__(self, other): - return + return self.x == other.x and self.y == other.y and self.z == other.z def sort_vectors(vect_lst): - return \ No newline at end of file + return sorted(vect_lst) \ No newline at end of file diff --git a/introduction_to_python/classes/1_implement_pow/solution/solution.py b/introduction_to_python/classes/1_implement_pow/solution/solution.py index 8cf8670e..afdee239 100644 --- a/introduction_to_python/classes/1_implement_pow/solution/solution.py +++ b/introduction_to_python/classes/1_implement_pow/solution/solution.py @@ -1,17 +1,8 @@ class py_solution: - def pow(self, x, n): - if x == 0 or x == 1 or n == 1: - return x - if x == -1: - if n % 2 == 0: - return 1 - else: - return -1 - if n == 0: - return 1 - if n < 0: - return 1 / self.pow(x, -n) - val = self.pow(x, n //2) - if n % 2 == 0: - return val * val - return val * val * x \ No newline at end of file + def pow(self, x, n): + if x == 0: + return 0 + elif n == 0: + return 1 + else: + return x*pow(x, n-1) \ No newline at end of file From 68b3da01160c7cc698362c89395904c45abfd452 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Sun, 9 Aug 2020 12:22:54 -0400 Subject: [PATCH 42/65] Partially complete, working on last exercise --- .../1_addition/Solution/app_solution.py | 7 +++++++ .../1_addition/Solution/model_solution.py | 4 ++-- .../1_addition/Solution/view_solution.py | 7 +++---- .../1_delete_key/Solution/app_solution.py | 6 ++++++ .../1_delete_key/Solution/model_solution.py | 5 ++--- .../1_delete_key/Solution/view_solution.py | 4 ++-- .../1_details/Solution/app_solution.py | 5 +++++ .../1_details/Solution/model_solution.py | 2 +- .../1_details/Solution/view_solution.py | 6 +++--- .../1_update_list/Solution/app_solution.py | 10 +++++++++- .../1_update_list/Solution/model_solution.py | 4 +++- .../1_update_list/Solution/view_solution.py | 4 ++-- .../2_books/Solution/app_solution.py | 7 +++++++ .../2_books/Solution/model_solution.py | 18 ++++++++---------- .../2_books/Solution/view_solution.py | 6 +++--- .../2_file_write/Solution/app_solution.py | 8 ++++++++ .../2_file_write/Solution/model_solution.py | 9 ++++++--- .../2_file_write/Solution/view_solution.py | 8 +++----- .../2_file_write/filename_x.txt | 1 + .../Solution/app_solution.py | 7 +++++++ .../Solution/model_solution.py | 7 +++---- .../Solution/view_solution.py | 8 ++++---- .../3_json_match/Solution/app_solution.py | 11 +++++++++++ .../3_json_match/Solution/model_solution.py | 14 +++++--------- .../3_json_match/Solution/view_solution.py | 8 ++++---- .../3_json_update/Solution/app_solution.py | 9 ++++++++- .../3_json_update/Solution/model_solution.py | 15 +++++++-------- .../3_json_update/Solution/view_solution.py | 8 ++++---- .../3_sql_connection/Solution/app_solution.py | 5 +++++ .../Solution/model_solution.py | 19 ++++++++++++++----- 30 files changed, 153 insertions(+), 79 deletions(-) create mode 100644 introduction_to_python/mvc_architecture/2_file_write/filename_x.txt diff --git a/introduction_to_python/mvc_architecture/1_addition/Solution/app_solution.py b/introduction_to_python/mvc_architecture/1_addition/Solution/app_solution.py index 1c878f3e..e323b591 100644 --- a/introduction_to_python/mvc_architecture/1_addition/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/1_addition/Solution/app_solution.py @@ -1,2 +1,9 @@ import model_solution as model import view_solution as view + +number_1=input(view.capture_number1()) +number_2=input(view.capture_number2()) +result=int(number_1)+int(number_2) +model.store([number_1, number_2, result]) + +print(view.display(result)) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_addition/Solution/model_solution.py b/introduction_to_python/mvc_architecture/1_addition/Solution/model_solution.py index 6536c365..fe065f8a 100644 --- a/introduction_to_python/mvc_architecture/1_addition/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/1_addition/Solution/model_solution.py @@ -1,3 +1,3 @@ - +data = [] def store(result): - return + return data.append(result) diff --git a/introduction_to_python/mvc_architecture/1_addition/Solution/view_solution.py b/introduction_to_python/mvc_architecture/1_addition/Solution/view_solution.py index dc8db3eb..3160db8c 100644 --- a/introduction_to_python/mvc_architecture/1_addition/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/1_addition/Solution/view_solution.py @@ -1,7 +1,6 @@ def capture_number1(): - return + return f'Enter a number: ' def capture_number2(): - return + return f'Enter another number: ' def display(result): - return - + return f'{result}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_delete_key/Solution/app_solution.py b/introduction_to_python/mvc_architecture/1_delete_key/Solution/app_solution.py index 1c878f3e..dad38af9 100644 --- a/introduction_to_python/mvc_architecture/1_delete_key/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/1_delete_key/Solution/app_solution.py @@ -1,2 +1,8 @@ import model_solution as model import view_solution as view + +movie_list = model.get_list() +del_key = input(view.delete_key()) +model.del_list_key(del_key) +final_list = model.get_list() +print(view.display(final_list)) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_delete_key/Solution/model_solution.py b/introduction_to_python/mvc_architecture/1_delete_key/Solution/model_solution.py index 4c0cb967..4b462042 100644 --- a/introduction_to_python/mvc_architecture/1_delete_key/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/1_delete_key/Solution/model_solution.py @@ -1,8 +1,7 @@ movie_list={'1':'World War Z','2':'Inception','3':'Black Mirror','4':'Once Upon A Time In Hollywood','5':'Birdman'} def get_list(): - return + return str(movie_list) def del_list_key(del_key): - pass - + del movie_list[del_key] \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_delete_key/Solution/view_solution.py b/introduction_to_python/mvc_architecture/1_delete_key/Solution/view_solution.py index 0593e2e7..692d85c5 100644 --- a/introduction_to_python/mvc_architecture/1_delete_key/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/1_delete_key/Solution/view_solution.py @@ -1,5 +1,5 @@ def delete_key(): - return + return f'What key do you want to delete?: ' def display(final_list): - return \ No newline at end of file + return f'{final_list}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_details/Solution/app_solution.py b/introduction_to_python/mvc_architecture/1_details/Solution/app_solution.py index e71d316e..b2211fc7 100644 --- a/introduction_to_python/mvc_architecture/1_details/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/1_details/Solution/app_solution.py @@ -1,3 +1,8 @@ import view_solution as view import model_solution as model +name = input(view.capture_name()) +age = input(view.capture_age()) +model.store(name,age) +info = view.display(name, age) +print(info) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_details/Solution/model_solution.py b/introduction_to_python/mvc_architecture/1_details/Solution/model_solution.py index 20790038..01528e9c 100644 --- a/introduction_to_python/mvc_architecture/1_details/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/1_details/Solution/model_solution.py @@ -1,3 +1,3 @@ data=[] def store(name,age): - return \ No newline at end of file + data.append((name, age)) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_details/Solution/view_solution.py b/introduction_to_python/mvc_architecture/1_details/Solution/view_solution.py index 45fae5aa..9d1db399 100644 --- a/introduction_to_python/mvc_architecture/1_details/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/1_details/Solution/view_solution.py @@ -1,8 +1,8 @@ def capture_name(): - return + return f'Enter your name: ' def capture_age(): - return + return f'Enter your age: ' def display(name,age): - return \ No newline at end of file + return f'{name}, {age}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_update_list/Solution/app_solution.py b/introduction_to_python/mvc_architecture/1_update_list/Solution/app_solution.py index 5e0d8984..c5296a58 100644 --- a/introduction_to_python/mvc_architecture/1_update_list/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/1_update_list/Solution/app_solution.py @@ -1,2 +1,10 @@ import view_solution as view -import model_solution as model \ No newline at end of file +import model_solution as model + +fruits = model.get_store() +show = view.show_fruits(fruits) +print(show) +fruit = input(view.ask_fruit()) +model.update_fruit(fruit) +data = view.show_fruits(fruits) +print(data) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_update_list/Solution/model_solution.py b/introduction_to_python/mvc_architecture/1_update_list/Solution/model_solution.py index e6b44e57..72807d6a 100644 --- a/introduction_to_python/mvc_architecture/1_update_list/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/1_update_list/Solution/model_solution.py @@ -4,4 +4,6 @@ def get_store(): return fruits def update_fruit(fruit): - return \ No newline at end of file + # fruits.append(fruit) + for index, value in enumerate(fruits): + return index,value \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/1_update_list/Solution/view_solution.py b/introduction_to_python/mvc_architecture/1_update_list/Solution/view_solution.py index 69a4f56b..8d1ae771 100644 --- a/introduction_to_python/mvc_architecture/1_update_list/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/1_update_list/Solution/view_solution.py @@ -1,6 +1,6 @@ def ask_fruit(): - return + return f'Enter a fruit: ' def show_fruits(fruits): - return + return f'{fruits}' diff --git a/introduction_to_python/mvc_architecture/2_books/Solution/app_solution.py b/introduction_to_python/mvc_architecture/2_books/Solution/app_solution.py index 8e7eefbc..9952d3bf 100644 --- a/introduction_to_python/mvc_architecture/2_books/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/2_books/Solution/app_solution.py @@ -1,3 +1,10 @@ import model_solution as model import view_solution as view +book_list = model.get_list() +show = view.show_list(book_list) +print(show) +book = input(view.retrive_book()) +author = model.retrive_book(book) +data = view.display(book, author) +print(data) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_books/Solution/model_solution.py b/introduction_to_python/mvc_architecture/2_books/Solution/model_solution.py index 178d7c44..958e8b6f 100644 --- a/introduction_to_python/mvc_architecture/2_books/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/2_books/Solution/model_solution.py @@ -1,15 +1,13 @@ import json book_author_list={"books":{"A Tale of Two Cities":'Charles Dickens',"Lord Of The Rings":'J.R.R. Tolkien',"Dark Psychology":'Steven Turner',"Rich Dad Poor Dad":'Robert T Kiyosaki'}} - +book_list = json.dumps(book_author_list) +# json.dumps() is a method in which it turns a python object into a JSON string def get_list(): - return + return str(book_list) def retrive_book(book): - return - - - - - - - + x = json.loads(book_list) + books = x['books'] + result = books.get(book) + return result +# json.loads() is a method in which it parses a JSON string \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_books/Solution/view_solution.py b/introduction_to_python/mvc_architecture/2_books/Solution/view_solution.py index 543c48b6..396197e8 100644 --- a/introduction_to_python/mvc_architecture/2_books/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/2_books/Solution/view_solution.py @@ -1,8 +1,8 @@ def show_list(book_list): - return + return f'{book_list}' def retrive_book(): - return + return f'Enter the name of the book you want: ' def display(book,author): - return \ No newline at end of file + return f'{book}{author}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_file_write/Solution/app_solution.py b/introduction_to_python/mvc_architecture/2_file_write/Solution/app_solution.py index 78cd8bf5..ff2f44be 100644 --- a/introduction_to_python/mvc_architecture/2_file_write/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/2_file_write/Solution/app_solution.py @@ -1,2 +1,10 @@ import view_solution as view import model_solution as model + +file_name = input(view.ask_fileName()) +model.create(file_name) +content = input(view.ask_content()) +model.write(file_name, content) +data = model.read(file_name) +result = view.display(data) +print(result) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_file_write/Solution/model_solution.py b/introduction_to_python/mvc_architecture/2_file_write/Solution/model_solution.py index 56fa05a6..49b389ca 100644 --- a/introduction_to_python/mvc_architecture/2_file_write/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/2_file_write/Solution/model_solution.py @@ -1,8 +1,11 @@ def create(file_name): - return + open(f'{file_name}.txt', 'w') def write(file,content): - return + with open(f'{file}.txt', 'w') as file_writer: + file_writer.write(content) def read(file): - return \ No newline at end of file + with open(f'{file}.txt', 'r') as file_reader: + x = file_reader.read() + return x \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_file_write/Solution/view_solution.py b/introduction_to_python/mvc_architecture/2_file_write/Solution/view_solution.py index 4ceef4e3..49791107 100644 --- a/introduction_to_python/mvc_architecture/2_file_write/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/2_file_write/Solution/view_solution.py @@ -1,10 +1,8 @@ def ask_fileName(): - return + return f'What is the name of the file you are searching for?: ' def ask_content(): - return + return f'What content are you searching for?: ' def display(data): - return - - + return f'{data}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_file_write/filename_x.txt b/introduction_to_python/mvc_architecture/2_file_write/filename_x.txt new file mode 100644 index 00000000..0ae5e8d3 --- /dev/null +++ b/introduction_to_python/mvc_architecture/2_file_write/filename_x.txt @@ -0,0 +1 @@ +filename_y \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_update_item_value/Solution/app_solution.py b/introduction_to_python/mvc_architecture/2_update_item_value/Solution/app_solution.py index 1c878f3e..70752a3d 100644 --- a/introduction_to_python/mvc_architecture/2_update_item_value/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/2_update_item_value/Solution/app_solution.py @@ -1,2 +1,9 @@ import model_solution as model import view_solution as view + +program_list = model.get_list +key = input(view.update_key()) +value = input(view.enter_value()) +new_list = model.update_list_key(key, value) +result = view.display(new_list) +print(result) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_update_item_value/Solution/model_solution.py b/introduction_to_python/mvc_architecture/2_update_item_value/Solution/model_solution.py index f0cf1614..4a2c500c 100644 --- a/introduction_to_python/mvc_architecture/2_update_item_value/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/2_update_item_value/Solution/model_solution.py @@ -1,9 +1,8 @@ program_list={'1':'Perl','2':'C','3':'C++','4':'Java','5':'Python'} def get_list(): - return + return str(program_list) def update_list_key(key,value): - return - - + for key, value in enumerate(program_list): + return key, value \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/2_update_item_value/Solution/view_solution.py b/introduction_to_python/mvc_architecture/2_update_item_value/Solution/view_solution.py index c4309d62..ca8afa83 100644 --- a/introduction_to_python/mvc_architecture/2_update_item_value/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/2_update_item_value/Solution/view_solution.py @@ -1,11 +1,11 @@ def show_list(program_list): - return + return f'{program_list}' def update_key(): - return + return f'Enter a key: ' def enter_value(): - return + return f'Enter a value: ' def display(new_list): - return \ No newline at end of file + return f'{new_list}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_json_match/Solution/app_solution.py b/introduction_to_python/mvc_architecture/3_json_match/Solution/app_solution.py index 1c878f3e..5426550c 100644 --- a/introduction_to_python/mvc_architecture/3_json_match/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/3_json_match/Solution/app_solution.py @@ -1,2 +1,13 @@ import model_solution as model import view_solution as view + +data_list = model.get_list() +show = view.show_list(data_list) +print(show) +sport = input(view.retrive_sport()) +country = input(view.retrive_country()) +data_a = model.retrive_match(sport, country) +# data_b = model.retrive_match(country) +# result = data_a + ' ' + data_b +result = data_a +print(result) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_json_match/Solution/model_solution.py b/introduction_to_python/mvc_architecture/3_json_match/Solution/model_solution.py index 511f0fa9..2e452fd9 100644 --- a/introduction_to_python/mvc_architecture/3_json_match/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/3_json_match/Solution/model_solution.py @@ -3,14 +3,10 @@ data_match=json.dumps(match_data) def get_list(): - return + return str(data_match) def retrive_match(sport,country): - return - - - - - - - + x = json.loads(data_match) + sport_country = x['sport', 'country'] + result = sport_country.get(sport, country) + return result \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_json_match/Solution/view_solution.py b/introduction_to_python/mvc_architecture/3_json_match/Solution/view_solution.py index 69aade0d..35f1e8d6 100644 --- a/introduction_to_python/mvc_architecture/3_json_match/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/3_json_match/Solution/view_solution.py @@ -1,11 +1,11 @@ def show_list(data_list): - return + return f'{data_list}' def retrive_sport(): - return + return f'Which sport are you looking for?: ' def retrive_country(): - return + return f'Which country are you looking for?: ' def display(sport,country): - return \ No newline at end of file + return f'{sport} {country}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_json_update/Solution/app_solution.py b/introduction_to_python/mvc_architecture/3_json_update/Solution/app_solution.py index 3dd36bc4..d94fa6a9 100644 --- a/introduction_to_python/mvc_architecture/3_json_update/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/3_json_update/Solution/app_solution.py @@ -1,4 +1,11 @@ import model_solution as model import view_solution as view - +data_list = model.get_list() +show = view.show_list(data_list) +print(show) +sport = input(view.retrive_sport()) +country = input(view.retrive_country()) +data_a = model.retrive_match(sport, country) +result = data_a +print(result) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_json_update/Solution/model_solution.py b/introduction_to_python/mvc_architecture/3_json_update/Solution/model_solution.py index d3b7a8a5..f564c6d0 100644 --- a/introduction_to_python/mvc_architecture/3_json_update/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/3_json_update/Solution/model_solution.py @@ -3,13 +3,12 @@ data_match=json.dumps(match_data) def get_list(): - return + return str(data_match) def retrive_match(sport,country): - return - - - - - - + x = json.loads(data_match) + sport_lst=x['sports'] + sport_lst.append(sport) + country_lst=x['country'] + country_lst.append(country) + return x \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_json_update/Solution/view_solution.py b/introduction_to_python/mvc_architecture/3_json_update/Solution/view_solution.py index ceff9d64..41a2d1de 100644 --- a/introduction_to_python/mvc_architecture/3_json_update/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/3_json_update/Solution/view_solution.py @@ -1,11 +1,11 @@ def show_list(data_list): - return + return f'{data_list}' def retrive_sport(): - return + return f'Which sport would you like to retrieve?: ' def retrive_country(): - return + return f'Which country would you like to retrieve?: ' def display(data): - return \ No newline at end of file + return f'{data}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/app_solution.py b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/app_solution.py index 78cd8bf5..c5ffcdcb 100644 --- a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/app_solution.py @@ -1,2 +1,7 @@ import view_solution as view import model_solution as model + +result = model.create() +print(result) +data = view.display(result_1, result_2) +print(data) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/model_solution.py b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/model_solution.py index 0b0a809d..b233f668 100644 --- a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/model_solution.py @@ -1,8 +1,17 @@ import sqlite3 +DB_name = 'myDB' -def create(): - return - -def query(): - return +def create(db=None): + if db is None: + mydb = ':memory:' + return mydb + else: + mydb = '{}.db'.format(db) + return db + connection = sqlite3.connect(db) + return connection + +def query(connection, create_table_student): + c = connection.cursor() + return c.execute(create_table_student) From 769f697ec703e5078ec368507b4711d7ae62eac9 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Sun, 9 Aug 2020 12:52:28 -0400 Subject: [PATCH 43/65] Edited solutions to pass after merge conflict --- .../1_list_max/solution/solution.py | 55 +------------------ .../2_farm_area/Solution/solution.py | 22 +------- .../3_grade/Solution/solution.py | 36 +----------- .../3_month_days/Solution/solution.py | 3 +- .../3_palindrome/Solution/solution.py | 4 +- .../3_shape_check/Solution/solution.py | 3 +- .../3_string_case/Solution/solution.py | 11 ---- .../2_ASCII/Solutions/solution.py | 16 +----- .../2_operators/Solutions/solution.py | 16 +----- .../Solutions/solution.py | 24 -------- .../Solutions/solution.py | 25 +-------- .../2_bash_operators/solution/solution.py | 21 +------ .../functions/1_range/Solution/solution.py | 21 +------ .../1_return_hello/Solution/solution.py | 24 +------- .../2_max_value/Solution/solution.py | 23 +------- .../2_shut_down/Solution/solution.py | 28 +--------- .../2_variable_argument/Solution/solution.py | 20 ------- .../3_count_even/Solution/solution.py | 17 +----- .../3_factorial/Solution/solution.py | 23 +------- .../functions/3_total/Solution/solution.py | 25 +-------- 20 files changed, 26 insertions(+), 391 deletions(-) diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index 7b500159..1578858a 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -1,13 +1,3 @@ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 -# L = [152, 463, 1112, 1337, -10] -# LIST_MAX = sorted(L)[-1] - -# print(LIST_MAX(L)) - L = [152, 463, 1112, 1337, -10] def LIST_MAX1(L): current_max = L[0] @@ -19,47 +9,4 @@ def LIST_MAX1(L): current_max = L[3] if L[4] > current_max: current_max = L[4] - return current_max -<<<<<<< HEAD -LIST_MAX = LIST_MAX1(L) -======= -L = [152, 463, 1112, 1337, -10] -# def LIST_MAX(L): -# if L == []: -# LIST_MAX1 = None -# else: -# LIST_MAX1 = sorted(L)[-1] -# return LIST_MAX1 - -# print(LIST_MAX(L)) -LIST_MAX = sorted(L)[-1] -# print(LIST_MAX) ->>>>>>> d536594... Pushing exercises -======= -# L = [152, 463, 1112, 1337, -10] -# LIST_MAX = sorted(L)[-1] - -# print(LIST_MAX(L)) - -L = [152, 463, 1112, 1337, -10] -def LIST_MAX1(L): - current_max = L[0] - if L[1] > current_max: - current_max = L[1] - if L[2] > current_max: - current_max = L[2] - if L[3] > current_max: - current_max = L[3] - if L[4] > current_max: - current_max = L[4] - return current_max -<<<<<<< HEAD -LIST_MAX = LIST_MAX1(L) - ->>>>>>> f07cce6... Completed -======= -LIST_MAX = LIST_MAX1(L) ->>>>>>> 6cffc71... Completed Exercises -======= -LIST_MAX = LIST_MAX1(L) ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 + return current_max \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py index fe2d8d67..9b6c3c51 100644 --- a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -1,26 +1,6 @@ -# Code your solution here -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 # length = len(input()) # breadth = len(input()) length = 6 breadth = 4 -<<<<<<< HEAD -======= -length = 6 -breadth = 4 - ->>>>>>> 39354d0... Completed Exercises -======= -# length = len(input()) -# breadth = len(input()) -length = 6 -breadth = 4 ->>>>>>> f07cce6... Completed -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 data = length * breadth -print(data) +print(data) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py index 27b3a28a..c58a31fd 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -1,11 +1,6 @@ # Code your solution here def grade(mark): if mark >= 90: -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 return 'A+ GRADE' elif mark >= 70: return 'B GRADE' @@ -17,33 +12,4 @@ def grade(mark): return 'FAIL' # score = int(input("Enter your grade here:")) mark = 80 -print(grade(mark)) -<<<<<<< HEAD -======= - # return 'A+ GRADE' - print('A+ GRADE') -======= - return 'A+ GRADE' ->>>>>>> 9784d40... Completed - elif mark >= 70: - return 'B GRADE' - elif mark >= 50: - return 'C GRADE' - elif mark >= 35: - return 'D GRADE' - else: -<<<<<<< HEAD - # return 'FAIL' - print('FAIL') -score = int(input("Enter your grade here:")) -print(grade(score)) ->>>>>>> d536594... Pushing exercises -======= - return 'FAIL' -# score = int(input("Enter your grade here:")) -mark = 80 -print(grade(mark)) ->>>>>>> 9784d40... Completed -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 -# grade(score) \ No newline at end of file +print(grade(mark)) \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py index 678676a5..9615947a 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py @@ -1,5 +1,6 @@ # Code your solution here -month = input('Enter any month:') +# month = input('Enter any month:') +month = 'august' month_dict = {'january':'31', 'february':'28, 29', 'march':'31', 'april':'30', 'may':'31', 'june':'30', 'july':'31', 'august':'31','september':'30', 'october':'31', 'november':'30', 'december':'31'} def data(month): if month in month_dict.keys(): diff --git a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py index b85e38d8..122aaedc 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py @@ -1,6 +1,6 @@ # Code your solution here -line = input('Enter any string value:') - +# line = input('Enter any string value:') +line = 'malayalam' if line == line[::-1]: is_palindrome = True else: diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py index 2b897c95..379e81de 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py @@ -1,5 +1,6 @@ # Code your solution here -figure = input('Enter any geometric shape value:') +# figure = input('Enter any geometric shape value:') +figure = '5' my_dict = {'3':'Triangle', '4':'Quadrilateral', '5':'Pentagon', '6':'Hexagon', '7':'Heptagon', '8':'Octagon', '9':'Nonagon'} def data(figure): diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py index 9c83382f..0c9227fb 100644 --- a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -1,17 +1,6 @@ # Code your solution here string_val = str(input()) -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> d536594... Pushing exercises -======= - ->>>>>>> 9784d40... Completed -======= - ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 upper_data = string_val.upper() lower_data = string_val.lower() diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py index 67bc0aaf..117c7cd9 100644 --- a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py @@ -1,16 +1,2 @@ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD # print('Hexadecimal') -print('Boolean') -======= -print('Hexadecimal') ->>>>>>> 3569546... Exercises completed -======= -# print('Hexadecimal') -print('Boolean') ->>>>>>> 9784d40... Completed -======= -# print('Hexadecimal') -print('Boolean') ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 +print('Boolean') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py index c3ce3ff1..e983d85b 100644 --- a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py @@ -1,16 +1,2 @@ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD # print('Boolean') -print('Hexadecimal') -======= -print('Boolean') ->>>>>>> 3569546... Exercises completed -======= -# print('Boolean') -print('Hexadecimal') ->>>>>>> 9784d40... Completed -======= -# print('Boolean') -print('Hexadecimal') ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 +print('Hexadecimal') \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py index 86d2607a..439e8ebe 100644 --- a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py @@ -1,33 +1,9 @@ x = 0 y = 1 -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 - -Answer_and = x & y -Answer_or = x | y -Answer_not = ~ x -<<<<<<< HEAD -======= -x & y = 0 -x | y = 1 -~ x, ~ y = 1, 0 - -Answer_and = 0 -Answer_or = 1 -Answer_not = 1, 0 ->>>>>>> 3569546... Exercises completed -======= - Answer_and = x & y Answer_or = x | y Answer_not = ~ x ->>>>>>> 39354d0... Completed Exercises -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 print(Answer_and) print(Answer_or) diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py index 019d1a45..89aa95f9 100644 --- a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py @@ -1,28 +1,5 @@ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 x = True y = False Answer = bool(x or y) - -<<<<<<< HEAD -print(Answer) -======= -x = 1 -y = 2 - ->>>>>>> 39354d0... Completed Exercises -======= -x = True -y = False - -Answer = bool(x or y) - -print(Answer) ->>>>>>> 9784d40... Completed -======= -print(Answer) ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 +print(Answer) \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py index 9ae0dc84..cb28f995 100644 --- a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -1,26 +1,7 @@ # Assign the correct strings below ONE = 'mkdir testdir && cd testdir' -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 3569546... Exercises completed -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 TWO = 'cat textfile.txt | grep and' THREE = 'ls >> contents.txt' FOUR = 'cd current || mkdir current' -FIVE = 'pwd > currentpath.txt' -<<<<<<< HEAD -<<<<<<< HEAD -======= -TWO = 'grep and textfile.txt' -THREE = 'grep -r >> contents.txt' -FOUR = 'cd current > current' -FIVE = 'ls > currentpath.txt' ->>>>>>> 3b8cef1... Exercises completed -======= ->>>>>>> 3569546... Exercises completed -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 +FIVE = 'pwd > currentpath.txt' \ No newline at end of file diff --git a/introduction_to_python/functions/1_range/Solution/solution.py b/introduction_to_python/functions/1_range/Solution/solution.py index 90d9aacc..262a8b51 100644 --- a/introduction_to_python/functions/1_range/Solution/solution.py +++ b/introduction_to_python/functions/1_range/Solution/solution.py @@ -1,26 +1,9 @@ +number = 99 def range_100(number): - if number <= 100: - return 'GREATNESS' - else: -<<<<<<< HEAD -<<<<<<< HEAD - return 'OOPS' -======= -# Code your solution here - # number = int(input('Enter any integer value:')) -number = 99 -def result(number): if number <= 100: return 'GREATNESS' else: return 'OOPS' -print(result(number)) ->>>>>>> 6cffc71... Completed Exercises -======= - return 'OOPS' ->>>>>>> 3f12b16... Updated and completed -======= - return 'OOPS' ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 +print(range_100(number)) \ No newline at end of file diff --git a/introduction_to_python/functions/1_return_hello/Solution/solution.py b/introduction_to_python/functions/1_return_hello/Solution/solution.py index 445c77cd..b85f1df8 100644 --- a/introduction_to_python/functions/1_return_hello/Solution/solution.py +++ b/introduction_to_python/functions/1_return_hello/Solution/solution.py @@ -1,23 +1,5 @@ -def hello(name): -<<<<<<< HEAD -<<<<<<< HEAD - val1 = 'Hello' + name - return val1 -======= -# Code your solution here # name = input('Enter your name: ') name = 'Newton' -def result(name): - val1 = 'Hello' + name - return val1 - -print(result(name)) ->>>>>>> 6cffc71... Completed Exercises -======= - val1 = 'Hello ' + name - return val1 ->>>>>>> 3f12b16... Updated and completed -======= - val1 = 'Hello ' + name - return val1 ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 +def hello(name): + val1 = 'Hello' +' '+ name + return val1 \ No newline at end of file diff --git a/introduction_to_python/functions/2_max_value/Solution/solution.py b/introduction_to_python/functions/2_max_value/Solution/solution.py index 5085b56f..0f3cf2e3 100644 --- a/introduction_to_python/functions/2_max_value/Solution/solution.py +++ b/introduction_to_python/functions/2_max_value/Solution/solution.py @@ -1,24 +1,3 @@ def max_val(a, b, c): max_value = max(a, b, c) -<<<<<<< HEAD -<<<<<<< HEAD - return max_value -======= -# Code your solution here -# a = int(input('Enter an integer value: ')) -# b = int(input('Enter another integer value: ')) -# c = int(input('Enter one last integer value: ')) -a = 1 -b = 2 -c = 3 -def result(a, b, c): - max_value = max(a, b, c) - return max_value -print(result(a, b, c)) ->>>>>>> 6cffc71... Completed Exercises -======= - return max_value ->>>>>>> 3f12b16... Updated and completed -======= - return max_value ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 + return max_value \ No newline at end of file diff --git a/introduction_to_python/functions/2_shut_down/Solution/solution.py b/introduction_to_python/functions/2_shut_down/Solution/solution.py index 85751398..5c153f1f 100644 --- a/introduction_to_python/functions/2_shut_down/Solution/solution.py +++ b/introduction_to_python/functions/2_shut_down/Solution/solution.py @@ -1,33 +1,9 @@ -def shut_down(x): -<<<<<<< HEAD -<<<<<<< HEAD -======= -# Code your solution here # x = bool(input('Enter a boolean value: ')) x = 'false' -def data(x): ->>>>>>> 6cffc71... Completed Exercises -======= ->>>>>>> 3f12b16... Updated and completed -======= ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 +def shut_down(x): if x == True: return 'SHUTDOWN' elif x == False: return 'SHUTDOWN ABORTED' else: -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - return 'This is not a boolean value.' -======= - return 'This is not a boolean value.' -result = data(x) -print(result) ->>>>>>> 6cffc71... Completed Exercises -======= - return 'This is not a boolean value.' ->>>>>>> 3f12b16... Updated and completed -======= - return 'This is not a boolean value.' ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 + return '.' \ No newline at end of file diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py index 452a7cd7..dbbcec4b 100644 --- a/introduction_to_python/functions/2_variable_argument/Solution/solution.py +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -1,22 +1,2 @@ def concat_args(*args): -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - return sum(args) -======= -# Code your solution here -def f(*args): - return sum(args) -result = f -print(result) ->>>>>>> 6cffc71... Completed Exercises -======= - args.split([]) - return ' '.join(args) ->>>>>>> 3f12b16... Updated and completed -======= return ''.join(args) ->>>>>>> 95a635a... Completed -======= - return ''.join(args) ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 diff --git a/introduction_to_python/functions/3_count_even/Solution/solution.py b/introduction_to_python/functions/3_count_even/Solution/solution.py index 5f3de168..93ea2775 100644 --- a/introduction_to_python/functions/3_count_even/Solution/solution.py +++ b/introduction_to_python/functions/3_count_even/Solution/solution.py @@ -1,17 +1,2 @@ def count_even(*args): -<<<<<<< HEAD -<<<<<<< HEAD - return list(map(lambda x: x % 2== 0)) -======= -# Code your solution here -def f(*args): - return list(map(lambda x: x % 2== 0)) -result = f -print(result) ->>>>>>> 6cffc71... Completed Exercises -======= - return len(list(filter(lambda x: x % 2 == 0, args))) ->>>>>>> 3f12b16... Updated and completed -======= - return len(list(filter(lambda x: x % 2 == 0, args))) ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 + return len(list(filter(lambda x: x % 2 == 0, args))) \ No newline at end of file diff --git a/introduction_to_python/functions/3_factorial/Solution/solution.py b/introduction_to_python/functions/3_factorial/Solution/solution.py index 1e93973f..ba7eaaa0 100644 --- a/introduction_to_python/functions/3_factorial/Solution/solution.py +++ b/introduction_to_python/functions/3_factorial/Solution/solution.py @@ -8,25 +8,4 @@ def factorial(n): else: for i in range(1, int(n) + 1): factorial = factorial * i -<<<<<<< HEAD -<<<<<<< HEAD -======= -# Code your solution here -# n = int(input(Enter any integer: )) -n = 4 - -def numbers(n): - factorial = 1 - if int(n) >= 1: - for i in range(1, int(n) + 1): - factorial = factorial * i - -result = numbers(n) -print(result) ->>>>>>> 6cffc71... Completed Exercises -======= - return factorial ->>>>>>> 3f12b16... Updated and completed -======= - return factorial ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 + return factorial \ No newline at end of file diff --git a/introduction_to_python/functions/3_total/Solution/solution.py b/introduction_to_python/functions/3_total/Solution/solution.py index b760f6bb..8a5dba47 100644 --- a/introduction_to_python/functions/3_total/Solution/solution.py +++ b/introduction_to_python/functions/3_total/Solution/solution.py @@ -1,27 +1,8 @@ -def sum_data(lst): - summ = 0 - for i in lst: - summ += i -<<<<<<< HEAD -<<<<<<< HEAD - return summ -======= -# Code your solution here l = [10, 20, 30, 40, 50, 60] # l = [1, 2, 3, 4, 5] # used the list provided in test_solution.py for the test to work - -def a_list(l): +def sum_data(lst): summ = 0 - for i in l: + for i in lst: summ += i - return summ -result = a_list(l) -print(result) ->>>>>>> 6cffc71... Completed Exercises -======= - return summ ->>>>>>> 3f12b16... Updated and completed -======= - return summ ->>>>>>> 95a635a4ecbbedb34125c1f8cacdc445bd0dbfd0 + return summ \ No newline at end of file From 540d48a8ab6ffa0524aaf9da57cc0d2b46df7830 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 10 Aug 2020 11:33:18 -0400 Subject: [PATCH 44/65] Completed --- .../3_sql_connection/Solution/app_solution.py | 7 ++-- .../Solution/model_solution.py | 30 ++++++++++-------- .../Solution/view_solution.py | 4 +-- .../mvc_architecture/3_sql_connection/db.db | Bin 0 -> 8192 bytes 4 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 introduction_to_python/mvc_architecture/3_sql_connection/db.db diff --git a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/app_solution.py b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/app_solution.py index c5ffcdcb..c123dabe 100644 --- a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/app_solution.py +++ b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/app_solution.py @@ -1,7 +1,8 @@ import view_solution as view import model_solution as model -result = model.create() -print(result) -data = view.display(result_1, result_2) +model.create() +result = model.query() +for i in range(len(result)): + data = view.display(result[i][0], result[i][1]) print(data) \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/model_solution.py b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/model_solution.py index b233f668..d790d02c 100644 --- a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/model_solution.py +++ b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/model_solution.py @@ -1,17 +1,21 @@ import sqlite3 -DB_name = 'myDB' -def create(db=None): - if db is None: - mydb = ':memory:' - return mydb - else: - mydb = '{}.db'.format(db) - return db - connection = sqlite3.connect(db) - return connection +def create(): + connection = sqlite3.connect('db.db') + cursor = connection.cursor() + query = 'CREATE TABLE IF NOT EXISTS student(student_id integer , student_name text);' + cursor.execute(query) + return -def query(connection, create_table_student): - c = connection.cursor() - return c.execute(create_table_student) +def query(): + connection=sqlite3.connect('db.db') + cursor=connection.cursor() + query="INSERT INTO student VALUES(1,'abc');" + cursor.execute(query) + query="INSERT INTO student VALUES(2,'xyz');" + cursor.execute(query) + query="SELECT * FROM student;" + cursor.execute(query) + data=cursor.fetchall() + return data \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/view_solution.py b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/view_solution.py index 8afea60b..4f6194c3 100644 --- a/introduction_to_python/mvc_architecture/3_sql_connection/Solution/view_solution.py +++ b/introduction_to_python/mvc_architecture/3_sql_connection/Solution/view_solution.py @@ -1,5 +1,3 @@ def display(result_1,result_2): - return - - + return f'{result_1} {result_2}' \ No newline at end of file diff --git a/introduction_to_python/mvc_architecture/3_sql_connection/db.db b/introduction_to_python/mvc_architecture/3_sql_connection/db.db new file mode 100644 index 0000000000000000000000000000000000000000..ccbf333eb838276fda1f7f7e5efdae9e32463a19 GIT binary patch literal 8192 zcmeI#u?oU45XSL~C{CiALzf#B#Ki~DD&4xM1;7c6?l1_^ rCtK>Ic}$D!V%6D)8&|uzU-}6G2q1s}0tg_000IagfB*sr{IS3XqSYrr literal 0 HcmV?d00001 From 7ac97f57f4186273b14c52e551583390507b123c Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 10 Aug 2020 16:04:04 -0400 Subject: [PATCH 45/65] finished --- .../1_insert_element/solution/solution.py | 5 ++++- .../1_print_array/solution/solution.py | 3 +++ .../1_print_dictionary/solution/solution.py | 3 +++ .../1_update_dict/solution/solution.py | 4 ++++ .../2_convert_json/solution/solution.py | 4 ++++ .../dictionaries_and_arrays/2_occurance/solution/solution.py | 2 ++ .../2_reverse_array/solution/solution.py | 2 ++ .../2_sort_values/solution/solution.py | 3 +++ .../3_difference/solution/solution.py | 4 ++++ .../3_square_keys/solution/solution.py | 5 +++++ 10 files changed, 34 insertions(+), 1 deletion(-) diff --git a/data_structures/dictionaries_and_arrays/1_insert_element/solution/solution.py b/data_structures/dictionaries_and_arrays/1_insert_element/solution/solution.py index 8a7c9d9a..97505f32 100755 --- a/data_structures/dictionaries_and_arrays/1_insert_element/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/1_insert_element/solution/solution.py @@ -1 +1,4 @@ -# Write your solution here \ No newline at end of file +# Write your solution here +def insert_element(array_num, ins_pos, ins_val): + array_num.insert(ins_pos, ins_val) + return array_num \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1_print_array/solution/solution.py b/data_structures/dictionaries_and_arrays/1_print_array/solution/solution.py index aeb50baa..7b26e86d 100755 --- a/data_structures/dictionaries_and_arrays/1_print_array/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/1_print_array/solution/solution.py @@ -1 +1,4 @@ # Write your solution here +def print_array(array_1): + for element in array_1: + print(element) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1_print_dictionary/solution/solution.py b/data_structures/dictionaries_and_arrays/1_print_dictionary/solution/solution.py index aeb50baa..51b9b751 100755 --- a/data_structures/dictionaries_and_arrays/1_print_dictionary/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/1_print_dictionary/solution/solution.py @@ -1 +1,4 @@ # Write your solution here +def print_dict(dict_num): + for value in dict_num.values(): + print(value) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1_update_dict/solution/solution.py b/data_structures/dictionaries_and_arrays/1_update_dict/solution/solution.py index aeb50baa..32315543 100755 --- a/data_structures/dictionaries_and_arrays/1_update_dict/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/1_update_dict/solution/solution.py @@ -1 +1,5 @@ # Write your solution here +def update_dict(key, value): + new_dict = {} + new_dict[key] = value + return new_dict \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2_convert_json/solution/solution.py b/data_structures/dictionaries_and_arrays/2_convert_json/solution/solution.py index aeb50baa..73675b58 100755 --- a/data_structures/dictionaries_and_arrays/2_convert_json/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/2_convert_json/solution/solution.py @@ -1 +1,5 @@ # Write your solution here +import json +def convert(dict): + new_dict = json.dumps(dict) + return new_dict \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2_occurance/solution/solution.py b/data_structures/dictionaries_and_arrays/2_occurance/solution/solution.py index aeb50baa..a1d41e5b 100755 --- a/data_structures/dictionaries_and_arrays/2_occurance/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/2_occurance/solution/solution.py @@ -1 +1,3 @@ # Write your solution here +def occurances(array_num, element): + return array_num.count(element) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2_reverse_array/solution/solution.py b/data_structures/dictionaries_and_arrays/2_reverse_array/solution/solution.py index aeb50baa..e89dfe25 100755 --- a/data_structures/dictionaries_and_arrays/2_reverse_array/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/2_reverse_array/solution/solution.py @@ -1 +1,3 @@ # Write your solution here +def reverse(array_num): + return array_num[::-1] \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2_sort_values/solution/solution.py b/data_structures/dictionaries_and_arrays/2_sort_values/solution/solution.py index aeb50baa..c4d10351 100755 --- a/data_structures/dictionaries_and_arrays/2_sort_values/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/2_sort_values/solution/solution.py @@ -1 +1,4 @@ # Write your solution here +import operator +def sort_dict(my_dictionary): + return dict(sorted(my_dictionary.items(), key = operator.itemgetter(1))) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/3_difference/solution/solution.py b/data_structures/dictionaries_and_arrays/3_difference/solution/solution.py index aeb50baa..0d8321c9 100755 --- a/data_structures/dictionaries_and_arrays/3_difference/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/3_difference/solution/solution.py @@ -1 +1,5 @@ # Write your solution here +def difference(array_num): + numbers = sorted(array_num) + result = numbers[-1] - numbers[0] + return result \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/3_square_keys/solution/solution.py b/data_structures/dictionaries_and_arrays/3_square_keys/solution/solution.py index aeb50baa..0da21ee2 100755 --- a/data_structures/dictionaries_and_arrays/3_square_keys/solution/solution.py +++ b/data_structures/dictionaries_and_arrays/3_square_keys/solution/solution.py @@ -1 +1,6 @@ # Write your solution here +def square_keys(num): + dict = {} + for x in range(1, num+1): + dict[x] = x**2 + return dict \ No newline at end of file From b61a211705a4c0e9d936d2c2c0f3dd34c7faabce Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 12 Aug 2020 09:42:47 -0400 Subject: [PATCH 46/65] Partially complete --- .../1_delete_end/solution/solution.py | 17 +++++++++++++ .../1_insert_after/solution/solution.py | 25 +++++++++++++++++++ .../1_insert_start/solution/solution.py | 13 ++++++++++ .../2_delete_item_value/solution/solution.py | 16 ++++++++++++ .../2_insert_end/solution/solution.py | 16 ++++++++++++ .../2_search_item/solution/solution.py | 15 +++++++++++ .../3_index_insertion/solution/solution.py | 18 ++++++++++++- .../3_node_traverse/solution/solution.py | 14 +++++++++-- .../3_reverse/solution/solution.py | 18 +++++++++++-- 9 files changed, 147 insertions(+), 5 deletions(-) diff --git a/data_structures/linked_lists/1_delete_end/solution/solution.py b/data_structures/linked_lists/1_delete_end/solution/solution.py index 35fc9320..aeae22f4 100644 --- a/data_structures/linked_lists/1_delete_end/solution/solution.py +++ b/data_structures/linked_lists/1_delete_end/solution/solution.py @@ -1 +1,18 @@ # Write your answers here +class Node: + def __init__(self, data): + self.data = data + self.next = None + def __str__(self): + return str(self.data) + +class linkedlist: + def __init__(self, head=None): + self.head = head + def delete_at_end(self): + if self.head is None: + return None + n = self.head + while n.next.next != None: + n = n.next + n.next = None diff --git a/data_structures/linked_lists/1_insert_after/solution/solution.py b/data_structures/linked_lists/1_insert_after/solution/solution.py index 35fc9320..91374eec 100644 --- a/data_structures/linked_lists/1_insert_after/solution/solution.py +++ b/data_structures/linked_lists/1_insert_after/solution/solution.py @@ -1 +1,26 @@ # Write your answers here +class Node: + def __init__(self, data): + self.data = data + self.next = None + +class linkedList: + def __init__(self, head=None): + self.head = head + def insert_after_item(self, x, data): + current_node = self.head + previous_node = self.head + if current_node is None: + new_node = Node(data) + self.head = new_node + return + while(not current_node is None and current_node.data is not x): + previous_node = current_node + current_node = current_node.next + new_node = Node(data) + if current_node is None: + previous_node.next = new_node + else: + _next = current_node.next + current_node.next = new_node + new_node.next = _next \ No newline at end of file diff --git a/data_structures/linked_lists/1_insert_start/solution/solution.py b/data_structures/linked_lists/1_insert_start/solution/solution.py index aeb50baa..8dc2c33e 100644 --- a/data_structures/linked_lists/1_insert_start/solution/solution.py +++ b/data_structures/linked_lists/1_insert_start/solution/solution.py @@ -1 +1,14 @@ # Write your solution here +class Node: + def __init__(self, data): + self.data = data + self.next = None + +class linkedList: + def __init__(self, head=None): + self.head = head + def insert_at_start(self, data): + Node1 = Node(data) + Node1.next = self.head + self.head = Node1 + diff --git a/data_structures/linked_lists/2_delete_item_value/solution/solution.py b/data_structures/linked_lists/2_delete_item_value/solution/solution.py index aeb50baa..6186634a 100644 --- a/data_structures/linked_lists/2_delete_item_value/solution/solution.py +++ b/data_structures/linked_lists/2_delete_item_value/solution/solution.py @@ -1 +1,17 @@ # Write your solution here +class Node: + def __init__(self,data): + self.data = data + self.next = None + +class linkedList: + def __init__(self, head=None): + self.head = head + def delete_item_by_value(self, x): + current_node = self.head + previous_node = current_node + while(not current_node is None and not current_node.data is x): + previous_node = current_node + current_node = current_node.next + if not current_node is None: + previous_node.next = current_node.next \ No newline at end of file diff --git a/data_structures/linked_lists/2_insert_end/solution/solution.py b/data_structures/linked_lists/2_insert_end/solution/solution.py index 0b2305ce..6a7df175 100644 --- a/data_structures/linked_lists/2_insert_end/solution/solution.py +++ b/data_structures/linked_lists/2_insert_end/solution/solution.py @@ -1 +1,17 @@ #Write your Answers here +class Node: + def __init__(self, data): + self.data = data + self.next = None + +class linkedList: + def __init__(self, head=None): + self.head = head + def insert_at_end(self, data): + current_node = self.head + previous_node = self.head + while not current_node is None: + previous_node = current_node + current_node = current_node.next + new_node = Node(data) + previous_node.next = new_node \ No newline at end of file diff --git a/data_structures/linked_lists/2_search_item/solution/solution.py b/data_structures/linked_lists/2_search_item/solution/solution.py index a14631d2..ac699d2e 100644 --- a/data_structures/linked_lists/2_search_item/solution/solution.py +++ b/data_structures/linked_lists/2_search_item/solution/solution.py @@ -1 +1,16 @@ # Write your solution here +class Node: + def __init__(self, data=None): + self.data = data + self.next = None +class linkedList: + def __init__(self, head=None): + self.head = head + def search(self, x): + current_node = self.head + while not current_node is None: + if current_node.data == x: + return True + else: + current_node = current_node.next + return False \ No newline at end of file diff --git a/data_structures/linked_lists/3_index_insertion/solution/solution.py b/data_structures/linked_lists/3_index_insertion/solution/solution.py index c4eb69b5..9d632d54 100644 --- a/data_structures/linked_lists/3_index_insertion/solution/solution.py +++ b/data_structures/linked_lists/3_index_insertion/solution/solution.py @@ -1,2 +1,18 @@ #Write your answers here - +class Node: + def __init__(self, data=None): + self.data = data + self.next = None +class linkedList: + def __init__(self, head=None): + self.head = head + def insert_at_index(self, index, data): + start_node = self.head + if index == 0: + return Node(data, self.head) + while index > 1: + self.head = start_node.next + index -=1 + start_node.next = Node(data, start_node.next) + return start_node + \ No newline at end of file diff --git a/data_structures/linked_lists/3_node_traverse/solution/solution.py b/data_structures/linked_lists/3_node_traverse/solution/solution.py index 4932939a..25c6cfce 100644 --- a/data_structures/linked_lists/3_node_traverse/solution/solution.py +++ b/data_structures/linked_lists/3_node_traverse/solution/solution.py @@ -1,3 +1,13 @@ # Write your answers here - - +class Node: + def __init__(self, data=None): + self.data = data + self.next = None +class linkedList: + def __init__(self, head=None): + self.head = head + def traverse(self): + current_node = self.head + while not current_node is None: + print(current_node.data) + current_node = current_node.next \ No newline at end of file diff --git a/data_structures/linked_lists/3_reverse/solution/solution.py b/data_structures/linked_lists/3_reverse/solution/solution.py index 58bdfc7d..746e3ce9 100644 --- a/data_structures/linked_lists/3_reverse/solution/solution.py +++ b/data_structures/linked_lists/3_reverse/solution/solution.py @@ -1,4 +1,18 @@ #Write your answers here +class Node: + def __init__(self, data=None): + self.data = data + self.next = None - - +class linkedList: + def __init__(self, head=None): + self.head = head + def reverse(self): + previous_node = None + current_node = self.head + while current_node: + next = current_node.next + current_node.next = previous_node + previous_node = current_node + current_node = next + self.head = previous_node \ No newline at end of file From 222c9853de17b80c103b81a931d05077d5f3bb03 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 12 Aug 2020 11:16:08 -0400 Subject: [PATCH 47/65] Reviewed over this problem --- .../3_index_insertion/solution/solution.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/data_structures/linked_lists/3_index_insertion/solution/solution.py b/data_structures/linked_lists/3_index_insertion/solution/solution.py index 9d632d54..86eca1e1 100644 --- a/data_structures/linked_lists/3_index_insertion/solution/solution.py +++ b/data_structures/linked_lists/3_index_insertion/solution/solution.py @@ -7,12 +7,12 @@ class linkedList: def __init__(self, head=None): self.head = head def insert_at_index(self, index, data): - start_node = self.head - if index == 0: - return Node(data, self.head) - while index > 1: - self.head = start_node.next - index -=1 - start_node.next = Node(data, start_node.next) - return start_node - \ No newline at end of file + current_index = 1 + current_node = self.head + while current_index < index-1: + current_node = current_node.next + current_index +=1 + next_node = current_node.next + new_node = Node(data) + new_node.next = next_node + current_node.next = new_node \ No newline at end of file From 2f2edfb2dbd8830acd1a79c435563a9746b792ea Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 12 Aug 2020 11:28:55 -0400 Subject: [PATCH 48/65] Edited --- .../2_delete_item_value/solution/solution.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/data_structures/linked_lists/2_delete_item_value/solution/solution.py b/data_structures/linked_lists/2_delete_item_value/solution/solution.py index 6186634a..ec72d0cc 100644 --- a/data_structures/linked_lists/2_delete_item_value/solution/solution.py +++ b/data_structures/linked_lists/2_delete_item_value/solution/solution.py @@ -9,9 +9,27 @@ def __init__(self, head=None): self.head = head def delete_item_by_value(self, x): current_node = self.head - previous_node = current_node - while(not current_node is None and not current_node.data is x): + previous_node = self.head + while current_node: + if current_node.data == x: + next_node = current_node.next + previous_node.next = next_node + return previous_node = current_node current_node = current_node.next - if not current_node is None: - previous_node.next = current_node.next \ No newline at end of file + return +# 1 -> 2 -> 3 -> 4 +# 1 -> 2 -> 4 +# delete: 3 + +# c_n = 1 +# p_n = 1 + +# p_n = 1 +# c_n = 1+next = 2 + +# p_n = 2 +# c_n = 2+next = 3 + +# n_n = c_n + next = 4 +# p_n.next = 4 From 4366db8686ef1b9fb60b72ec135ffbb9e3de951b Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 12 Aug 2020 11:39:52 -0400 Subject: [PATCH 49/65] Edited --- .../1_insert_after/solution/solution.py | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/data_structures/linked_lists/1_insert_after/solution/solution.py b/data_structures/linked_lists/1_insert_after/solution/solution.py index 91374eec..8ee77832 100644 --- a/data_structures/linked_lists/1_insert_after/solution/solution.py +++ b/data_structures/linked_lists/1_insert_after/solution/solution.py @@ -10,17 +10,31 @@ def __init__(self, head=None): def insert_after_item(self, x, data): current_node = self.head previous_node = self.head - if current_node is None: - new_node = Node(data) - self.head = new_node - return - while(not current_node is None and current_node.data is not x): + new_node = Node(data) + while current_node: + if current_node.data == x: + new_node.next = current_node.next + current_node.next = new_node + return previous_node = current_node current_node = current_node.next - new_node = Node(data) - if current_node is None: - previous_node.next = new_node - else: - _next = current_node.next - current_node.next = new_node - new_node.next = _next \ No newline at end of file + previous_node.next = new_node + +# 1 -> 2 -> 3 -> 5 +# insert: x=3 data=4 + +# c_n = 1 +# p_n = 1 +# n_n = 4 + +# p_n = c_n = 1 +# c_n = 1+next = 2 + +# p_n = 1+next = 2 +# c_n = 2+next = 3 + +# n_n.next = c_n.next = 5 +# 4 -> 5 + +# c_n.next = n_n +# 1 -> 2 -> 3 -> 4 -> 5 \ No newline at end of file From 34032ae2bc21f1a3a0a5519bdd5b633343230291 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 12 Aug 2020 23:01:51 -0400 Subject: [PATCH 50/65] Completed --- .../1_queue_bool/solution/solution.py | 8 ++- .../1_stack_bool/solution/solution.py | 5 +- .../2_queue_eq/solution/solution.py | 21 +++++- .../2_queue_len/solution/solution.py | 7 +- .../2_stack_eq/solution/solution.py | 20 +++++- .../2_stack_len/solution/solution.py | 7 +- .../3_backspace_compare/solution/solution.py | 70 ++++++++++++++++++- 7 files changed, 127 insertions(+), 11 deletions(-) diff --git a/data_structures/stacks_and_queues/1_queue_bool/solution/solution.py b/data_structures/stacks_and_queues/1_queue_bool/solution/solution.py index 103eb323..995faf0d 100644 --- a/data_structures/stacks_and_queues/1_queue_bool/solution/solution.py +++ b/data_structures/stacks_and_queues/1_queue_bool/solution/solution.py @@ -28,6 +28,8 @@ def dequeue(self): # Fill in the code for __bool__ def __bool__(self): - return - - + # return self.head_node != None + if self.head_node is None: + return False + else: + return True \ No newline at end of file diff --git a/data_structures/stacks_and_queues/1_stack_bool/solution/solution.py b/data_structures/stacks_and_queues/1_stack_bool/solution/solution.py index a7a4c309..cd845201 100644 --- a/data_structures/stacks_and_queues/1_stack_bool/solution/solution.py +++ b/data_structures/stacks_and_queues/1_stack_bool/solution/solution.py @@ -22,4 +22,7 @@ def pop(self): # Fill in the code for __bool__ def __bool__(self): - return \ No newline at end of file + if self.head_node is None: + return False + else: + return True \ No newline at end of file diff --git a/data_structures/stacks_and_queues/2_queue_eq/solution/solution.py b/data_structures/stacks_and_queues/2_queue_eq/solution/solution.py index 7fdf97e8..9201dfdb 100644 --- a/data_structures/stacks_and_queues/2_queue_eq/solution/solution.py +++ b/data_structures/stacks_and_queues/2_queue_eq/solution/solution.py @@ -28,8 +28,25 @@ def dequeue(self): # You may want to solve this magic method first! def __len__(self): - return + current_node = self.head_node + number_nodes = 0 + while current_node: + number_nodes += 1 + current_node = current_node.next + return number_nodes # Fill in the code for __len__ def __eq__(self, other): - return + #return len(self) == len(other) + if len(self) == len(other): + current_node1 = self.head_node + current_node2 = other.head_node + while current_node1: + if current_node1.value != current_node2.value: + return False + else: + current_node1 = current_node1.next + current_node2 = current_node2.next + return True + return False + diff --git a/data_structures/stacks_and_queues/2_queue_len/solution/solution.py b/data_structures/stacks_and_queues/2_queue_len/solution/solution.py index 7242a724..3d6e57d5 100644 --- a/data_structures/stacks_and_queues/2_queue_len/solution/solution.py +++ b/data_structures/stacks_and_queues/2_queue_len/solution/solution.py @@ -29,4 +29,9 @@ def dequeue(self): # Fill in the code for __len__ def __len__(self): - return \ No newline at end of file + current_node = self.head_node + number_nodes = 0 + while current_node: + number_nodes += 1 + current_node = current_node.next + return number_nodes \ No newline at end of file diff --git a/data_structures/stacks_and_queues/2_stack_eq/solution/solution.py b/data_structures/stacks_and_queues/2_stack_eq/solution/solution.py index a9fd5a45..27fe61b6 100644 --- a/data_structures/stacks_and_queues/2_stack_eq/solution/solution.py +++ b/data_structures/stacks_and_queues/2_stack_eq/solution/solution.py @@ -22,8 +22,24 @@ def pop(self): # You may want to solve this magic method first! def __len__(self): - return + current_node = self.head_node + number_nodes = 0 + while current_node: + number_nodes += 1 + current_node = current_node.next + return number_nodes # Fill in the code for __len__ def __eq__(self, other): - return \ No newline at end of file + #return len(self) == len(other) + if len(self) == len(other): + current_node1 = self.head_node + current_node2 = other.head_node + while current_node1: + if current_node1.value != current_node2.value: + return False + else: + current_node1 = current_node1.next + current_node2 = current_node2.next + return True + return False \ No newline at end of file diff --git a/data_structures/stacks_and_queues/2_stack_len/solution/solution.py b/data_structures/stacks_and_queues/2_stack_len/solution/solution.py index 6e8aa6fb..da619bca 100644 --- a/data_structures/stacks_and_queues/2_stack_len/solution/solution.py +++ b/data_structures/stacks_and_queues/2_stack_len/solution/solution.py @@ -22,4 +22,9 @@ def pop(self): # Fill in the code for __len__ def __len__(self): - return \ No newline at end of file + current_node = self.head_node + number_nodes = 0 + while current_node: + number_nodes += 1 + current_node = current_node.next + return number_nodes \ No newline at end of file diff --git a/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py b/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py index eaac5bc9..fc8e5b9a 100644 --- a/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py +++ b/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py @@ -1,2 +1,70 @@ +# def backspace_compare(str1=str, str2=str): +# def New_string(string): +# stack = [] +# for char in string: +# if char != '#': +# stack.append(char) +# elif stack: +# stack.pop() +# return stack +# return New_string(str1) == New_string(str2) + +class ListNode: + def __init__(self, value): + self.value = value + self.next = None +class Stack: + def __init__(self): + self.head_node = None + def push(self, value): + new_head = ListNode(value) + new_head.next = self.head_node + self.head_node = new_head + def pop(self): + if self.head_node: + value = self.head_node.value + self.head_node = self.head_node.next + return value + else: + raise IndexError + def __bool__(self): + if self.head_node is None: + return False + else: + return True + def __len__(self): + current_node = self.head_node + number_nodes = 0 + while current_node: + number_nodes += 1 + current_node = current_node.next + return number_nodes + def __eq__(self, other): + if len(self) == len(other): + current_node1 = self.head_node + current_node2 = other.head_node + while current_node1: + if current_node1.value != current_node2.value: + return False + else: + current_node1 = current_node1.next + current_node2 = current_node2.next + return True + return False + def backspace_compare(str1, str2): - return \ No newline at end of file + stack_1 = Stack() + stack_2 = Stack() + for char in str1: + if char == '#': + if stack_1: + stack_1.pop() + else: + stack_1.push(char) + for char in str2: + if char == '#': + if stack_2: + stack_2.pop() + else: + stack_2.push(char) + return stack_1 == stack_2 \ No newline at end of file From 7ad3317f0dd5cd12d5d1ebdc31b13f9bab57d78a Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 13 Aug 2020 11:10:38 -0400 Subject: [PATCH 51/65] Edited last solution --- .../3_backspace_compare/solution/solution.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py b/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py index fc8e5b9a..25462597 100644 --- a/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py +++ b/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py @@ -27,11 +27,11 @@ def pop(self): return value else: raise IndexError - def __bool__(self): - if self.head_node is None: - return False - else: - return True + # def __bool__(self): + # if self.head_node is None: + # return False + # else: + # return True def __len__(self): current_node = self.head_node number_nodes = 0 From a4bf64d449d92e8f2b7e5940b673ce0cbcdf149a Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 13 Aug 2020 16:47:46 -0400 Subject: [PATCH 52/65] Partially complete, working on lvl3 problems --- .../1_binary_tree/solution/solution.py | 15 +++++++++------ .../1_height_of_tree/solution/solution.py | 17 +++++++++++++++++ .../2_inorder_list/solution/solution.py | 14 +++++++++++++- .../2_postorder_list/solution/solution.py | 13 +++++++++++++ .../2_preorder_list/solution/solution.py | 12 ++++++++++++ .../2_search_node/solution/solution.py | 15 +++++++++++++++ .../3_closest_value/solution/solution.py | 6 ++---- .../3_insert_node/solution/solution.py | 19 +++++++++++++------ 8 files changed, 94 insertions(+), 17 deletions(-) diff --git a/data_structures/binary_trees/1_binary_tree/solution/solution.py b/data_structures/binary_trees/1_binary_tree/solution/solution.py index d4b2fbc9..ebdb7a03 100644 --- a/data_structures/binary_trees/1_binary_tree/solution/solution.py +++ b/data_structures/binary_trees/1_binary_tree/solution/solution.py @@ -1,7 +1,10 @@ #Write your solutions here - - - - - - +class Node: + def __init__(self, key, left=None, right=None): + self.key = key + self.left = left + self.right = right + +left_child = Node(4) +right_child = Node(7) +sample_tree = Node(5, left_child, right_child) \ No newline at end of file diff --git a/data_structures/binary_trees/1_height_of_tree/solution/solution.py b/data_structures/binary_trees/1_height_of_tree/solution/solution.py index 0352cbbf..03e48dd9 100644 --- a/data_structures/binary_trees/1_height_of_tree/solution/solution.py +++ b/data_structures/binary_trees/1_height_of_tree/solution/solution.py @@ -1 +1,18 @@ # Write your solutions here +class Node: + def __init__(self, key, left=None, right=None): + self.key = key + self.left = left + self.right = right + +def height(node): + if node is None: + return 0 + else: + left_height = height(node.left) + right_height = height(node.right) + + if (left_height > right_height): + return left_height+1 + else: + return right_height+1 \ No newline at end of file diff --git a/data_structures/binary_trees/2_inorder_list/solution/solution.py b/data_structures/binary_trees/2_inorder_list/solution/solution.py index c4f40e78..f863d95a 100644 --- a/data_structures/binary_trees/2_inorder_list/solution/solution.py +++ b/data_structures/binary_trees/2_inorder_list/solution/solution.py @@ -1 +1,13 @@ -#Write your solutions here \ No newline at end of file +#Write your solutions here +class Node: + def __init__(self, key, left=None, right=None): + self.key = key + self.left = left + self.right = right +def Inorder(root): + lst = [] + if root: + lst = Inorder(root.left) + lst.append(root.key) + lst += Inorder(root.right) + return lst \ No newline at end of file diff --git a/data_structures/binary_trees/2_postorder_list/solution/solution.py b/data_structures/binary_trees/2_postorder_list/solution/solution.py index 0352cbbf..f39cecc7 100644 --- a/data_structures/binary_trees/2_postorder_list/solution/solution.py +++ b/data_structures/binary_trees/2_postorder_list/solution/solution.py @@ -1 +1,14 @@ # Write your solutions here +class Node: + def __init__(self, key, left=None, right=None): + self.key = key + self.left = left + self.right = right + +def Postorder(root): + lst = [] + if root: + lst = Postorder(root.left) + lst += Postorder(root.right) + lst.append(root.key) + return lst \ No newline at end of file diff --git a/data_structures/binary_trees/2_preorder_list/solution/solution.py b/data_structures/binary_trees/2_preorder_list/solution/solution.py index 0352cbbf..2f01c868 100644 --- a/data_structures/binary_trees/2_preorder_list/solution/solution.py +++ b/data_structures/binary_trees/2_preorder_list/solution/solution.py @@ -1 +1,13 @@ # Write your solutions here +class Node: + def __init__(self, key, left=None, right=None): + self.key = key + self.left = left + self.right = right +def Preorder(root): + lst = [] + if root: + lst.append(root.key) + lst += Preorder(root.left) + lst += Preorder(root.right) + return lst \ No newline at end of file diff --git a/data_structures/binary_trees/2_search_node/solution/solution.py b/data_structures/binary_trees/2_search_node/solution/solution.py index a1fd7b02..24cabfd8 100644 --- a/data_structures/binary_trees/2_search_node/solution/solution.py +++ b/data_structures/binary_trees/2_search_node/solution/solution.py @@ -1 +1,16 @@ # Write solutions here +class Node: + def __init__(self, key, left=None, right=None): + self.key = key + self.left = left + self.right = right + +def search(root, key): + if root is None: + return False + if key == root.key: + return True + elif root.key > key: + return search(root.left, key) + else: + return search(root.right, key) \ No newline at end of file diff --git a/data_structures/binary_trees/3_closest_value/solution/solution.py b/data_structures/binary_trees/3_closest_value/solution/solution.py index 45487fe8..d1f49521 100644 --- a/data_structures/binary_trees/3_closest_value/solution/solution.py +++ b/data_structures/binary_trees/3_closest_value/solution/solution.py @@ -7,7 +7,5 @@ def __init__(self, key, left=None, right=None): def closest_value(node, target): - return - - - + a = node.key + child = node.left if target < a else node.right \ No newline at end of file diff --git a/data_structures/binary_trees/3_insert_node/solution/solution.py b/data_structures/binary_trees/3_insert_node/solution/solution.py index 0a3a0368..c30c19e4 100644 --- a/data_structures/binary_trees/3_insert_node/solution/solution.py +++ b/data_structures/binary_trees/3_insert_node/solution/solution.py @@ -7,9 +7,16 @@ def __init__(self, key, left=None, right=None): # Fill in your code here def insert(self, key): - return - - - - - + if self.key: + if key < self.key: + if self.left is None: + self.left = Node(key) + else: + self.left.insert(key) + else: + if self.right is None: + self.right = Node(key) + else: + self.right.insert(key) + else: + self.key = key \ No newline at end of file From 62437cca41530bfc9f60ade96c568619b57dc48f Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 14 Aug 2020 11:50:30 -0400 Subject: [PATCH 53/65] Completed --- .../2_search_node/solution/solution.py | 2 +- .../3_closest_value/solution/solution.py | 23 ++++++++++++- .../3_insert_node/solution/solution.py | 32 +++++++++++-------- .../3_nth_inorder/solution/solution.py | 19 +++++++++++ .../3_nth_preorder/solution/solution.py | 18 +++++++++++ 5 files changed, 79 insertions(+), 15 deletions(-) diff --git a/data_structures/binary_trees/2_search_node/solution/solution.py b/data_structures/binary_trees/2_search_node/solution/solution.py index 24cabfd8..b66724c1 100644 --- a/data_structures/binary_trees/2_search_node/solution/solution.py +++ b/data_structures/binary_trees/2_search_node/solution/solution.py @@ -8,7 +8,7 @@ def __init__(self, key, left=None, right=None): def search(root, key): if root is None: return False - if key == root.key: + elif key == root.key: return True elif root.key > key: return search(root.left, key) diff --git a/data_structures/binary_trees/3_closest_value/solution/solution.py b/data_structures/binary_trees/3_closest_value/solution/solution.py index d1f49521..508a9244 100644 --- a/data_structures/binary_trees/3_closest_value/solution/solution.py +++ b/data_structures/binary_trees/3_closest_value/solution/solution.py @@ -5,7 +5,28 @@ def __init__(self, key, left=None, right=None): self.right = right self.key = key +# def closest_value_helper(node, target, previous): +# if node: +# if node.key == target: +# return node.key +# child = node.left if target < node.key else node.right +# closest_child = closest_value_helper(child, target, node.key) +# if abs(target - node.key) < abs(target - closest_child): +# return node.key +# else: +# return closest_child +# return previous + +# def closest_value(node, target): +# return closest_value_helper(node, target, node.key) def closest_value(node, target): a = node.key - child = node.left if target < a else node.right \ No newline at end of file + if target < a: + child = node.left + else: + child = node.right + if not child: + return a + b = closest_value(child, target) + return min((a,b), key=lambda x: abs(target - b)) \ No newline at end of file diff --git a/data_structures/binary_trees/3_insert_node/solution/solution.py b/data_structures/binary_trees/3_insert_node/solution/solution.py index c30c19e4..8b6cd61c 100644 --- a/data_structures/binary_trees/3_insert_node/solution/solution.py +++ b/data_structures/binary_trees/3_insert_node/solution/solution.py @@ -6,17 +6,23 @@ def __init__(self, key, left=None, right=None): self.key = key # Fill in your code here + def inorder_nodes(self): + if not self: + return [] + leftNodes = self.left.inorder_nodes() if self.left else [] + rightNodes = self.right.inorder_nodes() if self.right else [] + return [self] + leftNodes + rightNodes + + def insert(self, key): - if self.key: - if key < self.key: - if self.left is None: - self.left = Node(key) - else: - self.left.insert(key) - else: - if self.right is None: - self.right = Node(key) - else: - self.right.insert(key) - else: - self.key = key \ No newline at end of file + if not self: + return Node(key) + node_lst = self.inorder_nodes() + for node in node_lst: + if not node.left: + node.left = Node(key) + return + elif not node.right: + node.right = Node(key) + return + return \ No newline at end of file diff --git a/data_structures/binary_trees/3_nth_inorder/solution/solution.py b/data_structures/binary_trees/3_nth_inorder/solution/solution.py index 6011d5ed..4f8162dc 100644 --- a/data_structures/binary_trees/3_nth_inorder/solution/solution.py +++ b/data_structures/binary_trees/3_nth_inorder/solution/solution.py @@ -1 +1,20 @@ #Write your solutions here +class Node: + def __init__(self, key, left=None, right=None): + self.key = key + self.left = left + self.right = right + +def Inorder(root): + lst = [] + if root: + lst = Inorder(root.left) + lst.append(root.key) + lst += Inorder(root.right) + return lst +def NthInorder(root, n): + inorder_key = Inorder(root) + if len(inorder_key) > n: + return inorder_key[n-1] + else: + return f'no {n}-th element' \ No newline at end of file diff --git a/data_structures/binary_trees/3_nth_preorder/solution/solution.py b/data_structures/binary_trees/3_nth_preorder/solution/solution.py index a8c5443e..d526af60 100644 --- a/data_structures/binary_trees/3_nth_preorder/solution/solution.py +++ b/data_structures/binary_trees/3_nth_preorder/solution/solution.py @@ -1,3 +1,21 @@ #Write your solutions here +class Node: + def __init__(self, key, left=None, right=None): + self.key = key + self.left = left + self.right = right +def Preorder(root): + lst = [] + if root: + lst.append(root.key) + lst += Preorder(root.left) + lst += Preorder(root.right) + return lst +def NthPreorder(root, n): + preorder_key = Preorder(root) + if len(preorder_key) > n: + return preorder_key[n-1] + else: + return f'no {n}-th element' \ No newline at end of file From c3ca725766fec9aad6e1d34e4e14725684c1314d Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 17 Aug 2020 10:51:02 -0400 Subject: [PATCH 54/65] Quiz and partially completed Heaps --- .../1_get_child_nodes/solution/solution.py | 13 ++++-- .../1_get_parent_node/solution/solution.py | 7 ++++ .../heaps/1_is_leaf_node/solution/solution.py | 9 +++- .../1_delete_end/solution/solution.py | 8 ++-- .../linked_lists/2_insert_end/.DS_Store | Bin 0 -> 6148 bytes .../2_insert_end/solution/solution.py | 2 +- data_structures/linked_lists/Quiz_Solution.py | 39 ++++++++++++++++++ .../1_stack_bool/solution/solution.py | 11 +++-- .../3_backspace_compare/.DS_Store | Bin 0 -> 6148 bytes .../3_backspace_compare/solution/solution.py | 6 ++- 10 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 data_structures/linked_lists/2_insert_end/.DS_Store create mode 100644 data_structures/linked_lists/Quiz_Solution.py create mode 100644 data_structures/stacks_and_queues/3_backspace_compare/.DS_Store diff --git a/data_structures/heaps/1_get_child_nodes/solution/solution.py b/data_structures/heaps/1_get_child_nodes/solution/solution.py index 476c5ab8..c1877f7b 100644 --- a/data_structures/heaps/1_get_child_nodes/solution/solution.py +++ b/data_structures/heaps/1_get_child_nodes/solution/solution.py @@ -1,5 +1,10 @@ # Write your solution here - - - - \ No newline at end of file +def get_child_nodes(heap, index): + left_index = 2*index + 1 #left child of heap[i] + right_index = 2*index + 2 #right child of heap[i] + lst = [] #creating empty list to append index's of heap + if left_index < len(heap): + lst.append(heap[left_index]) + if right_index < len(heap): + lst.append(heap[right_index]) + return lst \ No newline at end of file diff --git a/data_structures/heaps/1_get_parent_node/solution/solution.py b/data_structures/heaps/1_get_parent_node/solution/solution.py index aeb50baa..3c130417 100644 --- a/data_structures/heaps/1_get_parent_node/solution/solution.py +++ b/data_structures/heaps/1_get_parent_node/solution/solution.py @@ -1 +1,8 @@ # Write your solution here +def get_parent_node(heap, index): + parent_index = (index-1) // 2 #parent of heap[i] + if index == 0 and len(heap) > 0: + return heap[0] # root is heap[0] + elif index < len(heap): + return heap[parent_index] + return f'{index} is not a valid index in the heap' \ No newline at end of file diff --git a/data_structures/heaps/1_is_leaf_node/solution/solution.py b/data_structures/heaps/1_is_leaf_node/solution/solution.py index 4dca28ed..ebf8ea44 100644 --- a/data_structures/heaps/1_is_leaf_node/solution/solution.py +++ b/data_structures/heaps/1_is_leaf_node/solution/solution.py @@ -1,6 +1,11 @@ # Write your solution here def is_leaf(heap, index): - return - + leaf_index = heap[-1] + if index == 0 and len(heap) > 0: + leaf_index[0] + return False + else: + leaf_index + return True \ No newline at end of file diff --git a/data_structures/linked_lists/1_delete_end/solution/solution.py b/data_structures/linked_lists/1_delete_end/solution/solution.py index aeae22f4..591cb528 100644 --- a/data_structures/linked_lists/1_delete_end/solution/solution.py +++ b/data_structures/linked_lists/1_delete_end/solution/solution.py @@ -1,10 +1,10 @@ # Write your answers here class Node: - def __init__(self, data): + def __init__(self, data=None): self.data = data self.next = None - def __str__(self): - return str(self.data) + # def __str__(self): + # return str(self.data) class linkedlist: def __init__(self, head=None): @@ -15,4 +15,4 @@ def delete_at_end(self): n = self.head while n.next.next != None: n = n.next - n.next = None + n.next = None \ No newline at end of file diff --git a/data_structures/linked_lists/2_insert_end/.DS_Store b/data_structures/linked_lists/2_insert_end/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..751c1c602f52ed51100067ddc18f56f957f6596e GIT binary patch literal 6148 zcmeHKJE{Uf5bX9DESMM?&K11DAbNtmfPo+nWCefmMxM)~S^eShWHk{?q#C+wrl)I` ztzdgwM09c9%tfXm(!dSnYGG)0Za%P4W)uj=9Vhvfy>yrM&<(1eCyd+35v-k@|MPeI zZX5SLCo)R~r~nn90#twsyrqEkURW~;WTXOAfC~I6VBd!VH>`<$pnp0Ld;|cFk#@t{ zX9-}j1h6Ldfylr#sKB6Vju;wr}T|10>5`Tvo`9TlJgU!{PKm+f+aSIXWxcsc8}1-^z`%?)mbwNnth9Rs}`V`J@j d=0#CgY>o4p*atctd8Y&UGhn*VsKBQcxC7Y*70>_x literal 0 HcmV?d00001 diff --git a/data_structures/linked_lists/2_insert_end/solution/solution.py b/data_structures/linked_lists/2_insert_end/solution/solution.py index 6a7df175..88e65f56 100644 --- a/data_structures/linked_lists/2_insert_end/solution/solution.py +++ b/data_structures/linked_lists/2_insert_end/solution/solution.py @@ -10,7 +10,7 @@ def __init__(self, head=None): def insert_at_end(self, data): current_node = self.head previous_node = self.head - while not current_node is None: + while current_node != None: previous_node = current_node current_node = current_node.next new_node = Node(data) diff --git a/data_structures/linked_lists/Quiz_Solution.py b/data_structures/linked_lists/Quiz_Solution.py new file mode 100644 index 00000000..d539221b --- /dev/null +++ b/data_structures/linked_lists/Quiz_Solution.py @@ -0,0 +1,39 @@ +#Quiz - 2 + +#Question1 +class Tree: + def __init__(self, root_node=None): + self.root_node = root_node + +class TreeNode: + def __init__(self, value, left=None, right=None): + self.value = value + self.left = left + self.right = right + +items = Node(4) +items.left = Node(2) +items.right = Node(6) +items.left.left = Node(1) +items.left.right = Node(3) +items.right.left = Node(5) +items.right.right = Node(7) +my_tree_node = TreeNode(items) +# my_tree_node = TreeNode(items, items.left, items.right, items.left.left, items.left.right, items.right.left, items.right.right) + +#Question2 +class LinkedList: + def __init__(self, head_node=None): + self.head_node = head_node + def remove_tail(self): + if self.head_node is None: + return None + n = self.head_node + while n.next.next != None: + n = n.next + n.next = None + +class ListNode: + def __init__(self, value, next=None): + self.value = value + self.next = next \ No newline at end of file diff --git a/data_structures/stacks_and_queues/1_stack_bool/solution/solution.py b/data_structures/stacks_and_queues/1_stack_bool/solution/solution.py index cd845201..34ff1426 100644 --- a/data_structures/stacks_and_queues/1_stack_bool/solution/solution.py +++ b/data_structures/stacks_and_queues/1_stack_bool/solution/solution.py @@ -22,7 +22,10 @@ def pop(self): # Fill in the code for __bool__ def __bool__(self): - if self.head_node is None: - return False - else: - return True \ No newline at end of file + # if self.head_node is None: + # return False + # else: + # return True + if self.head_node: + return True + return False \ No newline at end of file diff --git a/data_structures/stacks_and_queues/3_backspace_compare/.DS_Store b/data_structures/stacks_and_queues/3_backspace_compare/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..751c1c602f52ed51100067ddc18f56f957f6596e GIT binary patch literal 6148 zcmeHKJE{Uf5bX9DESMM?&K11DAbNtmfPo+nWCefmMxM)~S^eShWHk{?q#C+wrl)I` ztzdgwM09c9%tfXm(!dSnYGG)0Za%P4W)uj=9Vhvfy>yrM&<(1eCyd+35v-k@|MPeI zZX5SLCo)R~r~nn90#twsyrqEkURW~;WTXOAfC~I6VBd!VH>`<$pnp0Ld;|cFk#@t{ zX9-}j1h6Ldfylr#sKB6Vju;wr}T|10>5`Tvo`9TlJgU!{PKm+f+aSIXWxcsc8}1-^z`%?)mbwNnth9Rs}`V`J@j d=0#CgY>o4p*atctd8Y&UGhn*VsKBQcxC7Y*70>_x literal 0 HcmV?d00001 diff --git a/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py b/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py index 25462597..94478da0 100644 --- a/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py +++ b/data_structures/stacks_and_queues/3_backspace_compare/solution/solution.py @@ -67,4 +67,8 @@ def backspace_compare(str1, str2): stack_2.pop() else: stack_2.push(char) - return stack_1 == stack_2 \ No newline at end of file + return stack_1 == stack_2 + +str1 = "a#c" +str2 = "c#d" +print(backspace_compare(str1, str2)) \ No newline at end of file From c227cde29c58aa3f8d9acebff91b8032c5ed686c Mon Sep 17 00:00:00 2001 From: PC-coding Date: Mon, 17 Aug 2020 11:17:27 -0400 Subject: [PATCH 55/65] completed --- .../heaps/1_is_leaf_node/solution/solution.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/data_structures/heaps/1_is_leaf_node/solution/solution.py b/data_structures/heaps/1_is_leaf_node/solution/solution.py index ebf8ea44..225dff78 100644 --- a/data_structures/heaps/1_is_leaf_node/solution/solution.py +++ b/data_structures/heaps/1_is_leaf_node/solution/solution.py @@ -1,11 +1,5 @@ # Write your solution here def is_leaf(heap, index): - leaf_index = heap[-1] - if index == 0 and len(heap) > 0: - leaf_index[0] - return False - else: - leaf_index + if index >= (len(heap)//2) and index < len(heap): return True - - \ No newline at end of file + return False \ No newline at end of file From 72e4dce270702299b0284de86f810d0a4901c251 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Tue, 18 Aug 2020 11:31:58 -0400 Subject: [PATCH 56/65] Completed Exercises --- .../solution/.model_solution.py | 6 +++- .../1_count_islands_list/solution/solution.py | 28 +++++++++++++++- .../solution/solution.py | 8 ++++- .../solution/solution.py | 7 +++- .../solution/solution.py | 7 +++- .../solution/solution.py | 6 +++- .../2_most_neighbors/solution/solution.py | 11 ++++++- .../2_num_hops_away_list/solution/solution.py | 14 +++++++- .../solution/solution.py | 28 +++++++++++++++- .../3_num_components/solution/solution.py | 32 ++++++++++++++++++- 10 files changed, 137 insertions(+), 10 deletions(-) diff --git a/algorithms/graph_traversal/1_count_edges_matrix/solution/.model_solution.py b/algorithms/graph_traversal/1_count_edges_matrix/solution/.model_solution.py index 79168448..3f215a5d 100644 --- a/algorithms/graph_traversal/1_count_edges_matrix/solution/.model_solution.py +++ b/algorithms/graph_traversal/1_count_edges_matrix/solution/.model_solution.py @@ -1,2 +1,6 @@ def count_edges(matrix): - return \ No newline at end of file + edge_count = 0 + for i in range(len(matrix)): + for j in range(len(matrix[i])): + edge_count += matrix[i][j] + return edge_count \ No newline at end of file diff --git a/algorithms/graph_traversal/1_count_islands_list/solution/solution.py b/algorithms/graph_traversal/1_count_islands_list/solution/solution.py index 984d95ff..1545b70b 100644 --- a/algorithms/graph_traversal/1_count_islands_list/solution/solution.py +++ b/algorithms/graph_traversal/1_count_islands_list/solution/solution.py @@ -1,2 +1,28 @@ def count_islands(adjacency_list): - return \ No newline at end of file + dictionary_count_edges = dict.fromkeys(adjacency_list.keys(), 0) + for adj_keyNode, edge_list in adjacency_list.items(): + for keyNode in dictionary_count_edges.keys(): + if not adj_keyNode == keyNode: + if keyNode in edge_list: + dictionary_count_edges[keyNode] += 1 + number_of_Islands = 0 + for edgeCount in dictionary_count_edges.values(): + if edgeCount == 0: + number_of_Islands += 1 + return number_of_Islands + +#adjacency_list = { 0: [1], 1: [0, 1, 2], 2: []} + +# dictionary_count_edges -> assigns every key:value pair to 0 + +#dictionary_count_edges = {0:0, 1:0, 2: 0} +#for every key and list in adjacency_list +#0 : [1] +#1 : [0, 1, 2] +#2 : [] + +#dictionary_count_edges = {0:2, 1:1, 2:1} +# for every key in dictionary_count_edges +# 0 -> in 0 and 1 so increment by 2 +# 1 -> in 0 so increment by 1 +# 2 -> in 1 so increment by 1 \ No newline at end of file diff --git a/algorithms/graph_traversal/1_list_to_matrix_representation/solution/solution.py b/algorithms/graph_traversal/1_list_to_matrix_representation/solution/solution.py index 98e903bc..908411a4 100644 --- a/algorithms/graph_traversal/1_list_to_matrix_representation/solution/solution.py +++ b/algorithms/graph_traversal/1_list_to_matrix_representation/solution/solution.py @@ -1 +1,7 @@ -adjacency_matrix = [] +adjacency_matrix = [ + [1, 1, 0, 1, 0], + [0, 0, 0, 1, 1], + [0, 1, 0, 0, 0], + [1, 0, 1, 0, 0], + [0, 0, 0, 0, 0], +] diff --git a/algorithms/graph_traversal/1_matrix_to_list_representation/solution/solution.py b/algorithms/graph_traversal/1_matrix_to_list_representation/solution/solution.py index 6340aed8..f7c80d5c 100644 --- a/algorithms/graph_traversal/1_matrix_to_list_representation/solution/solution.py +++ b/algorithms/graph_traversal/1_matrix_to_list_representation/solution/solution.py @@ -1 +1,6 @@ -adjacency_list = {} \ No newline at end of file +adjacency_list = { + 0: [1,2,3], + 1: [0,3], + 2: [1], + 3: [0,3] +} \ No newline at end of file diff --git a/algorithms/graph_traversal/2_defining_a_graph_list/solution/solution.py b/algorithms/graph_traversal/2_defining_a_graph_list/solution/solution.py index 6e9ac058..9f46b61d 100644 --- a/algorithms/graph_traversal/2_defining_a_graph_list/solution/solution.py +++ b/algorithms/graph_traversal/2_defining_a_graph_list/solution/solution.py @@ -1 +1,6 @@ -adjacency_list = {} +adjacency_list = { + 0: [], + 1: [2], + 2: [1, 3], + 3: [1] +} diff --git a/algorithms/graph_traversal/2_defining_a_graph_matrix/solution/solution.py b/algorithms/graph_traversal/2_defining_a_graph_matrix/solution/solution.py index 98e903bc..2ef3ee3c 100644 --- a/algorithms/graph_traversal/2_defining_a_graph_matrix/solution/solution.py +++ b/algorithms/graph_traversal/2_defining_a_graph_matrix/solution/solution.py @@ -1 +1,5 @@ -adjacency_matrix = [] +adjacency_matrix = [ + [0, 1, 0], + [1, 0, 1], + [0, 1, 0] +] diff --git a/algorithms/graph_traversal/2_most_neighbors/solution/solution.py b/algorithms/graph_traversal/2_most_neighbors/solution/solution.py index 2ada6d4a..944c9227 100644 --- a/algorithms/graph_traversal/2_most_neighbors/solution/solution.py +++ b/algorithms/graph_traversal/2_most_neighbors/solution/solution.py @@ -1,2 +1,11 @@ def most_neighbours(adjacency_list): - return \ No newline at end of file + maximum_len = -1 + maximum_key = -1 + for keyNode, edge_list in adjacency_list.items(): + number_of_neighbours = len(edge_list) + if number_of_neighbours > maximum_len: + maximum_key = keyNode + maximum_len = number_of_neighbours + elif number_of_neighbours == maximum_len and keyNode < maximum_key: + maximum_key = keyNode + return maximum_key \ No newline at end of file diff --git a/algorithms/graph_traversal/2_num_hops_away_list/solution/solution.py b/algorithms/graph_traversal/2_num_hops_away_list/solution/solution.py index 6921aded..7735a3b7 100644 --- a/algorithms/graph_traversal/2_num_hops_away_list/solution/solution.py +++ b/algorithms/graph_traversal/2_num_hops_away_list/solution/solution.py @@ -1,2 +1,14 @@ def hops_away(adjacency_list, node, num_hops): - return \ No newline at end of file + if not node in adjacency_list.keys(): + return [] + elif num_hops == 0: + return [node] + else: + number_hops_away = [] + for neighbour in adjacency_list[node]: + number_hops_away.extend(hops_away(adjacency_list, neighbour, num_hops-1)) + number_hops_away_1 = [] + for n in number_hops_away: + if not n in number_hops_away_1: + number_hops_away_1.append(n) + return number_hops_away_1 \ No newline at end of file diff --git a/algorithms/graph_traversal/3_depth_first_search_matrix/solution/solution.py b/algorithms/graph_traversal/3_depth_first_search_matrix/solution/solution.py index 3d9203e8..ec4a3880 100644 --- a/algorithms/graph_traversal/3_depth_first_search_matrix/solution/solution.py +++ b/algorithms/graph_traversal/3_depth_first_search_matrix/solution/solution.py @@ -1,2 +1,28 @@ def exists_path(matrix, origin, destination): - return \ No newline at end of file + def exists_path_visited(matrix, origin, destination, visited): + if origin in visited: + return False + if not (origin in range(len(matrix)) and + destination in range(len(matrix))): + return False + elif matrix[origin][destination] == 1: + return True + visited.append(origin) + for j in range(len(matrix[origin])): + if matrix[origin][j] == 1 and exists_path_visited(matrix, j, destination, visited): + return True + return False + return exists_path_visited(matrix, origin, destination, []) + +# matrix = [ [0, 1, 0], [0, 0, 1], [0, 1, 0] ] + +# exists_path(matrix, 0, 2) => True + +# exists_path_visited(matrix, 0, 2, []) + +# visited = [0] +# for j = 0, 1, 2 +# matrix, j, destination, visitedlist +# exists_path_visited(matrix, 1, 2, [0]) + +#matrix[1][2] == 1, so we would return True \ No newline at end of file diff --git a/algorithms/graph_traversal/3_num_components/solution/solution.py b/algorithms/graph_traversal/3_num_components/solution/solution.py index 307c1e19..4cafa4b9 100644 --- a/algorithms/graph_traversal/3_num_components/solution/solution.py +++ b/algorithms/graph_traversal/3_num_components/solution/solution.py @@ -1,2 +1,32 @@ +def reachable_dict(matrix): + reachable_dict = {} + for i in range(len(matrix)): + reachable_lst = [] + for j in range(len(matrix[i])): + if matrix[i][j] == 1: + reachable_lst.append(j) + reachable_dict[i] = reachable_lst +#getting every key that's directly reachable and putting it into a list + all_reachable = {} + for i, neighbours in reachable_dict.items(): + all_reachable_lst = [] + for n in neighbours: + all_reachable_lst = all_reachable_lst + reachable_dict[n] + all_reachable_lst = all_reachable_lst + [n] + all_reachable[i] = all_reachable_lst + return all_reachable +#getting every key that's neighbors of the directly reachables and putting it into a list + def num_components(adjacency_matrix): - return \ No newline at end of file + reachableDict = reachable_dict(adjacency_matrix) + num_components = 0 + visited = [False for i in range(len(adjacency_matrix))] + for i in range(len(adjacency_matrix)): + if visited[i] == False: + num_components += 1 + for j in reachableDict[i]: + visited[j] = True + return num_components + +# visited [False, False, False, False] +# visited [] \ No newline at end of file From c8a1f0896abaff298e6e5cd8f47a6951a010f0cb Mon Sep 17 00:00:00 2001 From: PC-coding Date: Tue, 18 Aug 2020 11:48:27 -0400 Subject: [PATCH 57/65] Completed --- .../2_defining_a_graph_list/solution/solution.py | 6 +++--- .../2_defining_a_graph_matrix/solution/solution.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/algorithms/graph_traversal/2_defining_a_graph_list/solution/solution.py b/algorithms/graph_traversal/2_defining_a_graph_list/solution/solution.py index 9f46b61d..ff5f1a77 100644 --- a/algorithms/graph_traversal/2_defining_a_graph_list/solution/solution.py +++ b/algorithms/graph_traversal/2_defining_a_graph_list/solution/solution.py @@ -1,6 +1,6 @@ adjacency_list = { 0: [], - 1: [2], - 2: [1, 3], - 3: [1] + 1: [2, 3], + 2: [1], + 3: [2] } diff --git a/algorithms/graph_traversal/2_defining_a_graph_matrix/solution/solution.py b/algorithms/graph_traversal/2_defining_a_graph_matrix/solution/solution.py index 2ef3ee3c..2518a871 100644 --- a/algorithms/graph_traversal/2_defining_a_graph_matrix/solution/solution.py +++ b/algorithms/graph_traversal/2_defining_a_graph_matrix/solution/solution.py @@ -1,5 +1,5 @@ adjacency_matrix = [ - [0, 1, 0], [1, 0, 1], - [0, 1, 0] + [0, 0, 0], + [1, 0, 1] ] From 1db9a2c2bc1b687aa8843cd077b039571b71dbd4 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 19 Aug 2020 10:59:55 -0400 Subject: [PATCH 58/65] Practice problems --- .../1_frog_hops/solution/solution.py | 15 ++++++++++-- .../1_jewel_thief/solution/solution.py | 23 +++++++++++++++++-- .../1_make_change/solution/solution.py | 15 +++++++++++- .../2_binary_search/solution/solution.py | 14 ++++++++++- .../solution/solution.py | 13 ++++++++++- .../2_min_max/solution/solution.py | 20 +++++++++++++++- .../2_square_root/solution/solution.py | 15 +++++++++++- .../3_scheduling/solution/solution.py | 9 +++++++- .../3_work_projects/solution/solution.py | 12 ++++++++-- 9 files changed, 124 insertions(+), 12 deletions(-) diff --git a/algorithms/greedy_and_divide_and_conquer/1_frog_hops/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/1_frog_hops/solution/solution.py index 1b5d3daa..de410054 100644 --- a/algorithms/greedy_and_divide_and_conquer/1_frog_hops/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/1_frog_hops/solution/solution.py @@ -1,3 +1,14 @@ +def min_hops_helper(max_units, n, river, num_hops): + position = 0 + for i in range(max_units, 0, -1): + if position + i <= n and river[position + i] == 1: + num_hops += 1 + position = position + i + return min_hops_helper(max_units, n-i, river[position:], num_hops) + if position == n: + return num_hops + else: + return -1 + def min_hops(max_units, n, river): - return - \ No newline at end of file + return min_hops_helper(max_units, n, river, 0) \ No newline at end of file diff --git a/algorithms/greedy_and_divide_and_conquer/1_jewel_thief/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/1_jewel_thief/solution/solution.py index ba31302d..db7681c6 100644 --- a/algorithms/greedy_and_divide_and_conquer/1_jewel_thief/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/1_jewel_thief/solution/solution.py @@ -1,3 +1,22 @@ -def steal_jewels(x, jewels): - return +def sort(tuples): + tuples.sort(key = lambda x: x[1]) + tuples.reverse() + return tuples +def steal_jewels(x, jewels): + max_val = 0 + sorted_value_jewels = sort(jewels) + for jewel in sorted_value_jewels: + jewel_weight = jewel[0] + jewel_value = jewel[1] + if x == 0: + return max_val + elif jewel_weight <= x: + max_val += jewel_value + x = x-jewel_weight + else: + # value of 1kg portion of the jewel + unit_val = jewel_value/jewel_weight + max_val += x * unit_val + return max_val + return max_val \ No newline at end of file diff --git a/algorithms/greedy_and_divide_and_conquer/1_make_change/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/1_make_change/solution/solution.py index a7f30ace..372663df 100644 --- a/algorithms/greedy_and_divide_and_conquer/1_make_change/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/1_make_change/solution/solution.py @@ -1,3 +1,16 @@ +def make_change_1(amount, denominations, num_coins): + # if amount is 0 we made all the change and we return num_coins. + if amount == 0: + return num_coins + # itterate through denominations from largest to smallest + for i in range(len(denominations)): + # if the amount is larger or equal to the current coin value we recurse, decreasing the amount by that coin value, and increasing the number of coins by 1. + if amount >= denominations[i]: + return make_change_1(amount-denominations[i], denominations, num_coins+1) + # once we've itterated through all the coins we never hit amount == 0, so we have a remainder we could not make change for and we return -1. + return -1 def make_change(amount, denominations): - return + # Sort denominations in decreasing order + denominations = sorted(denominations, reverse=True) + return make_change_1(amount, denominations, 0) \ No newline at end of file diff --git a/algorithms/greedy_and_divide_and_conquer/2_binary_search/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/2_binary_search/solution/solution.py index 782b41ae..94b9027b 100644 --- a/algorithms/greedy_and_divide_and_conquer/2_binary_search/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/2_binary_search/solution/solution.py @@ -1,2 +1,14 @@ +def binary_search_helper(lst, x, low, high): + if high >= low: + mid = (high + low) // 2 + if lst[mid] == x: + return mid + elif lst[mid] > x: + return binary_search_helper(lst, x, low, mid - 1) + else: + return binary_search_helper(lst, x, mid + 1, high) + else: + return -1 + def binary_search(lst, x): - return \ No newline at end of file + return binary_search_helper(lst, x, 0, len(lst)-1) diff --git a/algorithms/greedy_and_divide_and_conquer/2_make_change_limited_coins/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/2_make_change_limited_coins/solution/solution.py index c1634823..24e9527b 100644 --- a/algorithms/greedy_and_divide_and_conquer/2_make_change_limited_coins/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/2_make_change_limited_coins/solution/solution.py @@ -1,2 +1,13 @@ +def help_make_change(amount, denominations, denomination_keys, number_of_coins): + if amount == 0: + return number_of_coins + for index, keys in enumerate(denomination_keys): + if amount >= keys: + denominations[keys] -= 1 + if denominations[keys] == 0: + denomination_keys = denomination_keys[index + 1:] + return help_make_change(amount - keys, denominations, denomination_keys, number_of_coins + 1) + return -1 def make_change(amount, denominations): - return \ No newline at end of file + denomination_keys = sorted(denominations.keys(), reverse=True) + return help_make_change(amount, denominations, denomination_keys, 0) \ No newline at end of file diff --git a/algorithms/greedy_and_divide_and_conquer/2_min_max/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/2_min_max/solution/solution.py index 3cd23490..560cd607 100644 --- a/algorithms/greedy_and_divide_and_conquer/2_min_max/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/2_min_max/solution/solution.py @@ -1,2 +1,20 @@ +def helper_min_max(lst, low, high): + maximum = lst[high] + minimum = lst[low] + if low == high: + return (minimum, maximum) + elif low + 1 == high: + if lst[low] > lst[high]: + maximum = lst[low] + minimum = lst[high] + else: + maximum = lst[high] + minimum = lst[low] + return (minimum, maximum) + else: + mid = int((low + high) / 2) + min1, max1 = helper_min_max(lst, low, mid) + min2, max2 = helper_min_max(lst, mid + 1, high) + return (min(min1, min2), max(max1, max2)) def min_max(lst): - return \ No newline at end of file + return helper_min_max(lst, 0, len(lst)-1) \ No newline at end of file diff --git a/algorithms/greedy_and_divide_and_conquer/2_square_root/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/2_square_root/solution/solution.py index 05de023f..4beaf8df 100644 --- a/algorithms/greedy_and_divide_and_conquer/2_square_root/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/2_square_root/solution/solution.py @@ -1,2 +1,15 @@ def bin_sqrt(n): - return \ No newline at end of file + if n == 0 or n == 1: + return n + beginning = 1 + end = n + while beginning <= end: + mid = (beginning + end) // 2 + if mid*mid == n: + return mid + if mid*mid < n: + beginning = mid + 1 + answer = mid + else: + end = mid - 1 + return answer \ No newline at end of file diff --git a/algorithms/greedy_and_divide_and_conquer/3_scheduling/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/3_scheduling/solution/solution.py index 24ea4ba8..4a6cc712 100644 --- a/algorithms/greedy_and_divide_and_conquer/3_scheduling/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/3_scheduling/solution/solution.py @@ -1,3 +1,10 @@ def task_schedule(tasks): - return + tasks.sort(key = lambda x: x[1]) + number_of_tasks = 0 + current_end = 0 + for x in tasks: + if x[0] >= current_end: + current_end = x[1] + number_of_tasks += 1 + return number_of_tasks \ No newline at end of file diff --git a/algorithms/greedy_and_divide_and_conquer/3_work_projects/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/3_work_projects/solution/solution.py index babcb8e7..d0c3475e 100644 --- a/algorithms/greedy_and_divide_and_conquer/3_work_projects/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/3_work_projects/solution/solution.py @@ -1,3 +1,11 @@ - def max_profits(projects): - return + projects.sort(key = lambda x: x[1], reverse=True) + dict = {} + profit = 0 + for x in projects: + for i in range(x[0], 0, -1): + if not i in dict: + dict[i] = x[1] + profit += x[1] + break + return profit \ No newline at end of file From 4cfa87ef62ca928d70f2816d8f9fff1c4d87ae7e Mon Sep 17 00:00:00 2001 From: PC-coding Date: Wed, 19 Aug 2020 11:00:19 -0400 Subject: [PATCH 59/65] Practice problems --- .../3_scheduling/solution/solution.py | 1 - 1 file changed, 1 deletion(-) diff --git a/algorithms/greedy_and_divide_and_conquer/3_scheduling/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/3_scheduling/solution/solution.py index 4a6cc712..e9a756e0 100644 --- a/algorithms/greedy_and_divide_and_conquer/3_scheduling/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/3_scheduling/solution/solution.py @@ -1,4 +1,3 @@ - def task_schedule(tasks): tasks.sort(key = lambda x: x[1]) number_of_tasks = 0 From 8fabf11b55200d58efc9ffb5ea30820a1f725c7d Mon Sep 17 00:00:00 2001 From: PC-coding Date: Thu, 20 Aug 2020 10:58:09 -0400 Subject: [PATCH 60/65] Completed Exercises --- .../1_frequency_array/solution/solution.py | 10 ++- .../1_merge_sorted/solution/solution.py | 20 +++++- .../1_min_or_max_heap/solution/solution.py | 63 ++++++++++++++++++- .../solution/solution.py | 21 ++++++- .../2_median_of_medians/solution/solution.py | 9 ++- .../2_sort_linked_list/solution/solution.py | 20 ++++-- .../2_sort_vectors/solution/solution.py | 12 +++- .../3_sort_students/solution/solution.py | 13 +++- 8 files changed, 153 insertions(+), 15 deletions(-) diff --git a/algorithms/sorting/1_frequency_array/solution/solution.py b/algorithms/sorting/1_frequency_array/solution/solution.py index e5b85e17..294cb06f 100644 --- a/algorithms/sorting/1_frequency_array/solution/solution.py +++ b/algorithms/sorting/1_frequency_array/solution/solution.py @@ -1,3 +1,9 @@ - def frequency_array(lst): - return + maximum = -1 + for i in lst: + if i > maximum: + maximum = i + frequency_lst = [0 for i in range(maximum + 1)] + for i in range(len(lst)): + frequency_lst[lst[i]] += 1 + return frequency_lst diff --git a/algorithms/sorting/1_merge_sorted/solution/solution.py b/algorithms/sorting/1_merge_sorted/solution/solution.py index f79fd0e4..95a88b9d 100644 --- a/algorithms/sorting/1_merge_sorted/solution/solution.py +++ b/algorithms/sorting/1_merge_sorted/solution/solution.py @@ -1,2 +1,20 @@ +# def merge_sorted(lst1, lst2): + # new_lst = lst1 + lst2 + # new_lst.sort() + # return new_lst +def merge_helper(lst1, lst2, merged_lst): + if len(lst1) == 0: + merged_lst.extend(lst2) + return merged_lst + elif len(lst2) == 0: + merged_lst.extend(lst1) + return merged_lst + elif lst1[0] <= lst2[0]: + merged_lst.append(lst1[0]) + return merge_helper(lst1[1:], lst2, merged_lst) + else: + merged_lst.append(lst2[0]) + return merge_helper(lst1, lst2[1:], merged_lst) def merge_sorted(lst1, lst2): - return \ No newline at end of file + return merge_helper(lst1, lst2, []) + \ No newline at end of file diff --git a/algorithms/sorting/1_min_or_max_heap/solution/solution.py b/algorithms/sorting/1_min_or_max_heap/solution/solution.py index bbac9775..5abb3508 100644 --- a/algorithms/sorting/1_min_or_max_heap/solution/solution.py +++ b/algorithms/sorting/1_min_or_max_heap/solution/solution.py @@ -1,2 +1,63 @@ +def max_heap(heap): + if len(heap) == 0: + return True + for i in range(len(heap)): + root = heap[i] + leftindex = (2*i) + 1 + rightindex = (2*i) + 2 + left = None + right = None + if (2*i)+1 < len(heap): + left = heap[(2*i)+1] + if (2*i)+2 < len(heap): + right = heap[(2*i)+2] + if left == None and right == None: + return True + if left == None: + if right < root: + return max_heap(heap[rightindex:]) + elif right > root: + return False + if right == None: + if left < root: + return max_heap(heap[leftindex:]) + elif left > root: + return False + if left > root or right > root: + return False + return True +def min_heap(heap): + if len(heap) == 0: + return True + for i in range(len(heap)): + root = heap[i] + leftindex = (2*i) + 1 + rightindex = (2*i) + 2 + left = None + right = None + if (2*i)+1 < len(heap): + left = heap[(2*i)+1] + if (2*i)+2 < len(heap): + right = heap[(2*i)+2] + if left == None and right == None: + return True + if left == None: + if right > root: + return min_heap(heap[rightindex:]) + elif right < root: + return False + if right == None: + if left > root: + return min_heap(heap[leftindex:]) + elif left < root: + return False + if left < root or right < root: + return False + return True def min_or_max_heap(heap): - return \ No newline at end of file + if min_heap(heap): + return 'min' + elif max_heap(heap): + return 'max' + else: + return 'neither' \ No newline at end of file diff --git a/algorithms/sorting/2_frequency_array_cumulative/solution/solution.py b/algorithms/sorting/2_frequency_array_cumulative/solution/solution.py index 6cd3c60b..403e3a1d 100644 --- a/algorithms/sorting/2_frequency_array_cumulative/solution/solution.py +++ b/algorithms/sorting/2_frequency_array_cumulative/solution/solution.py @@ -1,3 +1,20 @@ -def frequency_array_cumulative(lst): - return +def frequency_array(lst): + maximum = -1 + for i in lst: + if i > maximum: + maximum = i + frequency_lst = [0 for i in range(maximum + 1)] + for i in range(len(lst)): + frequency_lst[lst[i]] += 1 + return frequency_lst +def frequency_array_cumulative(lst): + frequency_lst = frequency_array(lst) + frequency_length = len(frequency_lst) + frequency_list = [0 for i in range(frequency_length)] + for i in range(frequency_length): + if i == 0: + frequency_list[i] = frequency_lst[i] + else: + frequency_list[i] = frequency_lst[i] + frequency_list[i-1] + return frequency_list \ No newline at end of file diff --git a/algorithms/sorting/2_median_of_medians/solution/solution.py b/algorithms/sorting/2_median_of_medians/solution/solution.py index b1d3c339..09b73f79 100644 --- a/algorithms/sorting/2_median_of_medians/solution/solution.py +++ b/algorithms/sorting/2_median_of_medians/solution/solution.py @@ -1,2 +1,9 @@ def median_of_medians(lst): - return \ No newline at end of file + sublists = [lst[i:i+5] for i in range(0, len(lst), 5)] + medians = [] + for lists in sublists: + medians.append(sorted(lists)[len(lists)//2]) + if len(medians) <= 5: + return sorted(medians)[len(medians)//2] + else: + return median_of_medians(medians) \ No newline at end of file diff --git a/algorithms/sorting/2_sort_linked_list/solution/solution.py b/algorithms/sorting/2_sort_linked_list/solution/solution.py index 75e37545..365accc8 100644 --- a/algorithms/sorting/2_sort_linked_list/solution/solution.py +++ b/algorithms/sorting/2_sort_linked_list/solution/solution.py @@ -2,13 +2,21 @@ class ListNode: def __init__(self, value=None, next=None): self.value = value self.next = next - class LinkedList: def __init__(self, head=None): self.head = head - def sort_ll(self): - ... - - - + current_n = self.head + index = None + if self.head == None: + return None + else: + while current_n != None: + index = current_n.next + while index != None: + if current_n.value > index.value: + x = current_n.value + current_n.value = index.value + index.value = x + index = index.next + current_n = current_n.next \ No newline at end of file diff --git a/algorithms/sorting/2_sort_vectors/solution/solution.py b/algorithms/sorting/2_sort_vectors/solution/solution.py index d64b9657..3b20845e 100644 --- a/algorithms/sorting/2_sort_vectors/solution/solution.py +++ b/algorithms/sorting/2_sort_vectors/solution/solution.py @@ -1,4 +1,14 @@ import math +def magnitude(vector): + return math.sqrt((vector[0][0]-vector[1][0])**2 + (vector[0][1]-vector[1][1])**2) + def sort_vectors(vector_lst): - return + for index in range(1, len(vector_lst)): + current_vector = vector_lst[index] + position = index + while position > 0 and magnitude(vector_lst[position-1]) > magnitude(current_vector): + vector_lst[position] = vector_lst[position-1] + position -= 1 + vector_lst[position] = current_vector + return vector_lst \ No newline at end of file diff --git a/algorithms/sorting/3_sort_students/solution/solution.py b/algorithms/sorting/3_sort_students/solution/solution.py index 18aa8dcc..cdaf6e23 100644 --- a/algorithms/sorting/3_sort_students/solution/solution.py +++ b/algorithms/sorting/3_sort_students/solution/solution.py @@ -3,6 +3,17 @@ def __init__(self, name=None, avg=None, grade=None): self.name = name self.avg = avg self.grade = grade + def __lt__(self, other): + if self.grade < other.grade: + return True + if self.grade == other.grade: + if self.avg < other.avg: + return True + if self.avg == other.avg: + return self.name < other.name + return False + def __repr__(self): + return f'Name: {self.name}, Avg: {self.avg}, Grade: {self.grade}' def sort_students(slst): - return + return sorted(slst) From 039cb7f63205d7c78040d0e45a987e324c064957 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 21 Aug 2020 11:05:14 -0400 Subject: [PATCH 61/65] Completed --- .../1_factorial/solution/solution.py | 5 ++++- .../1_is_palindrome/solution/solution.py | 4 ++-- .../1_product_sequence_n/solution/solution.py | 5 ++++- .../solution/solution.py | 5 ++++- .../2_Tribonacci/solution/solution.py | 20 ++++++++++++++++- .../2_paths_to_nth_stair/solution/solution.py | 13 +++++++---- .../2_shortest_path_to_1/solution/solution.py | 22 ++++++++++++++++++- 7 files changed, 63 insertions(+), 11 deletions(-) diff --git a/algorithms/dynamic_programming/1_factorial/solution/solution.py b/algorithms/dynamic_programming/1_factorial/solution/solution.py index 0eaee264..fa53c9fc 100644 --- a/algorithms/dynamic_programming/1_factorial/solution/solution.py +++ b/algorithms/dynamic_programming/1_factorial/solution/solution.py @@ -1,2 +1,5 @@ def factorial(n): - return \ No newline at end of file + if n <= 1: + return 1 + else: + return n * factorial(n-1) \ No newline at end of file diff --git a/algorithms/dynamic_programming/1_is_palindrome/solution/solution.py b/algorithms/dynamic_programming/1_is_palindrome/solution/solution.py index b068a658..74071108 100644 --- a/algorithms/dynamic_programming/1_is_palindrome/solution/solution.py +++ b/algorithms/dynamic_programming/1_is_palindrome/solution/solution.py @@ -1,6 +1,6 @@ - def is_palindrome(string): if len(string) <= 1: return True else: - return string[0] == string[-1] and is_palindrome(string[1:-1]) + return string[0] == string[-1] + is_palindrome(string[1:-1]) \ No newline at end of file diff --git a/algorithms/dynamic_programming/1_product_sequence_n/solution/solution.py b/algorithms/dynamic_programming/1_product_sequence_n/solution/solution.py index f9e379ed..8ab12897 100644 --- a/algorithms/dynamic_programming/1_product_sequence_n/solution/solution.py +++ b/algorithms/dynamic_programming/1_product_sequence_n/solution/solution.py @@ -1,2 +1,5 @@ def product_sequence_n(n): - return + if n <= 1: + return 1 + else: + return n * product_sequence_n(n-2) diff --git a/algorithms/dynamic_programming/1_sum_first_n_integers/solution/solution.py b/algorithms/dynamic_programming/1_sum_first_n_integers/solution/solution.py index 194623e1..e3f29280 100644 --- a/algorithms/dynamic_programming/1_sum_first_n_integers/solution/solution.py +++ b/algorithms/dynamic_programming/1_sum_first_n_integers/solution/solution.py @@ -1,2 +1,5 @@ def sum_first_n(n): - return + if n == 1: + return 1 + else: + return n + sum_first_n(n-1) diff --git a/algorithms/dynamic_programming/2_Tribonacci/solution/solution.py b/algorithms/dynamic_programming/2_Tribonacci/solution/solution.py index 655f2cbe..1756866d 100644 --- a/algorithms/dynamic_programming/2_Tribonacci/solution/solution.py +++ b/algorithms/dynamic_programming/2_Tribonacci/solution/solution.py @@ -1,2 +1,20 @@ +# def tribonacci(n): +# if n == 0 or n == 1: +# return 0 +# elif n == 2: +# return 1 +# else: +# return tribonacci(n-1) + tribonacci(n-2) +tribonacci(n-3) def tribonacci(n): - return \ No newline at end of file + if n == 0 or n == 1: + return 0 + if n == 2: + return 1 + trib = [-1 for x in range(n+1)] + trib[0] = 0 + trib[1] = 0 + trib[2] = 1 + for x in range(3, n+1): + # trib[x] = trib[x-1] + trib[x-2] + trib[x-3] + trib[x] = trib[x-3] + trib[x-2] + trib[x-1] #to make the bottom-up tabulation make more sense + return trib[x] diff --git a/algorithms/dynamic_programming/2_paths_to_nth_stair/solution/solution.py b/algorithms/dynamic_programming/2_paths_to_nth_stair/solution/solution.py index 60cba7d0..f9a48356 100644 --- a/algorithms/dynamic_programming/2_paths_to_nth_stair/solution/solution.py +++ b/algorithms/dynamic_programming/2_paths_to_nth_stair/solution/solution.py @@ -1,5 +1,10 @@ def paths_nth_stair(n): - return - - - + if n <= 2: + return n + else: + paths = [-1 for x in range(n+1)] + paths[1] = 1 + paths[2] = 2 + for x in range(3, n+1): + paths[x] = paths[x-1] + paths[x-2] + return paths[n] \ No newline at end of file diff --git a/algorithms/dynamic_programming/2_shortest_path_to_1/solution/solution.py b/algorithms/dynamic_programming/2_shortest_path_to_1/solution/solution.py index 2fa2f79d..88bedbf9 100644 --- a/algorithms/dynamic_programming/2_shortest_path_to_1/solution/solution.py +++ b/algorithms/dynamic_programming/2_shortest_path_to_1/solution/solution.py @@ -1,2 +1,22 @@ def shortest_path_to_1(n): - return + if n == 1: + return 0 + elif n == 2 or n == 3: + return 1 + shortest = [-1 for x in range(n+1)] + shortest[1] = 0 + shortest[2] = 1 + shortest[3] = 1 + for x in range(4, n+1): + if shortest[x] == -1: + if x % 3 == 0 and x % 2 == 0: + shortest[x] = 1 + min(shortest[x-1], shortest[x//3], shortest[x//2]) + elif x % 3 == 0: + shortest[x] = 1 + min(shortest[x-1], shortest[x//3]) + elif x % 2 == 0: + shortest[x] = 1 + min(shortest[x-1], shortest[x//2]) + else: + shortest[x] = 1 + shortest[x-1] + return shortest[n] + + From f5e541dc04d38d7863a25cac847ede2126d5e1e4 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 21 Aug 2020 12:16:42 -0400 Subject: [PATCH 62/65] Completed --- .../solution/solution.py | 13 ++++++++++- .../solution/solution.py | 23 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/algorithms/dynamic_programming/3_longest_common_subsequence/solution/solution.py b/algorithms/dynamic_programming/3_longest_common_subsequence/solution/solution.py index 129b22d8..8d77638b 100644 --- a/algorithms/dynamic_programming/3_longest_common_subsequence/solution/solution.py +++ b/algorithms/dynamic_programming/3_longest_common_subsequence/solution/solution.py @@ -1,2 +1,13 @@ def longest_common_subseq(str1, str2): - return \ No newline at end of file + length_1 = len(str1) + length_2 = len(str2) + Length = [[None]*(length_2 + 1) for i in range(length_1 + 1)] + for i in range(length_1 + 1): + for x in range(length_2 + 1): + if i == 0 or x == 0: + Length[i][x] = 0 + elif str1[i-1] == str2[x-1]: + Length[i][x] = Length[i-1][x-1] + 1 + else: + Length[i][x] = max(Length[i-1][x], Length[i][x-1]) + return Length[length_1][length_2] \ No newline at end of file diff --git a/algorithms/dynamic_programming/3_palindromic_substring/solution/solution.py b/algorithms/dynamic_programming/3_palindromic_substring/solution/solution.py index 785697e6..7f221d07 100644 --- a/algorithms/dynamic_programming/3_palindromic_substring/solution/solution.py +++ b/algorithms/dynamic_programming/3_palindromic_substring/solution/solution.py @@ -1,2 +1,23 @@ def longest_palindrome_substr(str): - return \ No newline at end of file + n = len(str) + if n == 0: + return 0 + table = [[0 for x in range(n)] for y in range(n)] + max_length = 1 + for i in range(n): + table[i][i] = True + start = 0 + for i in range(n-1): + if (str[i] == str[i+1]): + table[i][i+1] = True + start = i + max_length = 2 + for k in range(3, n+1): + for i in range(n - k + 1): + j = i + k - 1 + if (table[i+1][j-1] and str[i] == str[j]): + table[i][j] = True + if k > max_length: + start = i + max_length = k + return max_length \ No newline at end of file From 4d375f457a97fb6b6898627015318f4c38a4e8b5 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 21 Aug 2020 13:42:58 -0400 Subject: [PATCH 63/65] edited --- .../2_make_change_limited_coins/solution/solution.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/algorithms/greedy_and_divide_and_conquer/2_make_change_limited_coins/solution/solution.py b/algorithms/greedy_and_divide_and_conquer/2_make_change_limited_coins/solution/solution.py index 24e9527b..1656d6d0 100644 --- a/algorithms/greedy_and_divide_and_conquer/2_make_change_limited_coins/solution/solution.py +++ b/algorithms/greedy_and_divide_and_conquer/2_make_change_limited_coins/solution/solution.py @@ -1,13 +1,25 @@ def help_make_change(amount, denominations, denomination_keys, number_of_coins): + # if we have ammount 0, we made all the change and we return num_coins. if amount == 0: return number_of_coins + # we itterate through the denomination_keys list by index and the denomination key for index, keys in enumerate(denomination_keys): + # if amount is greater than the denomination key if amount >= keys: + # we update the denomination dict taking one away denominations[keys] -= 1 + # if we now have none of that coin left in our denominations dict + # we update the list by removing that element and only looking at the + # denominations in the rest of the list. if denominations[keys] == 0: denomination_keys = denomination_keys[index + 1:] + # we recurse, updating the amount by subtracting the coin we saw, and + # adding one to num_coins return help_make_change(amount - keys, denominations, denomination_keys, number_of_coins + 1) + # if we itterated through all the coins and still have a remainder, we could not + # make all the change, so we return -1. return -1 def make_change(amount, denominations): + # create a list of denomination values sorted in decreasing order. denomination_keys = sorted(denominations.keys(), reverse=True) return help_make_change(amount, denominations, denomination_keys, 0) \ No newline at end of file From bc9e62c09f541338a00efafcd7efd113428c564d Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 21 Aug 2020 13:43:39 -0400 Subject: [PATCH 64/65] edited --- .../sorting/3_quick_sort/solution/solution.py | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/algorithms/sorting/3_quick_sort/solution/solution.py b/algorithms/sorting/3_quick_sort/solution/solution.py index a7495778..a54e3336 100644 --- a/algorithms/sorting/3_quick_sort/solution/solution.py +++ b/algorithms/sorting/3_quick_sort/solution/solution.py @@ -1,6 +1,30 @@ def median_of_medians(lst): - return - -def quick_sort(lst): - return + sublists = [lst[i:i+5] for i in range(0, len(lst), 5)] + medians = [] + for lists in sublists: + medians.append(sorted(lists)[len(lists)//2]) + if len(medians) <= 5: + return sorted(medians)[len(medians)//2] + else: + return median_of_medians(medians) + +def _partition(lst, min_index, max_index): + pivot_index = lst.index(median_of_medians(lst[min_index:max_index+1])) + lst[min_index], lst[pivot_index] = lst[pivot_index], lst[min_index] + pivot_index = min_index + for index in range(min_index, max_index + 1): + if lst[index] < lst[pivot_index]: + lst[pivot_index], lst[index] = lst[index], lst[pivot_index] + lst[pivot_index + 1], lst[index] = lst[index], lst[pivot_index + 1] + pivot_index += 1 + return pivot_index +def quick_sort_helper(lst, min_index, max_index): + if min_index < max_index: + pivot_index = _partition(lst, min_index, max_index) + quick_sort_helper(lst, min_index, pivot_index - 1) + quick_sort_helper(lst, pivot_index + 1, max_index) + +def quick_sort(lst): + quick_sort_helper(lst, 0, len(lst) - 1) + return lst \ No newline at end of file From 4b2b2d2a2a059b5a127da5ac49ad38e85a92eba8 Mon Sep 17 00:00:00 2001 From: PC-coding Date: Fri, 21 Aug 2020 13:44:24 -0400 Subject: [PATCH 65/65] edited --- data_structures/linked_lists/Quiz_Solution.py | 17 +++++++------- .../2_capture_display/Solution/solution.py | 7 +++--- introduction_to_python/assessment/solution.py | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 introduction_to_python/assessment/solution.py diff --git a/data_structures/linked_lists/Quiz_Solution.py b/data_structures/linked_lists/Quiz_Solution.py index d539221b..8687ea39 100644 --- a/data_structures/linked_lists/Quiz_Solution.py +++ b/data_structures/linked_lists/Quiz_Solution.py @@ -11,15 +11,14 @@ def __init__(self, value, left=None, right=None): self.left = left self.right = right -items = Node(4) -items.left = Node(2) -items.right = Node(6) -items.left.left = Node(1) -items.left.right = Node(3) -items.right.left = Node(5) -items.right.right = Node(7) -my_tree_node = TreeNode(items) -# my_tree_node = TreeNode(items, items.left, items.right, items.left.left, items.left.right, items.right.left, items.right.right) +items = TreeNode(4) +items.left = TreeNode(2) +items.right = TreeNode(6) +items.left.left = TreeNode(1) +items.left.right = TreeNode(3) +items.right.left = TreeNode(5) +items.right.right = TreeNode(7) +my_tree_node = Tree(items) #Question2 class LinkedList: diff --git a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py index 69d7ac2b..abc9b361 100644 --- a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py +++ b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py @@ -1,6 +1,7 @@ # Code your solution here -name = input("Enter your name:") -age = input("Enter your age:") - +# name = input("Enter your name:") +# age = input("Enter your age:") +name = 'Charlie' +age = 100 print(name) print(age) \ No newline at end of file diff --git a/introduction_to_python/assessment/solution.py b/introduction_to_python/assessment/solution.py new file mode 100644 index 00000000..fa77ab1b --- /dev/null +++ b/introduction_to_python/assessment/solution.py @@ -0,0 +1,23 @@ +# Quiz1 + +#Question1 +def recursive_multiply(x, y): + if x == 0: + return 0 + elif x == 1: + return y + else: + return y + recursive_multiply(x-1, y) + +# Question2 +class Ticket: + counter = 0 + def __init__(self): + self.ticket_number = Ticket.counter + if Ticket.counter == 99: + Ticket.counter = 0 + else: + Ticket.counter += 1 +for ticket in range(0, 100): + my_ticket = Ticket() + print(my_ticket.ticket_number) \ No newline at end of file