1. Write a Python program to calculate the sum, product, division, multiplication, and modular division of two numbers entered by the user.
# Input the two numbers from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Calculate the sum of the two numbers
sum_result = num1 + num2
# Calculate the product of the two numbers
product_result = num1 * num2
# Calculate the division of the two numbers
division_result = num1 / num2
# Calculate the multiplication of the two numbers
multiplication_result = num1 * num2
# Calculate the modulus (remainder) of the two numbers
modulus_result = num1 % num2
# Print the results
print("Sum:", sum_result)
print("Product:", product_result)
print("Division:", division_result)
print("Multiplication:", multiplication_result)
print("Modulus:", modulus_result)
2. Write a Python program to check if a given number is even or odd.
number = int(input("Enter a number: "))
if number % 2 == 0:
print(number, "is even.")
else:
print(number, "is odd.")
3. Write a Python program to convert temperature in Celsius to Fahrenheit.
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)
4. Write a Python program to calculate the factorial of a given number.
number = int(input("Enter a number: "))
factorial = 1
if number < 0:
print("Factorial cannot be calculated for negative numbers.")
elif number == 0:
print("The factorial of 0 is 1.")
else:
for i in range(1, number + 1):
factorial *= i
print("The factorial of", number, "is", factorial)
5. Write a Python program to find the area of a triangle given its base and height.
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
area = (base * height) / 2
print("The area of the triangle is:", area)