海峡到 Int Python
Str To Int Python
scores = int()
while True:
score = int(input("Score: "))
scores[int(score)] = score
again = input("N/F")
if again == "F":
print('o')
if again == "N":
while True:
score = int(input("Score: "))
scores[int(score)] = score
again = input("N/F")
if again == "F":
print(scores + score)
我不知道如何进入 scores[int(score)] = score
我收到了那个错误
Traceback (most recent call last):
File "main.py", line 4, in <module>
scores[int(score)] = score
TypeError: 'int' object does not support item assignment
我想做的是写下你的分数并计算平均分。
感谢您的帮助 (:
我认为你正在尝试做这样的事情?
scores = []
while True:
score = int(input("Score: "))
scores.append(int(score))
again = input("Continue? Y/N")
if again.lower() == "n":
break
print(f'Average: {sum(scores)/len(scores)}')
我认为在您开始摆弄像这样的玩具应用程序之前,python 上的简短初学者教程确实会让您受益匪浅。如果您至少首先了解基本语法,您将从练习中获得更多好处,我的意思是毫不吝啬。
scores = []
user_input = "0"
while user_input.isdigit():
user_input = input("Type score or str to get result\n")
if user_input.isdigit():
scores.append(int(user_input))
mean = sum(scores)/len(scores) if len(scores)>0 else 0
scores = int()
while True:
score = int(input("Score: "))
scores[int(score)] = score
again = input("N/F")
if again == "F":
print('o')
if again == "N":
while True:
score = int(input("Score: "))
scores[int(score)] = score
again = input("N/F")
if again == "F":
print(scores + score)
我不知道如何进入 scores[int(score)] = score
我收到了那个错误
Traceback (most recent call last):
File "main.py", line 4, in <module>
scores[int(score)] = score
TypeError: 'int' object does not support item assignment
我想做的是写下你的分数并计算平均分。 感谢您的帮助 (:
我认为你正在尝试做这样的事情?
scores = []
while True:
score = int(input("Score: "))
scores.append(int(score))
again = input("Continue? Y/N")
if again.lower() == "n":
break
print(f'Average: {sum(scores)/len(scores)}')
我认为在您开始摆弄像这样的玩具应用程序之前,python 上的简短初学者教程确实会让您受益匪浅。如果您至少首先了解基本语法,您将从练习中获得更多好处,我的意思是毫不吝啬。
scores = []
user_input = "0"
while user_input.isdigit():
user_input = input("Type score or str to get result\n")
if user_input.isdigit():
scores.append(int(user_input))
mean = sum(scores)/len(scores) if len(scores)>0 else 0