You are on page 1of 2

a=int(input("Enter a number="))

factorial=1
if a<0:
print("Factorial of a number does not exist")
elif a==0:
print("Factorial of a number is 1")
else :
for i in range(1,a + 1):
factorial = factorial*i
print("The factorial of",a,"is",factorial)

Enter a number=5
The factorial of 5 is 120

a=int(input("Enter first number:"))


if a%2==0:
print("Number is even number")
else:
print("Number is odd number")

Enter first number:6


Number is even number

import math

def solve_quadratic(a, b, c):


discriminant = b**2 - 4*a*c
if discriminant > 0:
root1 = (-b + math.sqrt(discriminant)) / (2*a)
root2 = (-b - math.sqrt(discriminant)) / (2*a)
return root1, root2
elif discriminant == 0:
root = -b / (2*a)
return root,
else:
real_part = -b / (2*a)
imaginary_part = math.sqrt(abs(discriminant)) / (2*a)
root1 = complex(real_part, imaginary_part)
root2 = complex(real_part, -imaginary_part)
return root1, root2
a = float(input("Enter the coefficient a: "))
b = float(input("Enter the coefficient b: "))
c = float(input("Enter the coefficient c: "))
roots = solve_quadratic(a, b, c)
if len(roots) == 1:
print(f"The quadratic equation has one real root: {roots[0]}")
elif len(roots) == 2:
print(f"The quadratic equation has two real roots: {roots[0]} and
{roots[1]}")
else:
print(f"The quadratic equation has two complex roots: {roots[0]}
and {roots[1]}")

Enter the coefficient a: 5


Enter the coefficient b: 6
Enter the coefficient c: 3
The quadratic equation has two real roots: (-0.6+0.4898979485566356j)
and (-0.6-0.4898979485566356j)

def find_factors(number):
factors = []
for i in range(1, number + 1):
if number % i == 0:
factors.append(i)
return factors
number = int(input("Enter a number: "))
result = find_factors(number)
print(f"The factors of {number} are: {result}")

Enter a number: 5
The factors of 5 are: [1, 5]

def is_palindrome(input_string):
input_string = input_string.lower()
input_string = input_string.replace(" ", "")
return input_string == input_string[::-1]
string_to_check = "A man a plan a canal Panama"
result = is_palindrome(string_to_check)

if result:
print(f"'{string_to_check}' is a palindrome.")
else:
print(f"'{string_to_check}' is not a palindrome.")

'A man a plan a canal Panama' is a palindrome.

You might also like