我是新手python.我确信这是一个非常基本的问题,但我仍然没有在python中得到它.
我有两个1D-arrays,长度为50的A和B.我想找到给定的用户输入,A [0],我必须返回B [0],A [1] - > B [1]等等.
我已经为这个任务创建了一个函数.
A = [10, 20,.... 500]
B = [1, 4,.... 2500]
def func():
x = input("enter a value from the array A: ") #user input
for i in range(50):
if A[i] == x:
print(B[i])
else:
print("do nothing")
func()
Run Code Online (Sandbox Code Playgroud)
但是,如果我调用该函数,我什么也得不到.如果有人能帮助我,我将不胜感激.谢谢.
试试这个
A = [10, 20,.... 500]
B = [1, 4,.... 2500]
def func():
x = int(input("enter a value from the array A: ")) #user input
for i in range(50):
if A[i] == x:
print(B[i])
else:
print("do nothing")
func()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
90 次 |
| 最近记录: |