首页 > 解决方案 > ValueError: no enough values to unpack (expected 2, got 1) 请帮我解决这个错误

问题描述

T = int(input())
for tc in range(T):
    # Read integers a and b.
    (a, b) = map(int, input().split(' '))
    
    ans = a + b
    print(ans)

标签: python

解决方案


T = int(input("Enter number of times for loop to run as per your input"))
for tc in range(T):
    (a, b) = map(int, input().split(' '))
    ans = a + b
    print(ans)

当你第一次运行时,它会询问你想要的测试用例的数量。之后,您必须为您的数字提供两个数字之间的空格,正如您在split(' '). 如果您提到'-'split您必须提供'-'两个输入数字之间的一个。此外,您可以strip()在前面添加函数split()以避免由于输入中的空格而导致的错误。


推荐阅读