0% found this document useful (0 votes)
17 views4 pages

Sodapdf

Uploaded by

darksuhbho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Sodapdf

Uploaded by

darksuhbho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Celcius to Farenheit
a = input("What do you want to write, ’c’ or ’f’: ")
if a == ’c’:
f = float(input("Enter the value in Fahrenheit: "))
c = (f - 32) * 5 / 9
print(f"{f}°F is equal to {c}°C")
elif a == 'f':
c = float(input("Enter the value in Celsius: "))
f = 9 * c / 5 + 32
print(f"{c}°C is equal to {f}°F")
else:
print("Error: Invalid input")

2.compound interest
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the annual interest rate (in percentage): "))
time = float(input("Enter the time period (in years): "))

rate /= 100
compound_interest = principal * ((1 + rate) ** time - 1)
print(f"The compound interest is: {compound_interest:.2f}")

3.prime number
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num**0.5) + 1):
if (num % i) == 0:
print(f"{num} is not a prime number.")
break
else:
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")

4.greater of three number


num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if num1 >= num2 and num1 >= num3:
print(f"{num1} is the greatest.")
elif num2 >= num1 and num2 >= num3:
print(f"{num2} is the greatest.")
else:
print(f"{num3} is the greatest.")

5.leap year
year = int(input("Enter a year: "))
if (year % 4 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")

6.vowel consonant
ch = input("Enter a character: ").lower()
if ch in ('a', 'e', 'i', 'o', 'u'):
print(ch, "is a vowel.")
else:
print(ch, "is not a vowel.")

7.factorial
a = int(input("Enter the number: "))
b=1
fact = 1
while b <= a:
fact *= b
b += 1
print("The factorial of", a, "is", fact)

8.factorial recuesive fnc


def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
number = 5
result = factorial(number)
print(f"The factorial of {number} is {result}")

9.GCD
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
num1 = 48
num2 = 18
result = gcd(num1, num2)
print(f"The GCD of {num1} and {num2} is {result}")

10.calcultor
def add(x, y): return x + y
def subtract(x, y): return x - y
def multiply(x, y): return x * y
def divide(x, y): return "Error! Division by zero." if y == 0 else x / y

def calculator():
operations = {'1': add, '2': subtract, '3': multiply, '4': divide}
while True:
choice = input("Select operation: 1. Add 2. Subtract 3. Multiply 4. Divide\nEnter choice (1/2/3/4): ")
if choice in operations:
num1, num2 = float(input("Enter first number: ")), float(input("Enter second number: "))
print(f"Result: {operations[choice](num1, num2)}")
if input("Do you want to perform another calculation? (yes/no): ").lower() != 'yes': break
else:
print("Invalid input. Please enter a number between 1 and 4.")

if __name__ == "__main__":
calculator()

11. Quadratic Equa


import cmath
a, b, c = 1, 5, 6
d = b**2 - 4*a*c
x = (-b - cmath.sqrt(d)) / (2 * a)
y = (-b + cmath.sqrt(d)) / (2 * a)
print("The solutions for the equation are:", x, y)

12.prime no range 1000


import math
lower_bound, upper_bound = 900, 1000
def is_prime(n):
if n <= 1:
return False
for i in range(2, math.isqrt(n) + 1):
if n % i == 0:
return False
return True
primes = [num for num in range(lower_bound, upper_bound + 1) if is_prime(num)]
print("Prime numbers between", lower_bound, "and", upper_bound, "are:", primes)

12.not fiboo include


def is_fibonacci(num):
a, b = 0, 1
while b <= num:
if b == num:
return True
a, b = b, a + b
return False
def print_non_fibonacci_series(limit):
for num in range(1, limit + 1):
if not is_fibonacci(num):
print(num, end=" ")
print_non_fibonacci_series(8)

13. sum of digit


def sum_of_digits(number):
total = 0
while number > 0:
total += number % 10
number //= 10
return total
number = 12345
print("The sum of digits in", number, "is:", sum_of_digits(number))

14. swwaapin three var


def swap_three_variables(a, b, c):
a, b, c = c, a, b
return a, b, c
x = 10
y = 20
z = 30
print("Before swapping:")
print("x =", x)
print("y =", y)
print("z =", z)
x, y, z = swap_three_variables(x, y, z)
print("\nAfter swapping:")
print("x =", x)
print("y =", y)
print("z =", z)

You might also like