Here is a Python program using logical operator to take two numbers from the user and print their sum if they are equal:
Python
# Take two numbers from the user
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
# Check if the numbers are equal
if num1 == num2:
# Print the sum of the numbers
print("The sum of the numbers is:", num1 + num2)
else:
# Print a message that the numbers are not equal
print("The numbers are not equal.")
[tex] { \color{cyan}{\boxed{\fcolorbox{lime}{black}{ \: Example \: Output:- }}}}[/tex]
Enter the first number: 10
Enter the second number: 10
The sum of the numbers is: 20
This program works by first taking two numbers from the user and storing them in the variables num1 and num2. Then, it uses the logical operator == to check if the numbers are equal. If the numbers are equal, the program prints the sum of the numbers. Otherwise, the program prints a message that the numbers are not equal.
[tex]{\underline{\boxed{{\underline{\overline{\mid{\mathscr{\pink{Thank \: You \: :) }{\mid}}}}}}}}}[/tex]
Answers & Comments
Answer:
# Taking input from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Checking if the numbers are equal
if num1 == num2:
sum_of_numbers = num1 + num2
print("The numbers are equal. Their sum is:", sum_of_numbers)
else:
print("The numbers are not equal.")
Explanation:
Verified answer
[tex] \sf{ \underline{ANSWER :}}[/tex]
Here is a Python program using logical operator to take two numbers from the user and print their sum if they are equal:
Python
# Take two numbers from the user
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
# Check if the numbers are equal
if num1 == num2:
# Print the sum of the numbers
print("The sum of the numbers is:", num1 + num2)
else:
# Print a message that the numbers are not equal
print("The numbers are not equal.")
[tex] { \color{cyan}{\boxed{\fcolorbox{lime}{black}{ \: Example \: Output:- }}}}[/tex]
Enter the first number: 10
Enter the second number: 10
The sum of the numbers is: 20
This program works by first taking two numbers from the user and storing them in the variables num1 and num2. Then, it uses the logical operator == to check if the numbers are equal. If the numbers are equal, the program prints the sum of the numbers. Otherwise, the program prints a message that the numbers are not equal.
[tex]{\underline{\boxed{{\underline{\overline{\mid{\mathscr{\pink{Thank \: You \: :) }{\mid}}}}}}}}}[/tex]
Hope this helps you !