Skip to content Skip to sidebar Skip to footer

Writing A Program That Compares 2 Numbers In Python

I am new to python and I do not know how to go about this problem exactly. If I want to compare two integers to see if they are equal, how would I set that up? For example, enter a

Solution 1:

a = input("Enter the first number: ")
b = input("Enter the second number: ")
# if a is b: - Compares id's, and can cause inconsistencies. Use == instead.
if a == b:
  print "Both inputs are equal"
else:
  print "Your input is not equal."

Solution 2:

a=20
b=10
if a==b:
 print "equal"
else:
 print "unequal"

Solution 3:

def compare(a, b):
   return a == b

You could write a function like this and call it, like so:

aNumber = 3
anotherNumber = 4
result = compare(aNumber, anotherNumber)
print(result)

Post a Comment for "Writing A Program That Compares 2 Numbers In Python"