【发布时间】:2014-07-31 19:17:43
【问题描述】:
在我正在使用的 Python 教程书中,我键入了一个为 同时分配 给出的示例。运行程序时出现上述ValueError,不知道是什么原因。
代码如下:
#avg2.py
#A simple program to average two exam scores
#Illustrates use of multiple input
def main():
print("This program computes the average of two exam scores.")
score1, score2 = input("Enter two scores separated by a comma: ")
average = (int(score1) + int(score2)) / 2.0
print("The average of the scores is:", average)
main()
这是输出。
>>> import avg2
This program computes the average of two exam scores.
Enter two scores separated by a comma: 69, 87
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import avg2
File "C:\Python34\avg2.py", line 13, in <module>
main()
File "C:\Python34\avg2.py", line 8, in main
score1, score2 = input("Enter two scores separated by a comma: ")
ValueError: too many values to unpack (expected 2)
【问题讨论】:
-
这是因为你正在使用 python3 检查我的答案它可能对你有帮助:)
标签: python input iterable-unpacking