Python Input Split with a limit range

1.3k Views Asked by At
var1,var2 = input("Enter two digits a and b (0-9):").split(' ')
while True:
    if (0 <= var1 <= 9) and (0 <= var2 <= 9):
        result = var1+var2
    print("The result is: %r." %result)

I use Spyder Python 3.5 to write this code and try to run it. However, this code does not work.

It reveals that " (1) var1,var2 = input("Enter two digits a and b (0-9):").split(''); (2) TypeError: 'str' object is not callable"

1

There are 1 best solutions below

0
Jeremy_Tamu On BEST ANSWER
a,b = map(int, input().split())

while True:
    if (0 <= a <= 9) and (0 <= b <= 9):
        c = a + b
        break

print('%r' %c)