Python 列表维护
您好,我正在制作一个列表维护程序,它将维护一个浮点值列表。我总是被卡住。 有人能帮我吗。 选项1是当前唯一有效的选项Python 列表维护,python,list,python-3.x,Python,List,Python 3.x,您好,我正在制作一个列表维护程序,它将维护一个浮点值列表。我总是被卡住。 有人能帮我吗。 选项1是当前唯一有效的选项 Option 3 Enter your choice: 3 Delete Value from List (by location in list): 2 Traceback (most recent call last): File "C:/Python33/test 3.py", line 49, in <module> main() File "C:/Pyth
Option 3
Enter your choice: 3
Delete Value from List (by location in list): 2
Traceback (most recent call last):
File "C:/Python33/test 3.py", line 49, in <module>
main()
File "C:/Python33/test 3.py", line 14, in main
opt3()
File "C:/Python33/test 3.py", line 36, in opt3
list1.pop(delLocation)
TypeError: 'str' object cannot be interpreted as an integer
option 2
Enter your choice: 2
Delete Value from List (by value): 1
Traceback (most recent call last):
File "C:/Python33/test 3.py", line 49, in <module>
main()
File "C:/Python33/test 3.py", line 12, in main
opt2()
File "C:/Python33/test 3.py", line 33, in opt2
list1.remove(delValue)
ValueError: list.remove(x): x not in list
list1
是在main()
函数中定义的,因此它在其他函数中不可用。你也可以
list1
设置为全局变量(阅读有关全局和的内容)或list1
作为参数传递给所有这些函数list1
是在main()
函数中定义的,因此它在其他函数中不可用。你也可以
list1
设置为全局变量(阅读有关全局和的内容)或list1
作为参数传递给所有这些函数在main函数中,执行以下操作:
global list1
list1=[1, 2, 3, 4, 5 ]
在main函数中,执行以下操作:
global list1
list1=[1, 2, 3, 4, 5 ]
听起来像家庭作业。请正确设置代码的格式/缩进。听起来像家庭作业。请正确设置代码的格式/缩进。