Skip to content
6 changes: 6 additions & 0 deletions problems/easy/easy_q1.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# 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))
else:

if (num % 2) == 0:


print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
Expand Down
17 changes: 15 additions & 2 deletions problems/easy/easy_q10.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ def is_palindrome(num):

reverse = 0

while True:
reverse = reverse * 10 + num % 10
num //= 10
if num == 0:
break
return reverse == original



while True:
reverse = reverse * 10 + num % 10
num //= 10
Expand All @@ -28,9 +37,13 @@ def is_palindrome(num):
else:
return "It is not a Palindrome"


if __name__ == "__main__":
nums = int(input("Enter the Number: "))
res = is_palindrome(nums)
print(res)







13 changes: 11 additions & 2 deletions problems/easy/easy_q11.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ def day_of_week(day):
7: "Sunday"
}

if day <=7 :
return switch[8]
else:
print("Error occured")
if __name__ == "__main__":
day = int(input("Enter a number (1-7) to get the day of the week: "))
result = day_of_week(day)
print(result)


if day < 1 or day > 7:
return "Invalid day"
return switch[day]
Expand All @@ -35,5 +45,4 @@ def day_of_week(day):
print(xcd)
else:
print("Enter Valid Input")



8 changes: 8 additions & 0 deletions problems/easy/easy_q16.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ def sum_first_last(arr):
return arr[0] + arr[-1]
if __name__ == "__main__":
# Handle the input by Yourself

arr=[]
n=int(input("Enter the Total number of Elements:"))
for i in range(n):
x=int(input("Enter the element :"))
arr.append(x)

arr=[2,5,8,7,6]

print(sum_first_last(arr))
10 changes: 7 additions & 3 deletions problems/easy/easy_q17.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# 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

n=int(input("Enter the number of times:"))
x="X"

x=input("Enter a character:")
n=int(input("enter the number of times to loop:"))

print_x_n_times(x,n)
9 changes: 7 additions & 2 deletions problems/easy/easy_q18.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# 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

s=input("Enter the string:")
print(last_char_of_string(s))

s=[7,8,9,6]
print( last_char_of_string(s))
print( last_char_of_string(s))

7 changes: 6 additions & 1 deletion problems/easy/easy_q2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ 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)
print(res,"is the largest number")

res = largest_of_two(num1,num2)

print(res)
Expand All @@ -47,4 +51,5 @@ def largest_of_two(a, b):






7 changes: 7 additions & 0 deletions problems/easy/easy_q3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# 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"
else:
return "Leap Year"


if year % 4 == 0 or year % 100 == 0 or year % 400 == 0:
return "Leap Year"
else:
Expand Down Expand Up @@ -42,6 +48,7 @@ def is_leap_year(year):




if __name__ == "__main__":

num = int(input("Enter the number :"))
Expand Down
8 changes: 7 additions & 1 deletion problems/easy/easy_q4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero.
def check_number(num):

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 = int(input("Enter the Number : "))
check_number(num)


if num > 0:
print("positive")
elif num < 0:
Expand Down Expand Up @@ -32,4 +38,4 @@ def check_number(num):
print(res)



10 changes: 7 additions & 3 deletions problems/easy/easy_q5.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def grade_system(marks):
<<<<<<< HEAD
if marks >=90 and marks <=100:
return "A"
elif marks >= 80 and marks <=90:
Expand All @@ -13,7 +13,7 @@ def grade_system(marks):
num = int(input("Enter the Mark : "))
res = grade_system(num)
print(res)
=======
if marks >= 90:
return "A"
elif marks >= 80:
Expand All @@ -22,13 +22,17 @@ def grade_system(marks):
return "C"
else:

return "F"


return "D"

return "F"



if __name__ == "__main__":
num = int(input("Enter the Mark : "))
res = grade_system(num)
print(res)
>>>>>>> c39895b92dbcd0dd59250c4268a660b41d857e3d
7 changes: 7 additions & 0 deletions problems/easy/easy_q6.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ def print_numbers(n):
while i <= n:
print(i)

i += 1

if __name__ == "__main__":
num = int(input("Enter the Number "))
print_numbers(num)

i+= 1

if __name__ == "__main__":
Expand All @@ -30,3 +36,4 @@ def print_numbers(n):




16 changes: 14 additions & 2 deletions problems/easy/easy_q7.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# 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 //= 10
return total

if __name__ == "__main__":
num = int(input("Enter the Number: "))
if num < 0:
num = -num
result = sum_of_digits(num)
print(f"Sum of digits: {result}")


total += num % 10
num = num//10

Expand All @@ -21,4 +33,4 @@ def sum_of_digits(num):




11 changes: 10 additions & 1 deletion problems/easy/easy_q8.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Reverse a Number: Accept a number and print its reverse using a while loop.
def reverse_number(num):

rev = ""
while num != 0:
digit = num % 10 #digit = 123%10 = 3 12%10
rev = rev + str(digit) #rev = 3
num //= 10 # num//= 10 = 12
return rev

rev = ''
while num != 0:
digit = num % 10
Expand All @@ -12,8 +20,9 @@ def reverse_number(num):
num //= 10
return int(rev)


if __name__ == "__main__":
num = int(input("Enter num : "))
num = int(input("Enter num : ")) #123
res = reverse_number(num)
print(res)

Expand Down
12 changes: 11 additions & 1 deletion problems/easy/easy_q9.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Factorial of a Number: Write a program to calculate the factorial of a given number using a while loop.
def factorial(n):
result = 1

i=1
while i <= n:
result *= i
i += 1

while n > 0:
result *= n
n -= 1

return result

if __name__ == "__main__":
Expand All @@ -16,7 +23,10 @@ def factorial(n):

print(factorial(num))



print(factorial(num))


res=factorial(num)
print(res)

12 changes: 12 additions & 0 deletions problems/medium/m1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def math_operations_menu(choice):
a=int(input("Enter first numbers: "))
b=int(input("Enter second numbers: "))


if choice == 2:
print("Subtraction:", a - b)
elif choice == 1:
print("Addition:", a + b)

if choice == 1:

print(f"Addition of {a} and {b} : {a + b}")
Expand All @@ -57,6 +63,7 @@ def math_operations_menu(choice):
print("Subtraction:", a - b)
elif choice == 1:
print("Addition:", a + b)

elif choice == 4:
print("Division:", a / b)
elif choice == 3:
Expand All @@ -82,6 +89,10 @@ def math_operations_menu(choice):
print(f"{a} to the power of {b} : {a**b}")
else:
print("Invalid option")


math_operations_menu()

math_operations_menu()

print("Invalid option!!!")
Expand Down Expand Up @@ -120,3 +131,4 @@ def math_operations_menu(choice):




8 changes: 7 additions & 1 deletion problems/medium/m17.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'''Write a program to reverse a given list without using built-in functions'''
def reverse_list(lst):

return lst[::-1]
lst=[1,2,3,4,5]
print(reverse_list(lst))

start = 0
end = len(lst)-1
while start < end:
Expand All @@ -13,4 +18,5 @@ def reverse_list(lst):
print("Original list:", input_list)

reversed_list = reverse_list(input_list)
print("Reversed list:", reversed_list)
print("Reversed list:", reversed_list)

Loading