instead of summing the two values, it just repeats it
Question:
my code in python is supposed to sum the two variables and return a value, but it keeps returning the two numbers together:
A = input("insert a value: ")
B = input("insert another value: ")
if A >= B:
R == A + B
print ("this is the result", R)
else:
R == A - B
print ("this is the result", R)
input 1: A=1 and B=1
output 1: R=11
input 2: A=2 and B=1
output 2: R=21
Answers:
I don’t write python code, but you need to cast the input from type String to Int
A_INPUT = input("insert a value: ")
B_INPUT = input("insert another value: ")
A = int(A_INPUT)
B = int(B_INPUT)
if A >= B:
R == A + B
print ("this is the result", R)
else:
R == A - B
print ("this is the result", R)
input()
returns a string (str
) object, so when you try to add A and B together, they end up being concatenated.
You need to cast the result from input()
to an integer (int
). Try something like this instead:
A = int(input("insert a value: "))
B = int(input("insert another value: "))
my code in python is supposed to sum the two variables and return a value, but it keeps returning the two numbers together:
A = input("insert a value: ")
B = input("insert another value: ")
if A >= B:
R == A + B
print ("this is the result", R)
else:
R == A - B
print ("this is the result", R)
input 1: A=1 and B=1
output 1: R=11
input 2: A=2 and B=1
output 2: R=21
I don’t write python code, but you need to cast the input from type String to Int
A_INPUT = input("insert a value: ")
B_INPUT = input("insert another value: ")
A = int(A_INPUT)
B = int(B_INPUT)
if A >= B:
R == A + B
print ("this is the result", R)
else:
R == A - B
print ("this is the result", R)
input()
returns a string (str
) object, so when you try to add A and B together, they end up being concatenated.
You need to cast the result from input()
to an integer (int
). Try something like this instead:
A = int(input("insert a value: "))
B = int(input("insert another value: "))