In: Computer Science
Phyton Exercise 3
Write a program that could evaluate the relationship between two values. User is to key in the two values, and it will be stored in variable, num1 and num2. The program will do a comparison between the two values. If num1 is greater than num2, a message will be display on screen to indicate that num1 is greater than num2. The program will also display appropriate messages when num2 is greater than num1; and num1 is equal to num2. Once user get to know the relationship between the two values, he/she should be prompted with an option to insert the next two values or terminate the program
Explanation:
Here is the code which takes num1 as input from the user and also num2 is taken as input.
Then both the values are compared and the answer is printed based on that.
Then again the user decided to terminate or repeat.
Code:
while(True):
num1 = int(input("Enter num1: "))
num2 = int(input("Enter num2: "))
if num1 > num2:
print("Num1 is greater than Num2")
elif num2 > num1:
print("Num2 is greater than Num1")
else:
print("Num1 is equal to Num2")
option = input("Would you like to try again?(y/n): ")
if(option=='n' or option=='N'):
break
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!