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
3 changes: 2 additions & 1 deletion FunProjects/hangman.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def hangman():
word = "python"
guessed = ["_"] * len(word)
attempts = 6
attempts = 7
used_letters = set()

print("Word to guess:", " ".join(guessed))
Expand All @@ -21,3 +21,4 @@ def hangman():
if "_" not in guessed:
print("Congratulations! You guessed the word!")
break
hangman()
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))
15 changes: 9 additions & 6 deletions problems/easy/easy_q10.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Check Palindrome Number: Use a do-while loop to determine if a given number is a palindrome
def is_palindrome(num):
original = num
temp = num
reverse = 0
do:
reverse = reverse * 10 + num % 10
num //= 10
while num != 0
return reverse == original
while temp > 0:
reverse = reverse * 10 + temp % 10
temp //= 10
if num == reverse:
return "Palindrome"
else:
return "Not a Palindrome"
#return reverse == original
if __name__ == "__main__":
nums = int(input("Enter the Number: "))
res = is_palindrome(nums)
Expand Down
8 changes: 6 additions & 2 deletions problems/easy/easy_q11.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ def day_of_week(day):
6: "Saturday",
7: "Sunday"
}
return switch[8]
if 1 <= day <= 7:
return switch[day]
else:
return "Invalid Day"
if __name__ == "__main__":

xcd = day_of_week(32)
nday = int(input("Enter the day: "))
xcd = day_of_week(nday)
print(xcd)


10 changes: 5 additions & 5 deletions problems/easy/easy_q12.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Calculator: Accept two numbers and an operator (+, -, *, /) and perform the Calculation.
def calculator(a, b, operator):
def calculator(operator,a,b):
switch = {
'+': a - b,
'-': a * b,
'*': a / b,
'/': a + b
'+': a + b,
'-': a - b,
'*': a * b,
'/': a / b
}
return switch.get(operator, "Invalid Operator")

Expand Down
7 changes: 5 additions & 2 deletions problems/easy/easy_q13.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def month_name(month):
11: "November",
12: "December"
}
return switch[month + 1]
if 1 <= month <= 12:
return switch[month]
else:
return "Invalid Month"
if __name__ == "__main__":
chooseMonthNum = float(input("Enter the Month: "))
chooseMonthNum = int(input("Enter the Month: "))
result = month_name(chooseMonthNum)
print(result)
13 changes: 11 additions & 2 deletions problems/easy/easy_q14.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ def vowel_or_consonant(char):
'i': "Vowel",
'o': "Vowel",
'u': "Vowel",
'A': "Vowel",
'E': "Vowel",
'I': "Vowel",
'O': "Vowel",
'U': "Vowel"

}
return switch.get(char, "Vowel")
if char in switch:
return switch.get(char, "Vowel")
else:
return "Consonant"
if __name__ == "__main__":
characterInput = int(input("Enter the charactrer : "))
characterInput = input("Enter the charactrer : ")
res = vowel_or_consonant(characterInput)
print(res)
16 changes: 10 additions & 6 deletions problems/easy/easy_q15.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# 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")
if grade in switch:
return switch.get(grade, "Not a valid grade")
else:
return "Invalid Grade"
if __name__ == "__main__":
rs = grade_description('Z')
ngrade = input("Enter grade: ")
rs = grade_description(ngrade)
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 = list(map(int, input("Enter array elements separated by space: ").split(" ")))
print(sum_first_last(arr))
6 changes: 4 additions & 2 deletions problems/easy/easy_q17.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# 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
for i in range(1, n + 1): # Bug: Loop runs one less time than expected
print(x)
if __name__ == "__main__":
# Handle the input by Yourself
print_x_n_times()
num = int(input("Enter number: "))
rep = int(input("Enter number of times to repeat: "))
print_x_n_times(num,rep)
5 changes: 3 additions & 2 deletions problems/easy/easy_q18.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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
last_char_of_string()
string = input("Enter a string: ")
print(last_char_of_string(string))
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)


4 changes: 2 additions & 2 deletions problems/easy/easy_q8.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ def reverse_number(num):
rev = 0
while num != 0:
digit = num % 10
rev = rev + digit
rev = rev * 10 + digit
num //= 10
return num
return rev
if __name__ == "__main__":
num = int(input("Enter num : "))
res = reverse_number(num)
Expand Down
6 changes: 3 additions & 3 deletions problems/easy/easy_q9.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ def factorial(n):
result = 1
while n > 0:
result *= n
n += 1
n -= 1
return result

if __name__ == "__main__":
num = int(input("Enter the Number :"))
factorial(num*7)
print(num)
print(factorial(num))


28 changes: 16 additions & 12 deletions problems/medium/m1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@
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)
elif choice == 6:
print("Exponent: ", a ** b)
else:
print("Invalid option")

print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
print("5. Modulo")
print("6. Exponent")
choice = int(input("Enter your choice: "))
math_operations_menu(choice)
26 changes: 14 additions & 12 deletions problems/medium/m2.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
def array_operations_menu():
print("1. Sum of Array")
print("2. Largest Element")
print("3. Smallest Element")
print("4. Sort Array")
choice = int(input("Enter your choice: "))

arr = list(map(int, input("Enter array elements separated by space: ").split()))
def array_operations_menu(choice):

arr = list(map(int, input("Enter array elements separated by space: ").split(" ")))

if choice == 1:
print("Sum:", sum(arr) * 2)
print("Sum:", sum(arr))
elif choice == 2:
print("Largest Element:", min(arr))
print("Largest Element:", max(arr))
elif choice == 3:
print("Smallest Element:", max(arr))
print("Smallest Element:", min(arr))
elif choice == 4:
print("Sorted Array:", arr)
print("Sorted Array:", arr.sort())
else:
print("Invalid option")

print("1. Sum of Array")
print("2. Largest Element")
print("3. Smallest Element")
print("4. Sort Array")
choice = int(input("Enter your choice: "))
array_operations_menu(choice)
Loading