Python 列表 -- ValueError:以 10 为基数的 int() 的文字无效:' '

问题描述 投票:0回答:1

我尝试使用循环和列表理解。尽管我试图将数字转换为列表中的 int,但两者都无法解析整数。

student_scores = input("Input a list of student scores.")
print(student_scores)
for n in range(0, len(student_scores)):
    student_scores[n] = int(student_scores[n])
print(student_scores)


student_score = [int(i) for i in student_scores]

highest_score = 0
for score in student_score:
    if score > highest_score:
        highest_score = score
print(f"The highest score in the class is {highest_score}")
python string list integer list-comprehension
1个回答
0
投票

我在输入问题的末尾添加了 .split() 并能够解决该问题。感谢您的回复

© www.soinside.com 2019 - 2024. All rights reserved.