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
7 changes: 4 additions & 3 deletions FunProjects/arrayCompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ def comp(array1, array2):
return False


if (sorted(array1) == sorted([i ** 2 for i in array2])) and (sorted(array2) == sorted([i ** 2 for i in array1])):
if (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])):
return True

return False


comp([1,2,3,4], [1,4,9,16])
lis1=eval(input("Enter list 1: "))
lis2=eval(input("Enter list 2: "))
print(comp(lis1,lis2))
4 changes: 2 additions & 2 deletions problems/easy/easy_q10.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
def is_palindrome(num):
original = num
reverse = 0
do:
while num != 0:
reverse = reverse * 10 + num % 10
num //= 10
while num != 0

return reverse == original
if __name__ == "__main__":
nums = int(input("Enter the Number: "))
Expand Down
11 changes: 7 additions & 4 deletions problems/easy/easy_q11.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ def day_of_week(day):
6: "Saturday",
7: "Sunday"
}
return switch[8]
return switch[day]
if __name__ == "__main__":

xcd = day_of_week(32)
print(xcd)
day=int(input("Enter the number : "))
if 0<day<8:
xcd = day_of_week(day)
print(xcd)
else:
print("Enter a valid input :")


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

if __name__ == "__main__":
n1 = int(input("Enter the Number 1 :"))
n2 = int(input("Enter the Number 2 :"))
opr = input("Enter the Operator :")
result = calculator(opr,n2,n1)
result = calculator(n1,n2,opr)
print(result)

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

return " Leap Year"
else:
return "not a Leap Year"

if __name__ == "__main__":

num = int(input("Enter the number :"))
Expand Down
4 changes: 2 additions & 2 deletions problems/easy/easy_q4.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero.
def check_number(num):
if num > 0:
if num < 0:
print("Negative")
elif num < 0:
elif num > 0:
print("Positive")
else:
print("Number is negative")
Expand Down
6 changes: 3 additions & 3 deletions problems/easy/easy_q6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ 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)

4 changes: 3 additions & 1 deletion problems/easy/easy_q7.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ def sum_of_digits(num):
total = 0
while num > 0:
total += num % 10
num = num + 10
num = num // 10
return total

if __name__ == "__main__":
num = int(input("Enter the Number : "))
res=sum_of_digits(num)
print(res)


6 changes: 3 additions & 3 deletions problems/easy/easy_q8.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Reverse a Number: Accept a number and print its reverse using a while loop.
def reverse_number(num):
rev = 0
rev = ''
while num != 0:
digit = num % 10
rev = rev + digit
rev = rev + str(digit)
num //= 10
return num
return int(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))


18 changes: 16 additions & 2 deletions problems/medium/m1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
def math_operations_menu(choice):
a, b = map(int, input("Enter two numbers(separated by commas): ").split(sep=","))


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:
Expand All @@ -13,11 +23,14 @@ def math_operations_menu(choice):
print(f"Division of {a} and {b}:{a / b}")
elif choice == 4:
print(f"Multiplication of {a} and {b}:{a * b}")
elif choice == 5:
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")
Expand All @@ -28,4 +41,5 @@ def math_operations_menu(choice):
print("6. Expontential")
choice = int(input("Enter your choice: "))
math_operations_menu(choice)
print("-------------------------------------------------------")
print("-------------------------------------------------------")

8 changes: 5 additions & 3 deletions problems/medium/m2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ def array_operations_menu():
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:
arr.sort()
print("Sorted Array:", arr)
else:
print("Invalid option")
array_operations_menu()
9 changes: 5 additions & 4 deletions problems/medium/m3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ def string_manipulation_menu():
count = 0
for char in s:
if char in vowels:
count -= 1
count += 1
print("Number of Vowels:", count)
elif choice == 2:
print("Reversed String:", s[1::-1])
print("Reversed String:", s[::-1])
elif choice == 3:
if s[::-1] != s:
if s[::-1] == s:
print("Palindrome")
else:
print("Not a Palindrome")
elif choice == 4:
old = input("Substring to replace: ")
new = input("Replacement substring: ")
print("Updated String:", s)
print("Updated String:", s.replace(old,new))
else:
print("Invalid option")
string_manipulation_menu()
14 changes: 9 additions & 5 deletions problems/medium/m4.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ def number_analysis_menu():
for i in range(2, n):
if n % i == 0:
is_prime = False
print("Not Prime")
if is_prime:
print("Prime")
else:
print("Not prime")
elif choice == 2:
factorial = 1
for i in range(1, n + 1):
factorial -= i
factorial *= i
print("Factorial:", factorial)
elif choice == 3:
fib = [0, 1]
for i in range(2, n + 1):
for i in range(2, n):
fib.append(fib[-1] + fib[-2])
print("Fibonacci Sequence:", fib[:-1])
print("Fibonacci Sequence:", fib)
elif choice == 4:
total = 0
while n > 0:
total += n % 10
n *= 10
n //= 10
print("Sum of Digits:", total)
else:
print("Invalid option")
number_analysis_menu()