From 38827cbeaac99d6803f9de7be8563bf18f04f72c Mon Sep 17 00:00:00 2001 From: aman Date: Sun, 6 Oct 2024 13:11:37 +0500 Subject: [PATCH 01/21] Add task1 and task2 --- .../task1.py" | 12 ++++++++++++ .../task2.py" | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task1.py" create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task2.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task1.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task1.py" new file mode 100644 index 00000000..c503d0d4 --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task1.py" @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +a, b = input("Type two numbers: ").split() +a = int(a) +b = int(b) +if a > b: + print("1") +elif a == b: + print("0") +else: + print("-1") + diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task2.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task2.py" new file mode 100644 index 00000000..b2245101 --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task2.py" @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +def MaxNum(a): + max_num = a[0] + for i in a: + if i > max_num: + max_num = i + return max_num +a = input("Please enter the 3 numbers: ") +a = list(map(int, a.split())) +print("The largest number is: ", MaxNum(a)) + From 80ad61d0877711d3fb2153eeea9956d77ec95e8e Mon Sep 17 00:00:00 2001 From: aman Date: Mon, 7 Oct 2024 11:37:46 +0500 Subject: [PATCH 02/21] Renaming files and add ex. pow a b --- .../even_num.py" | 12 ++++++++++++ .../int_cmp.py" | 0 .../max_of_three.py" | 0 .../pow_a_b.py" | 13 +++++++++++++ .../print_even_a_b.py" | 0 5 files changed, 25 insertions(+) create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/even_num.py" rename "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task1.py" => "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/int_cmp.py" (100%) rename "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task2.py" => "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/max_of_three.py" (100%) create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/pow_a_b.py" create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/print_even_a_b.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/even_num.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/even_num.py" new file mode 100644 index 00000000..ce74e27f --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/even_num.py" @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +def even_num(a, b): + num = [] + for i in range(a, b + 1): + if i % 2 == 0: + num.append(i) + print(num) +a, b = input("Type two numbers: ").split() +a = int(a) +b = int(b) +even_num(a, b) \ No newline at end of file diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task1.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/int_cmp.py" similarity index 100% rename from "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task1.py" rename to "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/int_cmp.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task2.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/max_of_three.py" similarity index 100% rename from "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/task2.py" rename to "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/max_of_three.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/pow_a_b.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/pow_a_b.py" new file mode 100644 index 00000000..0b6ce9b7 --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/pow_a_b.py" @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +def sum_sqr(n): + num = 0 + if int(n) >= 1 and int(n) <= 10860: + for i in range(1, n + 1): + num += i ** 2 + print(num) + else: + print("Please provide a positive number and in a range of 1 to 10860!") +num = input("Please enter a number: ") +num = int(num) +sum_sqr(num) \ No newline at end of file diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/print_even_a_b.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/print_even_a_b.py" new file mode 100644 index 00000000..e69de29b From ae821c75649ace65b048dd15addfb080e7da7966 Mon Sep 17 00:00:00 2001 From: aman Date: Tue, 8 Oct 2024 10:16:18 +0500 Subject: [PATCH 03/21] add code for ex. print_even_a_b --- .../calc_deposit.py" | 11 +++++++++++ .../even_num.py" | 12 ------------ .../print_even_a_b.py" | 12 ++++++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/calc_deposit.py" delete mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/even_num.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/calc_deposit.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/calc_deposit.py" new file mode 100644 index 00000000..fc759c97 --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/calc_deposit.py" @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +def calc_deposit(duration:int, rate:float, sum:int): + res = sum + for i in range(duration): + res += res * rate / 100 + print(res) +duration, rate, sum = input("Type number the folowing order duration, rate, sum: ").split() + +calc_deposit(int(duration), float(rate), int(sum)) + diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/even_num.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/even_num.py" deleted file mode 100644 index ce74e27f..00000000 --- "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/even_num.py" +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python3 - -def even_num(a, b): - num = [] - for i in range(a, b + 1): - if i % 2 == 0: - num.append(i) - print(num) -a, b = input("Type two numbers: ").split() -a = int(a) -b = int(b) -even_num(a, b) \ No newline at end of file diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/print_even_a_b.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/print_even_a_b.py" index e69de29b..ce74e27f 100644 --- "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/print_even_a_b.py" +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/print_even_a_b.py" @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +def even_num(a, b): + num = [] + for i in range(a, b + 1): + if i % 2 == 0: + num.append(i) + print(num) +a, b = input("Type two numbers: ").split() +a = int(a) +b = int(b) +even_num(a, b) \ No newline at end of file From a171bbb4d102f4cf4c6b0eee08798d639491e006 Mon Sep 17 00:00:00 2001 From: aman Date: Tue, 8 Oct 2024 11:16:02 +0500 Subject: [PATCH 04/21] Add the code for the task minimum number --- .../min.py" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" new file mode 100644 index 00000000..0ebea324 --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +def min_num(nums): + if not nums: + return None + res = nums[0] + for i in nums: + if i < res: + res = i + return res + +num_input = input("Please enter the numbers, there must be spaces between the numbers.: ") +numbers = list(map(int, num_input.split())) +print("The mininmum number is: ", min_num(numbers)) + + \ No newline at end of file From 32c0fd7f087feda205324ec75e362e4c4da190af Mon Sep 17 00:00:00 2001 From: aman Date: Tue, 8 Oct 2024 11:37:18 +0500 Subject: [PATCH 05/21] Add some changes in min.py --- .../min.py" | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" index 0ebea324..4e246a1f 100644 --- "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" @@ -1,13 +1,17 @@ #!/usr/bin/env python3 def min_num(nums): - if not nums: - return None - res = nums[0] - for i in nums: - if i < res: - res = i - return res + if 0 <= len(nums) <= 5: + if not nums: + print("The list is empty!") + return None + res = nums[0] + for i in nums: + if i < res: + res = i + return res + else: + print("The numbers out of range!") num_input = input("Please enter the numbers, there must be spaces between the numbers.: ") numbers = list(map(int, num_input.split())) From d668287a04e5799811a6dd180eabcd745a37789f Mon Sep 17 00:00:00 2001 From: aman Date: Tue, 8 Oct 2024 13:56:18 +0500 Subject: [PATCH 06/21] Add little change in min.py and create function for range task --- .../min.py" | 2 +- .../range.py" | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/range.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" index 4e246a1f..21f3667c 100644 --- "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/min.py" @@ -1,7 +1,7 @@ #!/usr/bin/env python3 def min_num(nums): - if 0 <= len(nums) <= 5: + if 0 <= len(nums) <= 10000: if not nums: print("The list is empty!") return None diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/range.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/range.py" new file mode 100644 index 00000000..3dc6f280 --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/range.py" @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +def list_range(n): + size = int(n) + if 0 <= size <= 10000: + num = [] + for i in range(1, size + 1): + num.append(i) + print(num) + else: + print("The number is out of range!") + +n = input("Please enter the size of list: ") +list_range(n) \ No newline at end of file From 843317c68adb65436eba8b393364a9f379f03b3e Mon Sep 17 00:00:00 2001 From: aman Date: Wed, 9 Oct 2024 09:24:12 +0500 Subject: [PATCH 07/21] Add codes for the task sum array --- .../sum_num.py" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/sum_num.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/sum_num.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/sum_num.py" new file mode 100644 index 00000000..0737a4ca --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/sum_num.py" @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +def sum_nums(nums): + if 0 <= len(nums) <= 10000: + sum = 0 + for i in nums: + sum += i + print(sum) + else: + print("The length of the list is out of the acceptable range!") +nums = input("Please enter the numbers: " ) +numbers = list(map(int, nums.split())) +sum_nums(numbers) \ No newline at end of file From ca65f27df5b67a553ae92ea141419536b632cb2b Mon Sep 17 00:00:00 2001 From: aman Date: Thu, 10 Oct 2024 10:45:42 +0500 Subject: [PATCH 08/21] Add code for task sort --- .../sort.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/sort.py" diff --git "a/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/sort.py" "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/sort.py" new file mode 100644 index 00000000..dfed1ba0 --- /dev/null +++ "b/python/\320\273\320\265\320\263\320\272\320\270\320\265 \320\262\320\276\320\277\321\200\320\276\321\201\321\213/sort.py" @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +def nums_sort(nums): + if 0 <= len(nums) <= 10000: + for i in range(len(nums) - 1): + for j in range(len(nums) - i - 1): + if nums[j] > nums[j + 1]: + nums[j], nums[j + 1] = nums[j + 1], nums[j] + return nums +num_input = input("Please enter the numbers, there must be spaces between the numbers.: ") +numbers = list(map(int, num_input.split())) +print(nums_sort(numbers)) From 47f9d031fe30c2bb96695d98b2d8a7fb791b4e40 Mon Sep 17 00:00:00 2001 From: aman Date: Thu, 10 Oct 2024 11:21:02 +0500 Subject: [PATCH 09/21] Add code for the task even_odd --- .../even_odd.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/even_odd.py" diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/even_odd.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/even_odd.py" new file mode 100644 index 00000000..0f6dc9c6 --- /dev/null +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/even_odd.py" @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +def even_odd(n): + if n % 2 == 0: + print("Even!") + else: + print("Odd!") +try: + num = int(input("Please enter a number: ")) + even_odd(num) +except ValueError: + print("Invalid input! Please enter a valid number.") \ No newline at end of file From 91914106820ab93281dcf9da071b07d1acb1d036 Mon Sep 17 00:00:00 2001 From: aman Date: Thu, 10 Oct 2024 11:40:00 +0500 Subject: [PATCH 10/21] Add code for task pallindrom --- .../pallindrom.py" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/pallindrom.py" diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/pallindrom.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/pallindrom.py" new file mode 100644 index 00000000..f281d89f --- /dev/null +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/pallindrom.py" @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +def pallindrom(w): + reversed_word = w[::-1] + if not w: # Check for empty string + raise ValueError("Input cannot be empty!") + if w == reversed_word: + print("This word is pallindrom!") + else: + print("This word is not pallindrom!") + +w = input("Please enter a word: ") +pallindrom(w) From b7e04eb8ad087dbb498b43c9399ad724308fcb3a Mon Sep 17 00:00:00 2001 From: aman Date: Fri, 11 Oct 2024 10:39:38 +0500 Subject: [PATCH 11/21] Add code for the task prime --- .../prime.py" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/prime.py" diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/prime.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/prime.py" new file mode 100644 index 00000000..6fbd6b2c --- /dev/null +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/prime.py" @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +import math +def prime_num(n): + if n <= 1: + return "The number isn't prime" + for i in range(2, int(math.sqrt(n)) + 1): + if n % i == 0: + return "The number isn't prime" + + return "The number is prime" + +num = int(input("Please enter a number: ")) +print(prime_num(num)) \ No newline at end of file From d9aa899589d77af0e9a7248ec4b1eefca4714db3 Mon Sep 17 00:00:00 2001 From: aman Date: Sat, 12 Oct 2024 15:28:08 +0500 Subject: [PATCH 12/21] Add code for the task validdate --- .../correctdate.py" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/correctdate.py" diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/correctdate.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/correctdate.py" new file mode 100644 index 00000000..f51da572 --- /dev/null +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/correctdate.py" @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +def leapYear(y): + y = int(y) + + if y % 4 == 0 and y % 100 != 0 or y % 400 == 0: + return True + +def checkdate(d, m, y): + MAX_VALID_YR = 9999; + MIN_VALID_YR = 1800; + y = int(y) + m = int(m) + d = int(d) + if y < int(MIN_VALID_YR) or y > int(MAX_VALID_YR): + return False + if m < 1 or m > 12: + return False + if d < 1 or d > 31: + return False + + if m == 2: + if leapYear(y): + return d <= 29 + else: + return d <= 28 + if m == 4 or m == 6 or m == 9 or m == 11: + return d <= 30 + return True +d, m, y = input("Please enter date in format dd.mm.yyyy: ").split(".") +print(checkdate(d, m, y)) + + \ No newline at end of file From 47d985c2e3a4e19c17afe684d5409ef46440d3c2 Mon Sep 17 00:00:00 2001 From: aman Date: Sat, 12 Oct 2024 16:23:46 +0500 Subject: [PATCH 13/21] Add code for the task perfect number --- .../perfectnum.py" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" new file mode 100644 index 00000000..1ae64b24 --- /dev/null +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +def perfectnum(n): + n = int(n) + sum = 0 + if n <= 0: + return "The number must be greater than 0!" + for i in range(1, n): + if n % i == 0: + sum += i + if sum == n: + return "Perfect number" + else: + return "Not a perfect number" + +num = input("Please enter the number: ") +print(perfectnum(num)) \ No newline at end of file From 64ebcc838c0616f9c9c61a902b1ed7e76fc4cec7 Mon Sep 17 00:00:00 2001 From: aman Date: Sat, 12 Oct 2024 16:26:26 +0500 Subject: [PATCH 14/21] Add changes to file perfectnum --- .../perfectnum.py" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" index 1ae64b24..c9e93434 100644 --- "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" @@ -3,8 +3,8 @@ def perfectnum(n): n = int(n) sum = 0 - if n <= 0: - return "The number must be greater than 0!" + if n <= 0 or n > 1000: + return "The number out of range!" for i in range(1, n): if n % i == 0: sum += i From 7526d3d6ba9a2d694f3c24e604c3192a27f78731 Mon Sep 17 00:00:00 2001 From: aman Date: Sun, 13 Oct 2024 17:27:13 +0500 Subject: [PATCH 15/21] Add code for the task fibonacci --- .../fibonacci.py" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/fibonacci.py" diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/fibonacci.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/fibonacci.py" new file mode 100644 index 00000000..acaa09de --- /dev/null +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/fibonacci.py" @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import math + +def is_perfect_square(x): + s = int(math.sqrt(x)) + + return s * s == x + +def fibnum(n): + + pos_test = 5 * (n ** 2) + 4 + neg_test = 5 * (n ** 2) - 4 + + return is_perfect_square(pos_test) or is_perfect_square(neg_test) + + +num = int(input("Enter a number: ")) +if fibnum(num): + print(f"{num} is a Fibonacci number") +else: + print(f"{num} is not a Fibonacci number") \ No newline at end of file From bbde35a05c07f8747be81d36f9b593168b026a46 Mon Sep 17 00:00:00 2001 From: aman Date: Mon, 14 Oct 2024 09:48:40 +0500 Subject: [PATCH 16/21] add code for the task list of perfect numbers --- .../list_perfectnum.py" | 23 +++++++++++++++++++ .../perfectnum.py" | 2 -- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/list_perfectnum.py" diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/list_perfectnum.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/list_perfectnum.py" new file mode 100644 index 00000000..8b71f47f --- /dev/null +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/list_perfectnum.py" @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +def listperfect(n): + perfect_nums = [6, 28, 496] + s = [] + try: + n = int(n) + if n < 0 or n > 1000: + print("The number is out of range!") + return [] + except ValueError: + print("Invalid input! Please enter a valid number.") + return [] + + + for i in range (1, n): + if i in perfect_nums: + s.append(i) + return s + + +num = input("Please enter the number: ") +print(listperfect(num)) diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" index c9e93434..b5b8dbd7 100644 --- "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/perfectnum.py" @@ -3,8 +3,6 @@ def perfectnum(n): n = int(n) sum = 0 - if n <= 0 or n > 1000: - return "The number out of range!" for i in range(1, n): if n % i == 0: sum += i From bbde7109fe4ea6c1b3a3be95d9380a8b074bf308 Mon Sep 17 00:00:00 2001 From: aman Date: Mon, 14 Oct 2024 11:24:59 +0500 Subject: [PATCH 17/21] Add code for task date season --- .../__pycache__/correctdate.cpython-312.pyc" | Bin 0 -> 1102 bytes .../correctdate.py" | 6 ++--- .../dateseazon.py" | 25 ++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/__pycache__/correctdate.cpython-312.pyc" create mode 100644 "python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/dateseazon.py" diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/__pycache__/correctdate.cpython-312.pyc" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/__pycache__/correctdate.cpython-312.pyc" new file mode 100644 index 0000000000000000000000000000000000000000..4559fc477edc9a880907f0ae9da9399def273a21 GIT binary patch literal 1102 zcmZWp%WD%s7@x`Jv1!t7N@9glHKfmkIF(>c9%9JO~Y(j*^)vU z1*7d@8w87|SUg0$^kA`w^&jxEX)hu4Q1G<3V({Y0?^}~4;K2O$_q}H3d$2#cySoUi z+JPxY+@+@Ndpd?iO~j^%;exhbq#Nb{#F6y z8{$JvWtzB{Nl968Dx;3GMY!K7Mn!ls^g#9Qp<-^uwKM@aXc$VRWP}M8H-WD#8>QV`VSOyuTEG z?J;_d>2e>)IA!tT%5flU#5Zr&!;x**)@Uhl(k2)WcJPvYb|LGpr>RS`z?HIZEj-x0^ Date: Mon, 14 Oct 2024 11:25:49 +0500 Subject: [PATCH 18/21] Add little change in file dateseazon --- .../dateseazon.py" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/dateseazon.py" "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/dateseazon.py" index 7b9b7deb..14665d5d 100644 --- "a/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/dateseazon.py" +++ "b/python/\321\201\321\200\320\265\320\264\320\275\320\270\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/dateseazon.py" @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from correctdate import checkdate -def CheckSeazon(d, m, y): +def CheckSeason(d, m, y): y = int(y) m = int(m) d = int(d) @@ -22,4 +22,4 @@ def CheckSeazon(d, m, y): print("Invalid date!") d, m, y = input("Please enter date in format dd.mm.yyyy: ").split(".") -CheckSeazon(d, m, y) \ No newline at end of file +CheckSeason(d, m, y) \ No newline at end of file From a83f13a5d64be1aeccf224ccd284e35ffcd9c320 Mon Sep 17 00:00:00 2001 From: aman Date: Tue, 15 Oct 2024 10:23:33 +0500 Subject: [PATCH 19/21] add code for the task sum of numbers --- .../SumNum.py" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "python/\321\201\320\273\320\276\320\266\320\275\321\213\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/SumNum.py" diff --git "a/python/\321\201\320\273\320\276\320\266\320\275\321\213\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/SumNum.py" "b/python/\321\201\320\273\320\276\320\266\320\275\321\213\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/SumNum.py" new file mode 100644 index 00000000..90ced2bb --- /dev/null +++ "b/python/\321\201\320\273\320\276\320\266\320\275\321\213\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/SumNum.py" @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 + +def sum_of_range(a, z): + a = int(a) + z = int(z) + n = z - a + 1 + return (n * (a + z)) // 2 + +a, z = input("Please enter the numbers: ").split() +print(sum_of_range(a, z)) \ No newline at end of file From 3329b7968a44cf06d9de086737c732b817b30e99 Mon Sep 17 00:00:00 2001 From: aman Date: Tue, 15 Oct 2024 14:35:26 +0500 Subject: [PATCH 20/21] Add code for the task leapyear --- .../leapyear.py" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "python/\321\201\320\273\320\276\320\266\320\275\321\213\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/leapyear.py" diff --git "a/python/\321\201\320\273\320\276\320\266\320\275\321\213\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/leapyear.py" "b/python/\321\201\320\273\320\276\320\266\320\275\321\213\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/leapyear.py" new file mode 100644 index 00000000..5be99242 --- /dev/null +++ "b/python/\321\201\320\273\320\276\320\266\320\275\321\213\320\265 \320\267\320\260\320\264\320\260\321\207\320\270/leapyear.py" @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +def leapYear(n): + n = int(n) + res = 0 + for i in range(1, n+1): + if i % 4 == 0 and i % 100 != 0 or i % 400 == 0: + res += 1 + return res +num = input("Please enter the number: ") +print(leapYear(num)) \ No newline at end of file From af3bc5f9b1254c06c58a5375150de72d968b41d8 Mon Sep 17 00:00:00 2001 From: aman Date: Sun, 20 Oct 2024 15:23:07 +0500 Subject: [PATCH 21/21] add codes for the task 'fast-api-final' --- .gitignore | 162 ++++++++++++++++++ .../fastapi-final/api-project-final/main.py | 80 +++++++++ .../api-project-final/requirements.txt | Bin 0 -> 1432 bytes .../api-project-final/testapp.py | 39 +++++ python/api/fastapi/api-project/main.py | 8 + 5 files changed, 289 insertions(+) create mode 100644 .gitignore create mode 100644 python/api/fastapi-final/api-project-final/main.py create mode 100644 python/api/fastapi-final/api-project-final/requirements.txt create mode 100644 python/api/fastapi-final/api-project-final/testapp.py create mode 100644 python/api/fastapi/api-project/main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..efa407c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,162 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ \ No newline at end of file diff --git a/python/api/fastapi-final/api-project-final/main.py b/python/api/fastapi-final/api-project-final/main.py new file mode 100644 index 00000000..34a1fbb4 --- /dev/null +++ b/python/api/fastapi-final/api-project-final/main.py @@ -0,0 +1,80 @@ +from fastapi import FastAPI, Header +from fastapi.responses import JSONResponse +from pydantic import BaseModel + +app = FastAPI() + + +@app.get("/sum1n/{n}") +async def read_root(n): + n = int(n) + res = 0 + for i in range(n): + res += i + return {"result": res} + + +@app.get("/fibo") +async def fibnums(n): + n = int(n) + if n <= 0: + return "Please enter the number bigger 0!" + elif n == 1: + return 0 + elif n == 2: + return 1 + else: + a, b = 0, 1 + for _ in range (2, n): + a, b = b, a + b + return JSONResponse(content={"result": b}) + + + +@app.post("/reverse") +async def revers_word(string: str = Header(...)): + return {"result": string[::-1]} + + + +element_list = [] +# Pydantic model +class ElementItem(BaseModel): + element: str + +@app.put("/list/") +async def create_item(item: ElementItem): + element_list.append(item.element) + return {"message": f"Item '{item.element}' updated successfully!"} + +@app.get("/list/") +async def get_list(): + return {"result": element_list} + + + + + +class ElementItem(BaseModel): + expr: str + +@app.post("/calculator/") +async def calc(item: ElementItem): + operands = item.expr.split(",") + num1 = float(operands[0]) + operator = operands[1] + num2 = float(operands[2]) + + match operator: + case "+": + res = num1 + num2 + case "-": + res = num1 - num2 + case "/": + if num2 == 0: + return "Division by zero is not allowed." + res = num1 / num2 + case "*": + res = num1 * num2 + + return { "result": res } \ No newline at end of file diff --git a/python/api/fastapi-final/api-project-final/requirements.txt b/python/api/fastapi-final/api-project-final/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..76fdf49b4f890b867208033b3596c7facd0d4411 GIT binary patch literal 1432 zcmZvcOK;mi41{?u(4QhBlJjT|J@i^MK!BclGF)4>oY<0KNqPMFw%?H2NKOM`BS##P zGsE5e`)6r2Ph*`eS*5Kl3i<#qf14Hjt(nlQF^YFEBAWH4TN~ghjAL=xb&wgFK@jIpH;Aw&Ke!+Kc{X!c)p`^ z>mJm$^*J@x5A`)ktzh{bRkb}(qnK2gp+ns@lM|C$!|xef2D;;~=8<|zPt>{_&^_^= z{NB)ciVDsLs`XUedn}w!u4^Yez%$J`X`0!s^HE<-wuXiFl&VY1t!onF_lOJ*FQB!< z-tYUA8SMYhY{}JxJWQF$rY;TFN&P(dp