In: Computer Science
Exercise #3 python
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.
below is the code which takes the numbers as input from user and then uses the if elif else conditional statements to check the values of both the numbers.
Code and OUtput:
choice = 'y'
while(choice!='n' and choice!='N'):
num1 = int(input("Enter value of num1: "))
num2 = int(input("Enter value of num2: "))
if num2 > num1:
print("num2 is greater than num1")
elif num1 > num2:
print("num1 is greater than num2")
else:
print("num1 is equal to num2")
choice = input("try again? ")
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!