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")
[Link] 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}")
[Link] 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.")
[Link] 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.")
[Link] 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.")
[Link] 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.")
[Link]
a = int(input("Enter the number: "))
b=1
fact = 1
while b <= a:
fact *= b
b += 1
print("The factorial of", a, "is", fact)
[Link] 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}")
[Link]
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}")
[Link]
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 - [Link](d)) / (2 * a)
y = (-b + [Link](d)) / (2 * a)
print("The solutions for the equation are:", x, y)
[Link] 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, [Link](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)
[Link] 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)