diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 759376b..a48fece 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -2,15 +2,9 @@ num = int(input("Enter a number: ")) + 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 Even".format(num)) - - - + \ No newline at end of file diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 110f086..ff47888 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -2,6 +2,7 @@ def largest_of_two(a, b): if a > b: + return a else: return b @@ -9,35 +10,9 @@ 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) - print(res) + print(num1,"larger") else: 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) - 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 - - + \ No newline at end of file diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 2a6b7cc..ef1d387 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,6 +1,7 @@ # 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: if year % 100 == 0: return "Not a Leap Year" @@ -21,10 +22,4 @@ def is_leap_year(year): return "Leap Year" return "Not a Leap Year" - - -if __name__ == "__main__": - - num = int(input("Enter the number :")) - res = is_leap_year(num) - print(res) \ No newline at end of file + \ No newline at end of file diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 7c0ec66..b99ff2e 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -3,6 +3,7 @@ num = int(input("Enter the Number : ")) def check_number(num): + if num < 0: print("Negative") elif num > 0: @@ -10,7 +11,7 @@ def check_number(num): else: print("Number is Zero") - + if __name__ == "__main__": num = int(input("Enter the Number : ")) check_number(num) diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index 587c604..7ada51f 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -9,10 +9,17 @@ def grade_system(marks): return "C" else: + return "F" + +if __name__ == "__main__": + mark = int(input("Enter the Mark : ")) + res = grade_system(mark) + + return "D" if __name__ == "__main__": num = int(input("Enter the Mark : ")) res = grade_system(num) - print(res) + \ No newline at end of file diff --git a/problems/easy/easy_q6.py b/problems/easy/easy_q6.py index 2a3d8c5..cc53209 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -3,8 +3,7 @@ def print_numbers(n): i = 1 while i <= n: print(i) - i += 1 - + if __name__ == "__main__": num = int(input("Enter the Number ")) print_numbers(num) diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index 0b3053c..eccd1cd 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -1,20 +1,26 @@ # Sum of Digits: Write a program to calculate the sum of digits of a number using a while loop. -def sum_of_digits(num): +def sum_of_digits(num): total = 0 while num > 0: total += num % 10 + num = num // 10 + + num = num // 10 num //= 10 + return total if __name__ == "__main__": num = int(input("Enter the Number : ")) + res=sum_of_digits(num) print(res) + diff --git a/problems/medium/m1.py b/problems/medium/m1.py index ade346b..99456d9 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -5,6 +5,10 @@ def math_operations_menu(choice): a, b = map(int, input("Enter two numbers(separated by commas): ").split(sep=",")) + + a=int(input("Enter a num1:")) + b=int(input("Enter a num2:")) + if choice == 1: @@ -19,44 +23,6 @@ def math_operations_menu(choice): print("Modulo:", a // b) else: print("Invalid option") - -math_operations_menu() - - if choice == 2: - print("Subtraction:", a - b) - elif choice == 1: - print("Addition:", a + b) - elif choice == 4: - print("Division:", a / b) - elif choice == 3: - print("Multiplication:", a * b) - 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") math_operations_menu() - - print("Invalid option!!!") -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 + \ No newline at end of file