diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 50fa9f4..2fd320a 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_q2.py b/problems/easy/easy_q2.py index 8c49830..8effa89 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 - else: - return a + print(a) + else: + print(b) + if __name__ == "__main__": 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 + largest_of_two(num1,num2) \ No newline at end of file diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..ab99555 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" + if year % 400 == 0 and year % 100 == 0 or year % 4 == 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_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..c4e3ab8 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,16 +1,15 @@ # 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") + elif num < 0: + print("Negative") else: - print("Number is negative") + print("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) diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index fbfab0b..06f5b5d 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -1,17 +1,19 @@ # 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" - else: + if marks < 100 and marks >= 90: + return "A" + elif marks < 90 and marks >= 80: + return "B" + elif marks <80 and marks >= 70: return "C" + elif marks < 0 or marks > 100: + return "Invalid marks" + else: + return "F" 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..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 diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index 8efa72e..5b3097e 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -3,10 +3,11 @@ def sum_of_digits(num): total = 0 while num > 0: total += num % 10 - num = num + 10 - return total + num //= 10 + print(total) if __name__ == "__main__": num = int(input("Enter the Number : ")) + sum_of_digits(num) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index dddb03c..95a8035 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -2,25 +2,26 @@ Create a menu to perform basic mathematical operations (addition, subtraction, multiplication, division, modulo) on two numbers. ''' -def math_operations_menu(): - print("1. Add") - print("2. Subtract") - print("3. Multiply") - print("4. Divide") - print("5. Modulo") - choice = int(input("Enter your choice: ")) - - a, b = map(int, input("Enter two numbers: ").split()) +def math_operations_menu(choice): + a, b = map(int, input("Enter two numbers: ").split(sep=",")) if choice == 1: print("Subtraction:", a - b) elif choice == 2: print("Addition:", 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) + print("Modulo:", a % b) else: print("Invalid option") + +print("1. Add") +print("2. Subtract") +print("3. Multiply") +print("4. Divide") +print("5. Modulo") +choice = int(input("Enter your choice: ")) +math_operations_menu(choice)