嘿,伙计们,我试图在for循环中创建N个对象,但它给了我一个错误TypeError: cannot unpack non-iterable Jugador object
你能帮我吗
我做错了什么
这是我的代码:
from Jugador import Jugador
class Juego():
tipoJuego = ""
nJugadores = ""
def __init__(self,tipoJuego, nJugadores):
self.tipoJuego = tipoJuego
self.nJugadores = nJugadores
nJugadoresInt = int(nJugadores)
tipoJuegoInt = int(tipoJuego)
if tipoJuegoInt == 1 or tipoJuegoInt == 2 or tipoJuegoInt == 3:
print("Has elegido el tipo de juego ",tipoJuegoInt, ", y van a jugar ", nJugadores, " Personas")
else:
print("Error: Tipo de juego invalido")
exit()
for i in range(1,nJugadoresInt):
print("Jugador",i, "introduzca el nombre de usuario:")
nUsu = input()
print("Introduzca la edad:")
age = input()
print("Introduzca la palabra elegida:")
word = input()
J,i = Jugador(nUsu, age, word)
如果您打算创建一种方法来分配N个对象,以便稍后找到它们,我可以建议将它们存储在一个列表中
J
:供参考:https://docs.python.org/3.8/tutorial/datastructures.html
相关问题 更多 >
编程相关推荐