Skip to content
Merged
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
6 changes: 2 additions & 4 deletions problems/easy/easy_q1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@


if (num % 2) != 0:
print("{0} is Odd".format(num))
print("{0} is odd".format(num))
else:
print("{0} is Even".format(num))
print("{0} is odd".format(num))




7 changes: 7 additions & 0 deletions problems/easy/easy_q10.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ def is_palindrome(num):
original = num

reverse = 0

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

while num != 0:
reverse = reverse * 10 + num % 10
num //= 10
Expand Down
12 changes: 11 additions & 1 deletion problems/easy/easy_q11.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Day of the Week: Write a program that takes a number (1-7) and prints the corresponding day of the week using a switch case.
#
def day_of_week(day):
switch = {
1: "Monday",
Expand All @@ -9,6 +9,16 @@ def day_of_week(day):
6: "Saturday",
7: "Sunday"
}

if day < 1 or day > 7:
return "Invalid day"
return switch[day]
if __name__ == "__main__":
xcd = day_of_week(32)
print(xcd)



return switch[day]
if __name__ == "__main__":

Expand Down
4 changes: 4 additions & 0 deletions problems/easy/easy_q12.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def calculator(a, b, operator):
n2 = int(input("Enter the Number 2 :"))
opr = input("Enter the Operator :")
result = calculator(n1,n2,opr)

print(result)

print(result)


print(result)

4 changes: 2 additions & 2 deletions problems/easy/easy_q13.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def month_name(month):
}
return switch[month + 1]
if __name__ == "__main__":
chooseMonthNum = float(input("Enter the Month: "))
chooseMonthNum = int(input("Enter the Month: "))
result = month_name(chooseMonthNum)
print(result)
print(result)
11 changes: 7 additions & 4 deletions problems/easy/easy_q14.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ def vowel_or_consonant(char):
'o': "Vowel",
'u': "Vowel",
}
return switch.get(char, "Vowel")
return switch.get(char.lower(),"Constant")
if __name__ == "__main__":
characterInput = int(input("Enter the charactrer : "))
res = vowel_or_consonant(characterInput)
print(res)
characterInput = input("Enter the charactrer : ")
if len(characterInput)==1:
res = vowel_or_consonant(characterInput)
print(res)
else:
print("Please enter exactly one character.")
11 changes: 6 additions & 5 deletions problems/easy/easy_q15.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Grade Description: Write a program that accepts a grade (A, B, C, D, F) and prints its description (e.g., A = Excellent, B = Good, etc.) using a switch case.
def grade_description(grade):
switch = {
'A': "Good",
'B': "Average",
'C': "Poor",
'D': "Excellent",
'A': "Excellent",
'B': "Good",
'C': "Average",
'D': "Poor",
'F': "Fail"
}
return switch.get(grade, "Not a valid grade")
return switch.get(grade.upper(), "Please enter a valid grade")
if __name__ == "__main__":
rs = grade_description('Z')
print(rs)


5 changes: 3 additions & 2 deletions problems/easy/easy_q16.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Print the Sum of First and Last Array Element
def sum_first_last(arr):
return arr[1] + arr[-1]
return arr[0] + arr[-1]
if __name__ == "__main__":
# Handle the input by Yourself
sum_first_last()
arr=[2,5,8,7,6]
print(sum_first_last(arr))
4 changes: 3 additions & 1 deletion problems/easy/easy_q17.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ def print_x_n_times(x, n):
print(x)
if __name__ == "__main__":
# Handle the input by Yourself
print_x_n_times()
x=input("Enter a character:")
n=int(input("enter the number of times to loop:"))
print_x_n_times(x,n)
3 changes: 2 additions & 1 deletion problems/easy/easy_q18.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ def last_char_of_string(s):
return s[-2] # Bug: Fetches second-to-last character instead of last
if __name__ == "__main__":
# Handle the input by Yourself
last_char_of_string()
s=[7,8,9,6]
print( last_char_of_string(s))
11 changes: 11 additions & 0 deletions problems/easy/easy_q2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
def largest_of_two(a, b):
if a > b:

return a
else:
return b
if __name__=="__main__":
a = int(input("Enter the First Number :"))
b = int(input("Enter the Second Number :"))
res = largest_of_two(a,b)
print(res)


return a

return b
Expand Down Expand Up @@ -30,4 +40,5 @@ def largest_of_two(a, b):
res = largest_of_two(num1,num2)
print(res)



6 changes: 6 additions & 0 deletions problems/easy/easy_q3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def is_leap_year(year):

if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:

return "Leap Year"
else:
return "Not Leap Year"



return "Leap Year"
return "Not a Leap Year"
Expand All @@ -23,6 +28,7 @@ def is_leap_year(year):
return "Not a Leap Year"



if __name__ == "__main__":

num = int(input("Enter the number :"))
Expand Down
6 changes: 4 additions & 2 deletions problems/easy/easy_q4.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ def check_number(num):
if __name__ == "__main__":
num = int(input("Enter the Number : "))
res = check_number(num)
print(res)
main



print(res)



4 changes: 4 additions & 0 deletions problems/easy/easy_q5.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ def grade_system(marks):
elif marks >= 70:
return "C"
else:

return "D"

return "F"


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

i+= 1

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



i+= 1
if __name__ == "__main__":
num = int(input("Enter the Number: "))
Expand All @@ -21,3 +29,4 @@ def print_numbers(n):
print_numbers(num)



8 changes: 6 additions & 2 deletions problems/easy/easy_q7.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ 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 : "))
print(sum_of_digits(num))

res=sum_of_digits(num)
print(res)




6 changes: 6 additions & 0 deletions problems/easy/easy_q8.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ def reverse_number(num):
rev = ''
while num != 0:
digit = num % 10

rev = rev*10+ digit
num //= 10
return rev

rev = rev + str(digit)
num //= 10
return int(rev)

if __name__ == "__main__":
num = int(input("Enter num : "))
res = reverse_number(num)
Expand Down
6 changes: 6 additions & 0 deletions problems/easy/easy_q9.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ def factorial(n):
return result

if __name__ == "__main__":

n= int(input("Enter the Number :"))
print(factorial(n))


num = int(input("Enter the Number :"))

print(factorial(num))


res=factorial(num)
print(res)
Expand Down