擅长:python、mysql、java
<p>我相信您正在尝试累积用户数据,以便在最后打印所有数据(如果不是这样,您可以在for循环的底部添加一行<code>print(f"User {i+1} is named {name} with mobile number {mno} (username {uname}, password {pswd}")</code>)。我认为这里有两种方法,其中一种更好。更糟糕但更简单的方法是将每个数据点存储为单个数组:</p>
<pre class="lang-py prettyprint-override"><code>name = []
mno = []
uname = []
pswd = []
n=int(input("Enter the number of User:\n"))
for i in range(0,n):
print("Enter the details of User %d"%(i+1))
name.append(input("Enter the name of the user:\n"))
mno.append(int(input("Enter the mobile number of the user:\n")))
uname.append(input("Enter the username of the user:\n"))
pswd.append(input("Enter the password of the user:\n"))
print(f"names: {name}\nPhone Numbers: {mno}\nUsernames: {uname}, Password: {pswd}")
# This information could be processed later in the program with name[0], mno[0]
</code></pre>
<p>更好的替代方法是使用Python的OOP模型,创建一个带有<code>__init__</code>的用户类,该类将分别设置名称、mno、uname、pswd的内部变量作为输入,并将其存储在<code>self</code>中,如果在类中添加了<code>__repr__</code>或<code>__str__</code>接口,则允许您只编写<code>print(user)</code></p>