How to Compare n and r in Python?

Estimated read time 1 min read

To compare two values n and r in Python, you can use comparison operators. Here’s an example of how you can do it:

n = 10
r = 5

if n > r:
    print("n is greater than r")
elif n < r:
    print("n is less than r")
    print("n is equal to r")

In this example, we compare n and r using the greater than (>) and less than (<) operators. If n is greater than r, the first condition is true and the corresponding message is printed. If n is less than r, the second condition is true. If both conditions are false, it means n and r are equal, and the else block is executed, printing the message “n is equal to r.”

You can modify the values of n and r in the example to compare any other pair of numbers.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply