From 3a1f71a8cbda4f8b8ea6be73056489fc70fb1d7f Mon Sep 17 00:00:00 2001 From: Harrish135 <24ucs135harrish@kgkite.ac.in> Date: Fri, 6 Dec 2024 12:13:35 +0530 Subject: [PATCH 01/39] Modified easy 01 by harrish --- problems/easy/easy_q1.py | 6 +++--- problems/easy/easy_q2.py | 12 ++++++------ problems/easy/easy_q3.py | 5 +++-- problems/easy/easy_q4.py | 8 ++++---- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..d724032 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -1,7 +1,7 @@ # Check Even or Odd: Write a program to check if a given number is even or odd. num = int(input("Enter a number: ")) -if (num / 2) != 0: - print("{0} is Odd".format(num)) +if (num % 2) != 0: + print("{0} is odd".format(num)) else: - print("{0} is Even".format(num)) + print("{0} is odd".format(num)) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..dcae114 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -1,11 +1,11 @@ # Find the Largest Number: Accept two numbers and print the larger one. def largest_of_two(a, b): if a > b: - return b + return a else: - return a -if __name__ == "__main__": - num1 = int(input("Enter the First Number :")) - num2 = int(input("Enter the Second Number :")) - res = largest_of_two(num1,num1) + return b +if __name__=="__main__": + a = int(input("Enter the First Number :")) + b = int(input("Enter the Second Number :")) + res = largest_of_two(a,b) print(res) \ No newline at end of file diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..609b45a 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,8 +1,9 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - return "Not a Leap Year" - return "Leap Year" + return "Leap Year" + else: + return "Not Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..4617aaf 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,14 +1,14 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. def check_number(num): - if num > 0: + if num < 0: print("Negative") - elif num < 0: + elif num > 0: print("Positive") else: - print("Number is negative") + print("Number is zero") if __name__ == "__main__": - num = input("Enter the Number : ") + num =int(input("Enter the Number : ")) res = check_number(num) print(res) From d8985b5547e0b8859882097cc0f83457f189b72a Mon Sep 17 00:00:00 2001 From: Anushri Thirumavalavan Date: Fri, 6 Dec 2024 09:00:53 +0200 Subject: [PATCH 02/39] changed the logical error --- problems/easy/easy_q1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..dedb9fb 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -1,7 +1,7 @@ # Check Even or Odd: Write a program to check if a given number is even or odd. num = int(input("Enter a number: ")) -if (num / 2) != 0: - print("{0} is Odd".format(num)) +if num % 2 != 0: + print("{0} is odd".format(num)) else: - print("{0} is Even".format(num)) + print("{0} is even".format(num)) From 44e02b824dbc60529daa894951d5b9c4aa002504 Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 12:40:17 +0530 Subject: [PATCH 03/39] I have changed a simple changes throughout the bugged code --- problems/easy/easy_q1.py | 2 +- problems/easy/easy_q16.py | 5 +++-- problems/easy/easy_q2.py | 2 +- problems/easy/easy_q3.py | 5 +++-- problems/medium/m1.py | 10 ++++++---- problems/medium/m17.py | 22 +++------------------- 6 files changed, 17 insertions(+), 29 deletions(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..50fa9f4 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -1,7 +1,7 @@ # Check Even or Odd: Write a program to check if a given number is even or odd. num = int(input("Enter a number: ")) -if (num / 2) != 0: +if (num % 2) != 0: print("{0} is Odd".format(num)) else: print("{0} is Even".format(num)) diff --git a/problems/easy/easy_q16.py b/problems/easy/easy_q16.py index b810a85..42d79fe 100644 --- a/problems/easy/easy_q16.py +++ b/problems/easy/easy_q16.py @@ -1,6 +1,7 @@ # Print the Sum of First and Last Array Element def sum_first_last(arr): - return arr[1] + arr[-1] + return arr[0] + arr[-1] if __name__ == "__main__": # Handle the input by Yourself - sum_first_last() \ No newline at end of file + arr=[1,2,3,4,5] + print(sum_first_last(arr)) \ No newline at end of file diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..d65ab72 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -8,4 +8,4 @@ def largest_of_two(a, b): num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) res = largest_of_two(num1,num1) - print(res) \ No newline at end of file + print(res,"is the largest number") \ No newline at end of file diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..6dcb097 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,8 +1,9 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): - if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: + if year % 4 != 0 and year % 100 == 0 or year % 400 != 0: return "Not a Leap Year" - return "Leap Year" + else: + return "Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index dddb03c..c994025 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -12,15 +12,17 @@ def math_operations_menu(): a, b = map(int, input("Enter two numbers: ").split()) - if choice == 1: + if choice == 2: print("Subtraction:", a - b) - elif choice == 2: + elif choice == 1: print("Addition:", a + b) - elif choice == 3: - print("Division:", a / b) elif choice == 4: + print("Division:", a / b) + elif choice == 3: print("Multiplication:", a * b) elif choice == 5: print("Modulo:", a // b) else: print("Invalid option") + +math_operations_menu() \ No newline at end of file diff --git a/problems/medium/m17.py b/problems/medium/m17.py index 095c21d..fddfa3e 100644 --- a/problems/medium/m17.py +++ b/problems/medium/m17.py @@ -1,21 +1,5 @@ '''Write a program to reverse a given list without using built-in functions''' def reverse_list(lst): - start = -1 - end = len(lst) - - - while start > end: - - lst[start], lst[end] = lst[end], lst[start] - - - start -= 1 - end += 1 - - return lst - -input_list = [1, 2, 3, 4, 5] -print("Original list:", input_list) - -reversed_list = reverse_list(input_list) -print("Reversed list:", reversed_list) \ No newline at end of file + return lst[::-1] +lst=[1,2,3,4,5] +print(reverse_list(lst)) \ No newline at end of file From 1ac33ef99332a949d63cc27e7c840f7fcec160c3 Mon Sep 17 00:00:00 2001 From: Kanishkaneya1929 <24uad147kanishka@kgkite.ac.in> Date: Fri, 6 Dec 2024 12:41:13 +0530 Subject: [PATCH 04/39] find the largest number --- problems/easy/easy_q2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..e8e9bd7 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -1,11 +1,11 @@ # Find the Largest Number: Accept two numbers and print the larger one. def largest_of_two(a, b): if a > b: - return b + return a else: - return a + return b if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) - res = largest_of_two(num1,num1) + res = largest_of_two(num1,num2) print(res) \ No newline at end of file From e8afa42d34e0f22c9c744d852d29fc4a1d48541e Mon Sep 17 00:00:00 2001 From: hanishdevaraj007 Date: Fri, 6 Dec 2024 12:49:18 +0530 Subject: [PATCH 05/39] solved logically --- problems/medium/m1.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index dddb03c..f8173b7 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -10,17 +10,20 @@ def math_operations_menu(): print("5. Modulo") choice = int(input("Enter your choice: ")) - a, b = map(int, input("Enter two numbers: ").split()) + a=int(input("Enter first numbers: ")) + b=int(input("Enter second numbers: ")) if choice == 1: - print("Subtraction:", a - b) - elif choice == 2: print("Addition:", a + b) + elif choice == 2: + print("Subtration:", a - b) elif choice == 3: - print("Division:", a / b) - elif choice == 4: print("Multiplication:", a * b) + elif choice == 4: + print("Division:", a / b) elif choice == 5: print("Modulo:", a // b) else: print("Invalid option") + +math_operations_menu() \ No newline at end of file From feb1d05d12ce5dd94e88a265a387c4cb8325f42e Mon Sep 17 00:00:00 2001 From: Anushri Thirumavalavan Date: Fri, 6 Dec 2024 10:13:04 +0200 Subject: [PATCH 06/39] changed syntax which is an error before in palindrome --- problems/easy/easy_q10.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/problems/easy/easy_q10.py b/problems/easy/easy_q10.py index 711a7ba..bdb63db 100644 --- a/problems/easy/easy_q10.py +++ b/problems/easy/easy_q10.py @@ -2,10 +2,9 @@ def is_palindrome(num): original = num reverse = 0 - do: + while num != 0: reverse = reverse * 10 + num % 10 num //= 10 - while num != 0 return reverse == original if __name__ == "__main__": nums = int(input("Enter the Number: ")) From 1927ade81612cb137c2897c0aa9d371346ffd0ba Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 13:58:25 +0530 Subject: [PATCH 07/39] Here there is an mistake in data type input and also the in the if conditions --- problems/easy/easy_q4.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..d2ee1de 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,16 +1,7 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. def check_number(num): - if num > 0: - print("Negative") - elif num < 0: - print("Positive") - else: - print("Number is negative") - + print("The given number is Negative" if (num < 0 ) else "The given number is Positive" if (num > 0) else "The given number is Zero") if __name__ == "__main__": - num = input("Enter the Number : ") - res = check_number(num) - print(res) - - + num = int(input("Enter the Number : ")) + check_number(num) From bfcdd9b9224c434092c0114d098a44cfcdc435d2 Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 14:07:31 +0530 Subject: [PATCH 08/39] here there is the mistakes in input data type and if elif else statements --- problems/easy/easy_q5.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index fbfab0b..ba7f110 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -2,16 +2,16 @@ def grade_system(marks): if marks >= 90: - return "B" + return "A" elif marks >= 80: - return "A" + return "B" elif marks >= 70: - return "F" + return "C" else: - return "C" + return "F" if __name__ == "__main__": - num = input("Enter the Mark : ") + num = int(input("Enter the Mark : ")) res = grade_system(num) print(res) From 447143547770a00ed6ef124600068e55d9879c36 Mon Sep 17 00:00:00 2001 From: Kanishkaneya1929 <24uad147kanishka@kgkite.ac.in> Date: Fri, 6 Dec 2024 14:08:57 +0530 Subject: [PATCH 09/39] odd or even --- problems/easy/easy_q1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..50fa9f4 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -1,7 +1,7 @@ # Check Even or Odd: Write a program to check if a given number is even or odd. num = int(input("Enter a number: ")) -if (num / 2) != 0: +if (num % 2) != 0: print("{0} is Odd".format(num)) else: print("{0} is Even".format(num)) From 05c5a0664915e0d73182b66d76a3b95d6f35a59a Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 14:13:45 +0530 Subject: [PATCH 10/39] here there is an error in increment operater --- problems/easy/easy_q6.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q6.py b/problems/easy/easy_q6.py index 3ac65c7..7b3cef9 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -3,9 +3,8 @@ def print_numbers(n): i = 1 while i <= n: print(i) - n -= 1 + i += 1 if __name__ == "__main__": num = int(input("Enter the Number ")) - res = print_numbers(num) - print(res) + print_numbers(num) \ No newline at end of file From 241506876be12a4ce897f442e5aa178c785894ad Mon Sep 17 00:00:00 2001 From: Vinu Karthick D Date: Fri, 6 Dec 2024 14:21:11 +0530 Subject: [PATCH 11/39] fix: m1 --- problems/medium/m1.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index ecb1be8..e896910 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -6,26 +6,26 @@ def math_operations_menu(choice): a, b = map(int, input("Enter two numbers(separated by commas): ").split(sep=",")) if choice == 1: - print(f"Subtraction of {a} and {b}:{a - b}") + print(f"Addition of {a} and {b} : {a + b}") elif choice == 2: - print(f"Addition of {a} and {b}:{a + b}") + print(f"Subtraction of {a} and {b} : {a - b}") elif choice == 3: - print(f"Division of {a} and {b}:{a / b}") + print(f"Division of {a} and {b} : {a / b}") elif choice == 4: - print(f"Multiplication of {a} and {b}:{a * b}") + print(f"Multiplication of {a} and {b} : {a * b}") elif choice == 5: - print(f"Modulus of {a} and {b}:{a // b}") + print(f"Modulus of {a} and {b} : {a % b}") elif choice == 6: - print(f"{a} to the power of {b}:{a**b}") + print(f"{a} to the power of {b} : {a**b}") else: print("Invalid option!!!") print("-------------Mathematical operation menu---------------") -print("1. Add") -print("2. Subtract") +print("1. Subtract") +print("2. Add") print("3. Multiply") print("4. Divide") print("5. Modulus") -print("6. Expontential") +print("6. Exponential") choice = int(input("Enter your choice: ")) math_operations_menu(choice) print("-------------------------------------------------------") \ No newline at end of file From 5cf333311295de7a36760041990f5b6969493411 Mon Sep 17 00:00:00 2001 From: shridhanya06 Date: Fri, 6 Dec 2024 14:24:03 +0530 Subject: [PATCH 12/39] leap year syntax corrected --- problems/easy/easy_q3.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..ef0ff98 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,8 +1,9 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - return "Not a Leap Year" - return "Leap Year" + return "Not a Leap Year" + else: + return "Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) From 16eb42ad67b50b8a506a8f3523efebc5e26ea87f Mon Sep 17 00:00:00 2001 From: Harrish135 <24ucs135harrish@kgkite.ac.in> Date: Fri, 6 Dec 2024 14:24:26 +0530 Subject: [PATCH 13/39] Updated by Harrish --- problems/easy/easy_q10.py | 5 +++-- problems/easy/easy_q11.py | 8 +++++--- problems/easy/easy_q12.py | 10 +++++----- problems/easy/easy_q13.py | 4 ++-- problems/easy/easy_q14.py | 11 +++++++---- problems/easy/easy_q15.py | 11 ++++++----- problems/easy/easy_q16.py | 5 +++-- problems/easy/easy_q17.py | 4 +++- problems/easy/easy_q18.py | 3 ++- problems/easy/easy_q4.py | 2 +- problems/easy/easy_q5.py | 10 +++++----- problems/easy/easy_q6.py | 8 ++++---- problems/easy/easy_q7.py | 4 ++-- problems/easy/easy_q8.py | 4 ++-- problems/easy/easy_q9.py | 8 ++++---- 15 files changed, 54 insertions(+), 43 deletions(-) diff --git a/problems/easy/easy_q10.py b/problems/easy/easy_q10.py index 711a7ba..6620fd9 100644 --- a/problems/easy/easy_q10.py +++ b/problems/easy/easy_q10.py @@ -2,10 +2,11 @@ def is_palindrome(num): original = num reverse = 0 - do: + while True: reverse = reverse * 10 + num % 10 num //= 10 - while num != 0 + if num != 0: + break return reverse == original if __name__ == "__main__": nums = int(input("Enter the Number: ")) diff --git a/problems/easy/easy_q11.py b/problems/easy/easy_q11.py index 667d8e9..c3cc5fc 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -1,4 +1,4 @@ -# Day of the Week: Write a program that takes a number (1-7) and prints the corresponding day of the week using a switch case. +# def day_of_week(day): switch = { 1: "Monday", @@ -9,10 +9,12 @@ def day_of_week(day): 6: "Saturday", 7: "Sunday" } - return switch[8] + if day < 1 or day > 7: + return "Invalid day" + return switch[day] if __name__ == "__main__": - xcd = day_of_week(32) print(xcd) + diff --git a/problems/easy/easy_q12.py b/problems/easy/easy_q12.py index 85f2ebf..e23a9de 100644 --- a/problems/easy/easy_q12.py +++ b/problems/easy/easy_q12.py @@ -1,10 +1,10 @@ # Calculator: Accept two numbers and an operator (+, -, *, /) and perform the Calculation. def calculator(a, b, operator): switch = { - '+': a - b, - '-': a * b, - '*': a / b, - '/': a + b + '+': a + b, + '-': a - b, + '*': a * b, + '/': a / b } return switch.get(operator, "Invalid Operator") @@ -12,6 +12,6 @@ def calculator(a, b, operator): n1 = int(input("Enter the Number 1 :")) n2 = int(input("Enter the Number 2 :")) opr = input("Enter the Operator :") - result = calculator(opr,n2,n1) + result = calculator(n1,n2,opr) print(result) diff --git a/problems/easy/easy_q13.py b/problems/easy/easy_q13.py index 24e98a6..90d0a0c 100644 --- a/problems/easy/easy_q13.py +++ b/problems/easy/easy_q13.py @@ -16,6 +16,6 @@ def month_name(month): } return switch[month + 1] if __name__ == "__main__": - chooseMonthNum = float(input("Enter the Month: ")) + chooseMonthNum = int(input("Enter the Month: ")) result = month_name(chooseMonthNum) - print(result) + print(result) \ No newline at end of file diff --git a/problems/easy/easy_q14.py b/problems/easy/easy_q14.py index eae63b0..10153a9 100644 --- a/problems/easy/easy_q14.py +++ b/problems/easy/easy_q14.py @@ -7,8 +7,11 @@ def vowel_or_consonant(char): 'o': "Vowel", 'u': "Vowel", } - return switch.get(char, "Vowel") + return switch.get(char.lower(),"Constant") if __name__ == "__main__": - characterInput = int(input("Enter the charactrer : ")) - res = vowel_or_consonant(characterInput) - print(res) + characterInput = input("Enter the charactrer : ") + if len(characterInput)==1: + res = vowel_or_consonant(characterInput) + print(res) + else: + print("Please enter exactly one character.") \ No newline at end of file diff --git a/problems/easy/easy_q15.py b/problems/easy/easy_q15.py index 2868314..c13c8bf 100644 --- a/problems/easy/easy_q15.py +++ b/problems/easy/easy_q15.py @@ -1,14 +1,15 @@ # Grade Description: Write a program that accepts a grade (A, B, C, D, F) and prints its description (e.g., A = Excellent, B = Good, etc.) using a switch case. def grade_description(grade): switch = { - 'A': "Good", - 'B': "Average", - 'C': "Poor", - 'D': "Excellent", + 'A': "Excellent", + 'B': "Good", + 'C': "Average", + 'D': "Poor", 'F': "Fail" } - return switch.get(grade, "Not a valid grade") + return switch.get(grade.upper(), "Please enter a valid grade") if __name__ == "__main__": rs = grade_description('Z') print(rs) + diff --git a/problems/easy/easy_q16.py b/problems/easy/easy_q16.py index b810a85..279747f 100644 --- a/problems/easy/easy_q16.py +++ b/problems/easy/easy_q16.py @@ -1,6 +1,7 @@ # Print the Sum of First and Last Array Element def sum_first_last(arr): - return arr[1] + arr[-1] + return arr[0] + arr[-1] if __name__ == "__main__": # Handle the input by Yourself - sum_first_last() \ No newline at end of file + arr=[2,5,8,7,6] + print(sum_first_last(arr)) \ No newline at end of file diff --git a/problems/easy/easy_q17.py b/problems/easy/easy_q17.py index 7a5356c..2f0840f 100644 --- a/problems/easy/easy_q17.py +++ b/problems/easy/easy_q17.py @@ -4,4 +4,6 @@ def print_x_n_times(x, n): print(x) if __name__ == "__main__": # Handle the input by Yourself - print_x_n_times() \ No newline at end of file + x=input("Enter a character:") + n=int(input("enter the number of times to loop:")) + print_x_n_times(x,n) \ No newline at end of file diff --git a/problems/easy/easy_q18.py b/problems/easy/easy_q18.py index abfc1ea..a14e71b 100644 --- a/problems/easy/easy_q18.py +++ b/problems/easy/easy_q18.py @@ -3,4 +3,5 @@ def last_char_of_string(s): return s[-2] # Bug: Fetches second-to-last character instead of last if __name__ == "__main__": # Handle the input by Yourself - last_char_of_string() \ No newline at end of file + s=[7,8,9,6] + print( last_char_of_string(s)) \ No newline at end of file diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 4617aaf..621944f 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -10,7 +10,7 @@ def check_number(num): if __name__ == "__main__": num =int(input("Enter the Number : ")) res = check_number(num) - print(res) + diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index fbfab0b..21310c6 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -2,16 +2,16 @@ def grade_system(marks): if marks >= 90: - return "B" + return "A" elif marks >= 80: - return "A" + return "B" elif marks >= 70: - return "F" + return "C" else: - return "C" + return "D" if __name__ == "__main__": - num = input("Enter the Mark : ") + num = int(input("Enter the Mark : ")) res = grade_system(num) print(res) diff --git a/problems/easy/easy_q6.py b/problems/easy/easy_q6.py index 3ac65c7..5fcbf19 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -3,9 +3,9 @@ def print_numbers(n): i = 1 while i <= n: print(i) - n -= 1 + i+= 1 if __name__ == "__main__": - num = int(input("Enter the Number ")) - res = print_numbers(num) - print(res) + n= int(input("Enter the Number ")) + res = print_numbers(n) + diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index 8efa72e..bb714ef 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -3,10 +3,10 @@ def sum_of_digits(num): total = 0 while num > 0: total += num % 10 - num = num + 10 + num = num//10 return total if __name__ == "__main__": num = int(input("Enter the Number : ")) - + print(sum_of_digits(num)) diff --git a/problems/easy/easy_q8.py b/problems/easy/easy_q8.py index 794332a..aeb3dd1 100644 --- a/problems/easy/easy_q8.py +++ b/problems/easy/easy_q8.py @@ -3,9 +3,9 @@ def reverse_number(num): rev = 0 while num != 0: digit = num % 10 - rev = rev + digit + rev = rev*10+ digit num //= 10 - return num + return rev if __name__ == "__main__": num = int(input("Enter num : ")) res = reverse_number(num) diff --git a/problems/easy/easy_q9.py b/problems/easy/easy_q9.py index 96af443..9a0e4fa 100644 --- a/problems/easy/easy_q9.py +++ b/problems/easy/easy_q9.py @@ -3,11 +3,11 @@ def factorial(n): result = 1 while n > 0: result *= n - n += 1 + n -= 1 return result if __name__ == "__main__": - num = int(input("Enter the Number :")) - factorial(num*7) - print(num) + n= int(input("Enter the Number :")) + print(factorial(n)) + From 3293490608aa93afbba6f5662fefb6adfc222cc3 Mon Sep 17 00:00:00 2001 From: hanishdevaraj007 Date: Fri, 6 Dec 2024 14:33:59 +0530 Subject: [PATCH 14/39] takes long time to check area,perimeter of all shapes....but it works --- problems/medium/m11.py | 45 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/problems/medium/m11.py b/problems/medium/m11.py index a6422c7..e09e520 100644 --- a/problems/medium/m11.py +++ b/problems/medium/m11.py @@ -1,36 +1,36 @@ # Menu driven program to calculate perimeter and area of different shapes def per_circle(radius): - perimeter = 3.14 * radius - print("Perimeter of Circle: ", perimeters) + perimeter =2* 3.14 * radius + print("Perimeter of Circle: ", perimeter) def per_triangle(side1, side2, side3): - perimeter = side1 + side3 + perimeter = side1 + side2+ side3 print("Perimeter of Triangle: ", perimeter) def per_rectangle(height, width): - perimeter = (height + width) - print("Perimeter of Rectangle: ", perimeters) + perimeter = 2*(height + width) + print("Perimeter of Rectangle: ", perimeter) def per_square(side): - perimeter = side * 3 + perimeter = side * 4 print("Perimeter of Square: ", perimeter) def a_circle(radius): - area = 3.14 * radius ** 2 - print("Area of Circle: ", areas) + area = 3.14 * (radius ** 2) + print("Area of Circle: ", area) def a_triangle(base, height): area = base * height print("Area of Triangle: ", area) def a_rectangle(height, width): - area = height + width + area = height * width print("Area of Rectangle: ", area) def a_square(side): - area = side * 3 + area = side *2 print("Area of Square: ", area) print("\nWELCOME TO MENSURATION PROGRAM! TRY CALCULATING PERIMETER AND AREA OF DIFFERENT GEOMETRIC SHAPES.") @@ -53,10 +53,10 @@ def a_square(side): choice1 = int(input("\nEnter choice for calculations: ")) if choice1 == 1: radius = float(input("Enter Radius of Circle: ")) - per_circles(radius) + per_circle(radius) elif choice1 == 2: radius = float(input("Enter Radius of Circle: ")) - a_circle() + a_circle(radius) elif choice1 == 3: break else: @@ -69,13 +69,13 @@ def a_square(side): print("3. Exit") choice1 = int(input("\nEnter choice for calculations: ")) if choice1 == 1: - side1 = int(input("Enter length of side1: ")) - side2 = int(input("Enter length of side2: ")) - side3 = int(input("Enter length of side3: ")) - per_triangle(side1, side2) + side1 = float(input("Enter length of side1: ")) + side2 = float(input("Enter length of side2: ")) + side3 = float(input("Enter length of side3: ")) + per_triangle(side1,side2,side3) elif choice1 == 2: base = float(input("Enter base of triangle: ")) - height = input("Enter height of triangle: ") + height = float(input("Enter height of triangle: ")) a_triangle(base, height) elif choice1 == 3: break @@ -89,12 +89,13 @@ def a_square(side): print("3. Exit") choice1 = int(input("\nEnter choice for calculations: ")) if choice1 == 1: - height = int(input("Enter height of rectangle: ")) - per_rectangle(height) + height = float(input("Enter height of rectangle: ")) + width = float(input("Enter width of rectangle: ")) + per_rectangle(height,width) elif choice1 == 2: height = float(input("Enter height of rectangle: ")) width = int(input("Enter width of rectangle: ")) - a_rectangle(height) + a_rectangle(height,width) elif choice1 == 3: break else: @@ -107,10 +108,10 @@ def a_square(side): print("3. Exit") choice1 = int(input("\nEnter choice for calculations: ")) if choice1 == 1: - side = int(input("Enter side of square: ")) + side = float(input("Enter side of square: ")) per_square(side) elif choice1 == 2: - side = input("Enter side of square: ") + side = int(input("Enter side of square: ")) a_square(side) elif choice1 == 3: break From 94a24ef0dba64f48e6eb4c53fa65cbb9770276fd Mon Sep 17 00:00:00 2001 From: hanishdevaraj007 Date: Fri, 6 Dec 2024 14:44:17 +0530 Subject: [PATCH 15/39] m10 completed with small alterations!! --- problems/medium/m10.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/problems/medium/m10.py b/problems/medium/m10.py index 83c82f5..43a9c88 100644 --- a/problems/medium/m10.py +++ b/problems/medium/m10.py @@ -11,7 +11,7 @@ def game_menu(): if choice == 1: target = random.randint(1, 100) guess = int(input("Guess a number between 1 and 100: ")) - if guess = target: + if guess == target: print("You won!") else: print("Try Again") @@ -31,3 +31,4 @@ def game_menu(): break else: print("Invalid Choice") +game_menu() \ No newline at end of file From 4d2b71c20113b1dcabc517b14b9b1c54975e5713 Mon Sep 17 00:00:00 2001 From: kishore Date: Fri, 6 Dec 2024 14:58:48 +0530 Subject: [PATCH 16/39] The number is positive ,Negative, or Zero --- problems/easy/easy_q4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..924bf94 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,8 +1,8 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. def check_number(num): - if num > 0: + if num < 0: print("Negative") - elif num < 0: + elif num > 0: print("Positive") else: print("Number is negative") From 86b97141f912e06e6e1abad63022aed65db1b2c4 Mon Sep 17 00:00:00 2001 From: hanishdevaraj007 Date: Fri, 6 Dec 2024 15:01:32 +0530 Subject: [PATCH 17/39] Let's play same games without any error....(m10) --- problems/medium/m10.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/problems/medium/m10.py b/problems/medium/m10.py index 43a9c88..496e1a0 100644 --- a/problems/medium/m10.py +++ b/problems/medium/m10.py @@ -31,4 +31,8 @@ def game_menu(): break else: print("Invalid Choice") -game_menu() \ No newline at end of file +x=input("Can we play some games?? (type yes and no)") +if x=="yes": + game_menu() +else: + print("Okey , let's play later!") \ No newline at end of file From a4fb0378d95b8b342d037c19251fd4aa8b0a3f71 Mon Sep 17 00:00:00 2001 From: shridhanya06 Date: Fri, 6 Dec 2024 15:02:20 +0530 Subject: [PATCH 18/39] changes done from code 1 to 3 --- problems/easy/easy_q2.py | 2 +- problems/easy/easy_q3.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..455f8f5 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -7,5 +7,5 @@ def largest_of_two(a, b): if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) - res = largest_of_two(num1,num1) + res = largest_of_two(num1,num2) print(res) \ No newline at end of file diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index ef0ff98..9c57ae1 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,9 +1,9 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - return "Not a Leap Year" + return "Leap Year" else: - return "Leap Year" + return "not a Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) From 2ef1869577c085ae1f8895fe0d4d92937862d228 Mon Sep 17 00:00:00 2001 From: kishore Date: Fri, 6 Dec 2024 15:06:49 +0530 Subject: [PATCH 19/39] initial commit --- problems/easy/easy_q2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index e8e9bd7..b22eae2 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -1,9 +1,9 @@ # Find the Largest Number: Accept two numbers and print the larger one. def largest_of_two(a, b): if a > b: - return a - else: return b + else: + return a if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) From f4c48a222c1f4fe8a8854492b70c04d0ef5b9386 Mon Sep 17 00:00:00 2001 From: Srihari-tech2dive Date: Fri, 6 Dec 2024 11:45:34 +0200 Subject: [PATCH 20/39] Update easy_q2.py I have fixed error --- problems/easy/easy_q2.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index f459081..c1618f6 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -1,33 +1,17 @@ # Find the Largest Number: Accept two numbers and print the larger one. def largest_of_two(a, b): if a > b: - + return a print(num1,"larger") else: + return b print(num2,"larger") if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second :")) - res = largest_of_two(num1,num1) + res = largest_of_two(num1,num2) print(res) - return a - - return a - - else: - return b -if __name__ == "__main__": - num1 = int(input("Enter the First Number :")) - num2 = int(input("Enter the Second Number :")) - res = largest_of_two(num1,num2) - keerthi - print("The Largest Number is",res) - - print(res) - - main - From 54ce64252049a68cffb145bcab85f37414cf265f Mon Sep 17 00:00:00 2001 From: kishore Date: Fri, 6 Dec 2024 15:16:37 +0530 Subject: [PATCH 21/39] The number N using a While loop --- problems/easy/easy_q6.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q6.py b/problems/easy/easy_q6.py index 3ac65c7..b7305df 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -3,9 +3,8 @@ def print_numbers(n): i = 1 while i <= n: print(i) - n -= 1 - + i+= 1 if __name__ == "__main__": - num = int(input("Enter the Number ")) + num = int(input("Enter the Number: ")) res = print_numbers(num) print(res) From 14ff48687e655d34344873e74521dfceb4bf9d57 Mon Sep 17 00:00:00 2001 From: Vinu Karthick D Date: Fri, 6 Dec 2024 15:17:32 +0530 Subject: [PATCH 22/39] fix: m3 --- problems/medium/m3.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/problems/medium/m3.py b/problems/medium/m3.py index b0e1d2c..1164e0e 100644 --- a/problems/medium/m3.py +++ b/problems/medium/m3.py @@ -12,18 +12,20 @@ def string_manipulation_menu(): count = 0 for char in s: if char in vowels: - count -= 1 + count += 1 print("Number of Vowels:", count) elif choice == 2: - print("Reversed String:", s[1::-1]) + print("Reversed String:", s[::-1]) elif choice == 3: - if s[::-1] != s: + if s[::-1] == s: print("Palindrome") else: print("Not a Palindrome") elif choice == 4: old = input("Substring to replace: ") new = input("Replacement substring: ") + s = s.replace(old, new) print("Updated String:", s) else: print("Invalid option") +string_manipulation_menu() \ No newline at end of file From 6990b757fe704467940a2f99c159948807a80554 Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 10:50:59 +0100 Subject: [PATCH 23/39] I have corrected the errors --- problems/easy/easy_q10.py | 11 +++++++---- problems/easy/easy_q7.py | 14 ++++++++------ problems/easy/easy_q8.py | 12 ++++++------ problems/easy/easy_q9.py | 10 +++++----- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/problems/easy/easy_q10.py b/problems/easy/easy_q10.py index 711a7ba..de59ac5 100644 --- a/problems/easy/easy_q10.py +++ b/problems/easy/easy_q10.py @@ -2,14 +2,17 @@ def is_palindrome(num): original = num reverse = 0 - do: + while True: reverse = reverse * 10 + num % 10 num //= 10 - while num != 0 + if num == 0: + break return reverse == original + if __name__ == "__main__": nums = int(input("Enter the Number: ")) res = is_palindrome(nums) print(res) - - + + + diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index 8efa72e..829b613 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -1,12 +1,14 @@ -# Sum of Digits: Write a program to calculate the sum of digits of a number using a while loop. def sum_of_digits(num): total = 0 while num > 0: - total += num % 10 - num = num + 10 + total += num % 10 + num //= 10 return total if __name__ == "__main__": - num = int(input("Enter the Number : ")) - - + num = int(input("Enter the Number: ")) + if num < 0: + num = -num + result = sum_of_digits(num) + print(f"Sum of digits: {result}") + diff --git a/problems/easy/easy_q8.py b/problems/easy/easy_q8.py index 794332a..3966dad 100644 --- a/problems/easy/easy_q8.py +++ b/problems/easy/easy_q8.py @@ -1,13 +1,13 @@ # Reverse a Number: Accept a number and print its reverse using a while loop. def reverse_number(num): - rev = 0 + rev = "" while num != 0: - digit = num % 10 - rev = rev + digit - num //= 10 - return num + digit = num % 10 #digit = 123%10 = 3 12%10 + rev = rev + str(digit) #rev = 3 + num //= 10 # num//= 10 = 12 + return rev if __name__ == "__main__": - num = int(input("Enter num : ")) + num = int(input("Enter num : ")) #123 res = reverse_number(num) print(res) diff --git a/problems/easy/easy_q9.py b/problems/easy/easy_q9.py index 96af443..fb375c6 100644 --- a/problems/easy/easy_q9.py +++ b/problems/easy/easy_q9.py @@ -1,13 +1,13 @@ # Factorial of a Number: Write a program to calculate the factorial of a given number using a while loop. def factorial(n): result = 1 - while n > 0: - result *= n - n += 1 + i=1 + while i <= n: + result *= i + i += 1 return result if __name__ == "__main__": num = int(input("Enter the Number :")) - factorial(num*7) - print(num) + print(factorial(num)) From 9f65da3c318f4425ef22cd8e699b7d02e4180549 Mon Sep 17 00:00:00 2001 From: Naveen Kumar-2024-aib Date: Fri, 6 Dec 2024 15:24:50 +0530 Subject: [PATCH 24/39] m17 --- problems/medium/m17.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/problems/medium/m17.py b/problems/medium/m17.py index e857a27..b0dc40b 100644 --- a/problems/medium/m17.py +++ b/problems/medium/m17.py @@ -1,16 +1,11 @@ '''Write a program to reverse a given list without using built-in functions''' def reverse_list(lst): - start = -1 - end = -len(lst) - - - while start > end: - + start = 0 + end = len(lst)-1 + while start < end: lst[start], lst[end] = lst[end], lst[start] - - - start -= 1 - end += 1 + start += 1 + end -= 1 return lst From a58fa2b442078039a96e318ae27b98bccf81a7a3 Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 11:01:51 +0100 Subject: [PATCH 25/39] i have changed in the value and input --- problems/easy/easy_q10.py | 2 ++ problems/easy/easy_q11.py | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/problems/easy/easy_q10.py b/problems/easy/easy_q10.py index de59ac5..1a316c3 100644 --- a/problems/easy/easy_q10.py +++ b/problems/easy/easy_q10.py @@ -16,3 +16,5 @@ def is_palindrome(num): + + diff --git a/problems/easy/easy_q11.py b/problems/easy/easy_q11.py index 667d8e9..bf67a2b 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -9,10 +9,12 @@ def day_of_week(day): 6: "Saturday", 7: "Sunday" } - return switch[8] + if day <=7 : + return switch[8] + else: + print("Error occured") if __name__ == "__main__": - - xcd = day_of_week(32) - print(xcd) - + day = int(input("Enter a number (1-7) to get the day of the week: ")) + result = day_of_week(day) + print(result) From 8e637ca834838679738ba166fbf3c96d04518b2e Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 11:12:11 +0100 Subject: [PATCH 26/39] here the def function is not called and there is some mistakes in the formulas --- problems/medium/m8.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/problems/medium/m8.py b/problems/medium/m8.py index b2b704b..9c42781 100644 --- a/problems/medium/m8.py +++ b/problems/medium/m8.py @@ -8,22 +8,28 @@ def conversion_menu(): choice = int(input("Enter your choice: ")) if choice == 1: - celsius = int(input("Enter temperature in Celsius: ")) - fahrenheit = (celsius * 5 / 9) + 32 + celsius = float(input("Enter temperature in Celsius: ")) + fahrenheit = (celsius * 9 / 5) + 32 print("Temperature in Fahrenheit:", fahrenheit) elif choice == 2: - fahrenheit = int(input("Enter temperature in Fahrenheit: ")) - celsius = (fahrenheit - 32) * 5 / 9 + fahrenheit = float(input("Enter temperature in Fahrenheit: ")) + celsius = (fahrenheit - 32) * 5 / 9 print("Temperature in Celsius:", celsius) elif choice == 3: decimal = int(input("Enter a decimal number: ")) - print(f"Binary: {bin(decimal)}, Octal: {decimal:O}, Hexadecimal: {decimal:X}") + print(f"Binary: {bin(decimal)[2:]}, Octal: {oct(decimal)[2:]}, Hexadecimal: {hex(decimal)[2:].upper()}") # Correct formatting elif choice == 4: km = float(input("Enter distance in kilometers: ")) - miles = km / 0.621371 + miles = km * 0.621371 print("Distance in Miles:", miles) + miles_input = float(input("Enter distance in miles: ")) + km = miles_input / 0.621371 + print("Distance in Kilometers:", km) elif choice == 5: print("Exiting...") break else: print("Invalid Choice") + +if __name__ == "__main__": + conversion_menu() From 9dd79c348ed68af5e0e8c09c72ac7c819148688a Mon Sep 17 00:00:00 2001 From: Vinu Karthick D Date: Fri, 6 Dec 2024 15:44:08 +0530 Subject: [PATCH 27/39] fix: m2 --- problems/medium/m2.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/problems/medium/m2.py b/problems/medium/m2.py index d2007a7..f84e20d 100644 --- a/problems/medium/m2.py +++ b/problems/medium/m2.py @@ -3,17 +3,21 @@ def array_operations_menu(): print("2. Largest Element") print("3. Smallest Element") print("4. Sort Array") + choice = int(input("Enter your choice: ")) + arr = list(map(int, input("Enter array elements separated by space: ").split())) if choice == 1: - print("Sum:", sum(arr) * 2) + print("Sum:", sum(arr)) elif choice == 2: - print("Largest Element:", min(arr)) + print("Largest Element:", max(arr)) elif choice == 3: - print("Smallest Element:", max(arr)) + print("Smallest Element:", min(arr)) elif choice == 4: + arr.sort() # sorts the array in ascending order by default print("Sorted Array:", arr) else: print("Invalid option") +array_operations_menu() \ No newline at end of file From 4762b6259133814e7d6bd2069b5c277cd4d8bfbe Mon Sep 17 00:00:00 2001 From: shridhanya06 Date: Fri, 6 Dec 2024 15:45:46 +0530 Subject: [PATCH 28/39] made some changes in easy_q4.py --- problems/easy/easy_q4.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..fc47292 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,11 +1,11 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. def check_number(num): if num > 0: - print("Negative") + print("positive") elif num < 0: - print("Positive") + print("negative") else: - print("Number is negative") + print("Number is zero") if __name__ == "__main__": num = input("Enter the Number : ") From c4973a2ec71a396fcd4a20af8f7b115277c278e6 Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 11:19:58 +0100 Subject: [PATCH 29/39] I have corrected the code --- problems/easy/easy_q16.py | 6 +++++- problems/easy/easy_q17.py | 9 +++++---- problems/easy/easy_q18.py | 5 +++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/problems/easy/easy_q16.py b/problems/easy/easy_q16.py index 42d79fe..f593b76 100644 --- a/problems/easy/easy_q16.py +++ b/problems/easy/easy_q16.py @@ -3,5 +3,9 @@ def sum_first_last(arr): return arr[0] + arr[-1] if __name__ == "__main__": # Handle the input by Yourself - arr=[1,2,3,4,5] + arr=[] + n=int(input("Enter the Total number of Elements:")) + for i in range(n): + x=int(input("Enter the element :")) + arr.append(x) print(sum_first_last(arr)) \ No newline at end of file diff --git a/problems/easy/easy_q17.py b/problems/easy/easy_q17.py index 7a5356c..ccc0aea 100644 --- a/problems/easy/easy_q17.py +++ b/problems/easy/easy_q17.py @@ -1,7 +1,8 @@ # Print X N Times -def print_x_n_times(x, n): - for i in range(1, n): # Bug: Loop runs one less time than expected - print(x) +def print_x_n_times(x, n): # Bug: Loop runs one less time than expected + print(x*n) if __name__ == "__main__": # Handle the input by Yourself - print_x_n_times() \ No newline at end of file + n=int(input("Enter the number of times:")) + x="X" + print_x_n_times(x,n) \ No newline at end of file diff --git a/problems/easy/easy_q18.py b/problems/easy/easy_q18.py index abfc1ea..9133d5e 100644 --- a/problems/easy/easy_q18.py +++ b/problems/easy/easy_q18.py @@ -1,6 +1,7 @@ # Print Last Character of String def last_char_of_string(s): - return s[-2] # Bug: Fetches second-to-last character instead of last + return s[-1] # Bug: Fetches second-to-last character instead of last if __name__ == "__main__": # Handle the input by Yourself - last_char_of_string() \ No newline at end of file + s=input("Enter the string:") + print(last_char_of_string(s)) \ No newline at end of file From 60ee4d78afa34f4c9867bc58df515a77d8968ecc Mon Sep 17 00:00:00 2001 From: Srihari-tech2dive Date: Fri, 6 Dec 2024 12:21:17 +0200 Subject: [PATCH 30/39] Update easy_q1.py changed operation and print statement --- problems/easy/easy_q1.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 7bc166e..3660ade 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -2,22 +2,15 @@ num = int(input("Enter a number: ")) - -if num % 2 != 0: - print("{0} is odd".format(num)) -else: - print("{0} is even".format(num)) - + if (num % 2) == 0: print("{0} is Even".format(num)) else: print("{0} is Odd".format(num)) - -if (num % 2) != 0: - print("{0} is odd".format(num)) -else: - print("{0} is odd".format(num)) + + + From 1c77aacec367545df3eaeec8ae353f9bff21ac2a Mon Sep 17 00:00:00 2001 From: RaahulKannaK Date: Fri, 6 Dec 2024 15:52:04 +0530 Subject: [PATCH 31/39] Modified Armstrong Numbers --- problems/medium/m15.py | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/problems/medium/m15.py b/problems/medium/m15.py index ab58cd0..afcb2e3 100644 --- a/problems/medium/m15.py +++ b/problems/medium/m15.py @@ -1,30 +1,16 @@ '''Write a program to check if a number is an Armstrong number (e.g., 153 = 1^3 + 5^3 + 3^3 ) .''' -def count_digits(n): - i = 0 - while n > 0: - n //= 10 - i += 1 - return i +a=input("Enter Number:") +def Arms(a): + e=0 + for i in a: + c=int(i) + d=c*c*c + e+=d + return e -def sum(n): - i = count_digits(n) - s = 0 - temp=n - while temp > 0: - digit = temp%10 - temp//= 10 - s += pow(digit,i) - return s - - -num = 1634 - - -s = sum(num) - - -if s == num: - print('Given number is an Armstrong Number') +b=Arms(a) +f=int(a) +if b==f: + print(b,"is an Armstrong Number") else: - print('Given number is not an Armstrong Number') - + print(b,"is not An Armstrong Number") \ No newline at end of file From 9f309db3cddc6536c9150c852641c8483de0187d Mon Sep 17 00:00:00 2001 From: Sharmily-Veeramani Date: Fri, 6 Dec 2024 15:55:13 +0530 Subject: [PATCH 32/39] changed the arithmetic symbol of '/' to '%' --- problems/easy/easy_q1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..50fa9f4 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -1,7 +1,7 @@ # Check Even or Odd: Write a program to check if a given number is even or odd. num = int(input("Enter a number: ")) -if (num / 2) != 0: +if (num % 2) != 0: print("{0} is Odd".format(num)) else: print("{0} is Even".format(num)) From d58deae1d6d1811bbbf3da3039d84404f75b8c5d Mon Sep 17 00:00:00 2001 From: mohamedimthiyas2007 Date: Fri, 6 Dec 2024 11:52:47 +0000 Subject: [PATCH 33/39] added f format which is not added before --- problems/easy/easy_q1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..5785085 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -2,6 +2,6 @@ num = int(input("Enter a number: ")) if (num / 2) != 0: - print("{0} is Odd".format(num)) + print(f"{0} is Odd".format(num)) else: - print("{0} is Even".format(num)) + print(f"{0} is Even".format(num)) From 7ec4cd82063692cbfd439a8bedab394cf242e5b0 Mon Sep 17 00:00:00 2001 From: mohamedimthiyas2007 Date: Fri, 6 Dec 2024 12:01:41 +0000 Subject: [PATCH 34/39] repeat two times of num1 --- problems/easy/easy_q2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..455f8f5 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -7,5 +7,5 @@ def largest_of_two(a, b): if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) - res = largest_of_two(num1,num1) + res = largest_of_two(num1,num2) print(res) \ No newline at end of file From 277f1224b027ce386043f918e50bceb28721713a Mon Sep 17 00:00:00 2001 From: mohamedimthiyas2007 Date: Fri, 6 Dec 2024 12:12:46 +0000 Subject: [PATCH 35/39] in 3rd line code we add logical mistake ! i will remove --- problems/easy/easy_q3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..0626149 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,6 +1,6 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): - if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: + if year % 4 == 0 and year % 100 == 0 or year % 400 == 0: return "Not a Leap Year" return "Leap Year" if __name__ == "__main__": From 51b8f84828f07e1f3f9d7dbf558fd5e856721679 Mon Sep 17 00:00:00 2001 From: mohamedimthiyas2007 Date: Fri, 6 Dec 2024 13:36:29 +0000 Subject: [PATCH 36/39] added f format whic 5th and 7th line' --- problems/easy/easy_q4.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..a925fc3 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,14 +1,14 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. def check_number(num): if num > 0: - print("Negative") + print("positive") elif num < 0: - print("Positive") + print("negative") else: - print("Number is negative") + print("the number is zero") if __name__ == "__main__": - num = input("Enter the Number : ") + num = int(input("Enter the Number : ")) res = check_number(num) print(res) From 76ac5ddf7b7ed95d45a30cfc5881b983d2294767 Mon Sep 17 00:00:00 2001 From: mohamedimthiyas2007 Date: Fri, 6 Dec 2024 15:07:32 +0000 Subject: [PATCH 37/39] added zero divisional error --- problems/easy/easy_q2.py | 5 +--- problems/easy/easy_q3.py | 7 +++-- problems/easy/easy_q5.py | 23 +++++++-------- problems/medium/m1.py | 62 ++++++++++++++++++++++++---------------- 4 files changed, 53 insertions(+), 44 deletions(-) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index c0f1462..e7e115b 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -8,10 +8,7 @@ def largest_of_two(a, b): num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) res = largest_of_two(num1,num2) -<<<<<<< HEAD - print(res) -======= print(res) ->>>>>>> ba97dead197c3e5577b54dfdb8c34d42327f3c16 + diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 0143c1d..501dadc 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,8 +1,9 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): - if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - return "Leap Year" - return "Not a Leap Year" + if year % 4 == 0 or year % 100 == 0 or year % 400 == 0: + return "Leap Year" + else: + return "Not a Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index 195d34d..cd6d1ee 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -1,17 +1,14 @@ -# Grading System: Write a program that takes a student’s marks as input and prints the grade (A, B, C, or F) based on given thresholds. - def grade_system(marks): - if marks >= 90: - return "B" - elif marks >= 80: - return "A" - elif marks >= 70: - return "F" + if marks >=90 and marks <=100: + return "A" + elif marks >= 80 and marks <=90: + return "B" + elif marks >= 70 and marks <=80: + return "C" else: - return "C" + return "D" if __name__ == "__main__": - num = int(input("Enter the Mark : ")) - res = grade_system(num) - print(res) - + num = int(input("Enter the Mark : ")) + res = grade_system(num) + print(res) \ No newline at end of file diff --git a/problems/medium/m1.py b/problems/medium/m1.py index ecb1be8..7021189 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -1,31 +1,45 @@ -''' -Create a menu to perform basic mathematical operations (addition, subtraction, multiplication, division, modulo) on two numbers. - -''' def math_operations_menu(choice): - a, b = map(int, input("Enter two numbers(separated by commas): ").split(sep=",")) + try: + a, b = map(int, input("Enter two numbers (separated by a comma): ").split(sep=",")) + + # Perform the operation based on user's choice + if choice == 1: + print(f"Addition of {a} and {b}: {a + b}") + elif choice == 2: + print(f"Subtraction of {a} and {b}: {a - b}") + elif choice == 3: + print(f"Multiplication of {a} and {b}: {a * b}") + elif choice == 4: + if b == 0: + print("Error! Division by zero is not allowed.") + else: + print(f"Division of {a} and {b}: {a / b}") + elif choice == 5: + if b == 0: + print("Error! Modulo by zero is not allowed.") + else: + print(f"Modulus of {a} and {b}: {a % b}") + elif choice == 6: + print(f"{a} to the power of {b}: {a ** b}") + else: + print("Invalid option!!!") + except ValueError: + print("Invalid input! Please enter two valid numbers separated by a comma.") - if choice == 1: - print(f"Subtraction of {a} and {b}:{a - b}") - elif choice == 2: - print(f"Addition of {a} and {b}:{a + b}") - elif choice == 3: - print(f"Division of {a} and {b}:{a / b}") - elif choice == 4: - print(f"Multiplication of {a} and {b}:{a * b}") - elif choice == 5: - print(f"Modulus of {a} and {b}:{a // b}") - elif choice == 6: - print(f"{a} to the power of {b}:{a**b}") - else: - print("Invalid option!!!") -print("-------------Mathematical operation menu---------------") +# Menu for mathematical operations +print("-------------Mathematical Operation Menu---------------") print("1. Add") print("2. Subtract") print("3. Multiply") print("4. Divide") print("5. Modulus") -print("6. Expontential") -choice = int(input("Enter your choice: ")) -math_operations_menu(choice) -print("-------------------------------------------------------") \ No newline at end of file +print("6. Exponential") + +# Get user's choice for operation +try: + choice = int(input("Enter your choice: ")) + math_operations_menu(choice) +except ValueError: + print("Invalid choice! Please enter a number between 1 and 6.") + +print("-------------------------------------------------------") From b11f62a9931c8b97d939c3fe4829af377fb1a106 Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 11:43:00 +0100 Subject: [PATCH 38/39] completed --- problems/medium/m13.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/problems/medium/m13.py b/problems/medium/m13.py index 33dfa3f..ffad2e1 100644 --- a/problems/medium/m13.py +++ b/problems/medium/m13.py @@ -4,12 +4,15 @@ def is_prime(num): if num < 2: return False - for i in range(2, num): - if num % i == 0: + n=num // 2 + 1 + for i in range(2, n): + if n % i == 0: return False return True n = int(input("Enter a number: ")) -for i in range(2, n + 1): - if is_prime(i): - print(i) + +if is_prime(n): + print(f"The given number {n} is a not prime number ") +else: + print(f"The given number {n} is a prime number ") \ No newline at end of file From eb5e991f05ef4daa39a8b6d2de1221cc632c3c10 Mon Sep 17 00:00:00 2001 From: mourishantony Date: Fri, 6 Dec 2024 22:39:39 +0530 Subject: [PATCH 39/39] Completed now --- problems/medium/m12.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/problems/medium/m12.py b/problems/medium/m12.py index 7692543..48b725c 100644 --- a/problems/medium/m12.py +++ b/problems/medium/m12.py @@ -9,8 +9,10 @@ def multiply(x, y): return x * y def divide(x, y): - return x / y - + try: + return x / y + except Exception as e : + print(f"Error occured due to {e}") while True: print("\nMENU") print("1. Add") @@ -23,7 +25,9 @@ def divide(x, y): if choice == '5': break - + elif choice not in "1234" : + print("Invalid Choice") + continue num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) @@ -35,8 +39,5 @@ def divide(x, y): result = multiply(num1, num2) elif choice == '4': result = divide(num1, num2) - else: - print("Invalid choice") - continue - + print("Result: ", result)