Sodapdf
Sodapdf
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.")
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)
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()