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 number for a, enter a number for b and see if they are equal or not?
user1590499
9013 gold badges10 silver badges17 bronze badges
asked Sep 15, 2012 at 1:25
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."
answered Sep 15, 2012 at 1:32
AestheteAesthete
18.2k6 gold badges34 silver badges45 bronze badges
6
a=20 b=10 if a==b: print "equal" else: print "unequal"
answered Sep 15, 2012 at 1:26
user1655481user1655481
3861 silver badge10 bronze badges
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)answered Sep 15, 2012 at 1:27
BorgleaderBorgleader
15.6k5 gold badges43 silver badges61 bronze badges
6
Python Basic: Exercise-134 with Solution
Write a Python program to input two integers in a single line.
Sample Solution-1:
Python Code:
print("Input the value of x & y") x, y = map(int, input().split()) print("The value of x & y are: ",x,y)Sample Output:
Input the value of x & y 2 4 The value of x & y are: 2 4Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Sample Solution-2:
Python Code:
a, b = [int(a) for a in input("Input the value of a & b: ").split()] print("The value of a & b are:",a,b)Sample Output:
Input the value of a & b: 2 4 The value of a & b are: 2 4Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to calculate the time runs (difference between start and current time)of a program.
Next: Write a Python program to print a variable without spaces between values.
Python Basic: Exercise-35 with Solution
Write a Python program which will return true if the two given integer values are equal or their sum or difference is 5.
Pictorial Presentation:
Sample Solution:
Python Code:
def test_number5(x, y): if x == y or abs(x-y) == 5 or (x+y) == 5: return True else: return False print(test_number5(7, 2)) print(test_number5(3, 2)) print(test_number5(2, 2)) print(test_number5(7, 3)) print(test_number5(27, 53))Sample Output:
True True True False FalseFlowchart:
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to sum of two given integers. However, if the sum is between 15 to 20 it will return 20.
Next: Write a Python program to add two objects if both objects are an integer type.