1
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"

4

1 回答 1

0
a,b = map(int, input().split())

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

print('%r' %c)
于 2016-10-10T00:49:54.540 回答