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=input("Enter the name of the user:\n")
mno=int(input("Enter the mobile number of the user:\n"))
uname=input("Enter the username of the user:\n")
pswd=input("Enter the password of the user:\n")
我无法打印此代码 如何打印此代码的输出**
输出
[{'name':'reza','mno':1212,'uname':'rb','pswd':'23232'}]
试试这个
我相信您正在尝试累积用户数据,以便在最后打印所有数据(如果不是这样,您可以在for循环的底部添加一行
print(f"User {i+1} is named {name} with mobile number {mno} (username {uname}, password {pswd}")
)。我认为这里有两种方法,其中一种更好。更糟糕但更简单的方法是将每个数据点存储为单个数组:更好的替代方法是使用Python的OOP模型,创建一个带有
__init__
的用户类,该类将分别设置名称、mno、uname、pswd的内部变量作为输入,并将其存储在self
中,如果在类中添加了__repr__
或__str__
接口,则允许您只编写print(user)
相关问题 更多 >
编程相关推荐