Artificial Intelligence
Artificial Intelligence
# Addition
addition = num1 + num2
print(f"The sum of {num1} and {num2} is: {addition}")
# Subtraction
subtraction = num1 - num2
print(f"The difference of {num1} and {num2} is: {subtraction}")
# Multiplication
multiplication = num1 * num2
print(f"The product of {num1} and {num2} is: {multiplication}")
# Division
if num2 != 0: # Checking if the divisor is not zero
division = num1 / num2
print(f"The division of {num1} by {num2} is: {division}")
else:
print("Division by zero is not allowed.")
# Modulus
if num2 != 0: # Checking if the divisor is not zero
modulus = num1 % num2
print(f"The modulus of {num1} and {num2} is: {modulus}")
else:
print("Modulus by zero is not allowed.")
# Floor Division
if num2 != 0: # Checking if the divisor is not zero
floor_division = num1 // num2
print(f"The floor division of {num1} by {num2} is: {floor_division}")
else:
print("Floor division by zero is not allowed.")
# Exponentiation
exponentiation = num1 ** num2
print(f"The result of {num1} raised to the power of {num2} is:
{exponentiation}")
Enter the first number: 10
Enter the second number: 3
The sum of 10.0 and 3.0 is: 13.0
The difference of 10.0 and 3.0 is: 7.0
The product of 10.0 and 3.0 is: 30.0
The division of 10.0 by 3.0 is: 3.3333333333333335
The modulus of 10.0 and 3.0 is: 1.0
The floor division of 10.0 by 3.0 is: 3.0
The result of 10.0 raised to the power of 3.0 is: 1000.0
2. Write a Program to Find the Largest of Three Numbers
Question: Write a program to input three numbers and find the
largest of the three using if-elif-else statements.
Ans: # Program to find the largest of three numbers
return total_sum
list1 = [1, 2, 3]
list2 = [4, 5, 6]
merged_list = merge_lists(list1, list2)
print("Merged list:", merged_list)
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
if choice == '1':
print(f"{num1} + {num2} = {add(num1, num2)}")
elif choice == '2':
print(f"{num1} - {num2} = {subtract(num1, num2)}")
elif choice == '3':
print(f"{num1} * {num2} = {multiply(num1, num2)}")
elif choice == '4':
print(f"{num1} / {num2} = {divide(num1, num2)}")
else:
print("Invalid input")