Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion problems/easy/easy_q1.py
Original file line number Diff line number Diff line change
@@ -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))
10 changes: 5 additions & 5 deletions problems/easy/easy_q2.py
Original file line number Diff line number Diff line change
@@ -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)
largest_of_two(num1,num2)
7 changes: 4 additions & 3 deletions problems/easy/easy_q3.py
Original file line number Diff line number Diff line change
@@ -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 :"))
Expand Down
11 changes: 5 additions & 6 deletions problems/easy/easy_q4.py
Original file line number Diff line number Diff line change
@@ -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)



18 changes: 10 additions & 8 deletions problems/easy/easy_q5.py
Original file line number Diff line number Diff line change
@@ -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)

5 changes: 2 additions & 3 deletions problems/easy/easy_q6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions problems/easy/easy_q7.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


25 changes: 13 additions & 12 deletions problems/medium/m1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)