Python 3.x 使用list2 python打印list1

Python 3.x 使用list2 python打印list1,python-3.x,list,Python 3.x,List,我不知道如何在互联网上搜索这个代码,所以我在这里问 我的代码: # This code is in Tes.py n = [str]*3 x = [int]*3 MyLib.name(n) MyLib.number(x) MyLib.Result(n,x) # This code in MyLib.py with 3 def def name(data) : for i in range (3) : n[i] = str(input("Enter Name

我不知道如何在互联网上搜索这个代码,所以我在这里问 我的代码:

# This code is in Tes.py
n = [str]*3 
x = [int]*3
MyLib.name(n)
MyLib.number(x)
MyLib.Result(n,x)

# This code in MyLib.py with 3 def
def name(data) :
    for i in range (3) :
        n[i] = str(input("Enter Name : ")

def number(data) :
    for s in range (3) :
        x[i] = int(input("Enter Number : ")

def result(data1,data2) :
    for i in data1 :
        for i in data2 :
            print("Your Name",n,"Your Number",x)

examples :
input 1 : Jack
          Rino
          Gust
input 2 : 1232
          1541
          2021
output what I want : Your Name Jack Your Number 1232
                     Your Name Rino Your Number 1541
                     Your Name Gust Your Number 2021

output that i got :  Your Name Jack Your Number 1232
                     Your Name Jack Your Number 1541
                     Your Name Jack Your Number 2021
                     Your Name Rino Your Number 1232
                     Your Name Rino Your Number 1541
                     Your Name Rino Your Number 2021
                     Your Name Gust Your Number 1232
                     Your Name Gust Your Number 1541
                     Your Name Gust Your Number 2021
如何获得我想要的输出,我想在谷歌上搜索,但我不知道我必须键入什么。

这就是你的意思吗

for i in range(min(len(n), len(x))):
    print("Your Name",n[i],"Your Number",x[i])
如果您为该代码提供您提到的输入,它将显示所需的结果。当您编写两个循环时

 for i in n :
    for i in x :
您的打印将被触发3*3=9次!您只需要一个循环,因为在两个输入端,您接受相同数量的输入(3个名称和3个数字!)。甚至我都会说为什么你需要3个循环?为什么不仅仅是这样:

total = 3
n = [str]*total
x = [int]*total
for i in range (total):
    n[i] = str(input("Enter Name : "))
    x[i] = int(input("Enter Number : "))
    print("Your Name",n[i],"Your Number",x[i])

    

我试过了,但错误是“索引器:列表索引超出范围”,有什么解决办法吗?我得到了错误是“索引器:列表索引超出范围”,有什么建议吗?我没有更改代码,我只是在打印中添加[I](“你的名字”,n[I],“你的号码”,x[I]),只添加[I]不会解决你的问题。在打印之前,必须重写正在使用的循环。还有为什么在嵌套循环中使用相同的变量
i
?在
def number(data)
函数中,您使用
s
作为循环变量,但使用
x[i]
分配数字!我已经编辑好了,很抱歉缺少细节
total = 3
n = [str]*total
x = [int]*total
for i in range (total):
    n[i] = str(input("Enter Name : "))
    x[i] = int(input("Enter Number : "))
    print("Your Name",n[i],"Your Number",x[i])