int()Python 3的文字无效

时间:2017-11-06 01:42:19

标签: python

    print("INPUT:")
num_sequence_A = input("sequence of numbers:") 

num_sequence_B = input("sequence of numbers:") 

dot_product = []
list_A = num_sequence_A.split(", ")

list_B = num_sequence_B.split(", ")



for i in range (len(list_A)):

    number = int(list_A[i]) * int(list_B[i])

    dot_product.append(number)

下面的代码一直工作正常,直到我今天尝试打开它并收到消息"用spyder创建的文件混合了行尾字符" ..

现在我得到了ValueError: invalid literal for int() with base 10

1 个答案:

答案 0 :(得分:0)

假设一个字符串作为输入:

>>> num_sequence_A = 'aaa'
>>> list_A = num_sequence_A.split(", ")
>>> list_A
['aaa']
>>> list_A[0]
'aaa'

int('aaa')提升了OP中观察到的ValueError。具体做法是:

ValueError: invalid literal for int() with base 10: 'aaa'