Makes such a mistake: ValueError: not enough values to unpack (expected 2, got 0)
-
I've just started studying the software, and that's the problem, and I'm starting to deal with acmp, like everything's going to be okay, but when I want to see how it works, it's not on the website, it's not like IDLE itself, it's not going to be anything but problem. ValueError: not enough values to unpack (expected 2, got 0) Code itself:
fin = open("input.txt") fout = open("output.txt","w")
a,b = map(int, fin.readline().split())
fout.write(str(a+b))fin.close()
fout.close()
Why doesn't it work? Input.txt find 4 and 5. Help the school.
-
a,b = map(int, fin.readline().split())
Depends on what is contained in the row which is extracted by a cut
fin.readline()
For example, if there's only one number or no numbers in the line, then there's a mistake, because nothing can be recorded in the variable.
b
or both variablesa, b
respectivelya, b = map(int, "".split()) # ошибка ValueError: not enough values to unpack (expected 2, got 0)
a, b = map(int, "10".split()) # ошибка ValueError: not enough values to unpack (expected 2, got 1)
a, b = map(int, "10 20".split()) # OK, все корректно
a, b = map(int, "10 20 30".split()) # ошибка ValueError: too many values to unpack (expected 2)
I'd rather read the information on the list and then work with it, depending on the size of the list.
data = list(int, fin.readline().split())