From d58deae1d6d1811bbbf3da3039d84404f75b8c5d Mon Sep 17 00:00:00 2001 From: mohamedimthiyas2007 Date: Fri, 6 Dec 2024 11:52:47 +0000 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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("-------------------------------------------------------")