Home > other >  Python3 object-oriented appeared this kind of question to do!!!!!
Python3 object-oriented appeared this kind of question to do!!!!!

Time:12-15

Just met a problem when writing code to the
The code below

 class Engine (object) : 

Def __init__ (self, scene_map) :
Self. Scene_map=scene_map

Def play (self) :
Current_scene=self. Scene_map. Opening_scene () #
the current sceneLast_scene=self. Scene_map. Next_scene (' lanmo)

While current_scene!=last_scene:
Next_scene_name=current_scene. Enter ()
Current_scene=self. Scene_map. Next_scene (next_scene_name)

The class Base () :
Def enter (self) :
Print (' ok ')

The class Map (object) :

Modules={
'base: the base (),
}

Def __init__ (self, start_scene) :
Self. Start_scene=start_scene

Def next_scene (self, scene_neme) :
Val=Map. Modules. The get (scene_name)
Return val

Def opening_scene (self) :
Return the self. Next_scene (self. Start_scene)

A_map=Map (' base ')
A_game=Engine (a_map)
A_game. Play ()



Error:

 PS E: \ ic> Python try. Py 
Traceback (the most recent call last) :
The File "E: \ IC \ try. Py", line 36, in & lt; module>
A_game. Play ()
The File "E: \ IC \ try. Py", line 7, in play
Current_scene=self. Scene_map. Opening_scene () #
the current sceneThe File "E: \ IC \ try. Py", line 32, in opening_scene
Return the self. Next_scene (self. Start_scene)
The File "E: \ IC \ try. Py, 28, the line in next_scene
Val=Map. Modules. The get (scene_name)
NameError: name 'scene_name' is not defined


Anyone who can help solve it, really appreciate!!!!!

CodePudding user response:

The
refer to the original poster XHQShow response:
just met a problem when writing code to the
The code below

 class Engine (object) : 

Def __init__ (self, scene_map) :
Self. Scene_map=scene_map

Def play (self) :
Current_scene=self. Scene_map. Opening_scene () #
the current sceneLast_scene=self. Scene_map. Next_scene (' lanmo)

While current_scene!=last_scene:
Next_scene_name=current_scene. Enter ()
Current_scene=self. Scene_map. Next_scene (next_scene_name)

The class Base () :
Def enter (self) :
Print (' ok ')

The class Map (object) :

Modules={
'base: the base (),
}

Def __init__ (self, start_scene) :
Self. Start_scene=start_scene

Def next_scene (self, scene_neme) :
Val=Map. Modules. The get (scene_name)
Return val

Def opening_scene (self) :
Return the self. Next_scene (self. Start_scene)

A_map=Map (' base ')
A_game=Engine (a_map)
A_game. Play ()



Error:

 PS E: \ ic> Python try. Py 
Traceback (the most recent call last) :
The File "E: \ IC \ try. Py", line 36, in & lt; module>
A_game. Play ()
The File "E: \ IC \ try. Py", line 7, in play
Current_scene=self. Scene_map. Opening_scene () #
the current sceneThe File "E: \ IC \ try. Py", line 32, in opening_scene
Return the self. Next_scene (self. Start_scene)
The File "E: \ IC \ try. Py, 28, the line in next_scene
Val=Map. Modules. The get (scene_name)
NameError: name 'scene_name' is not defined


Anyone who can help solve it, really appreciate!!!!!

Parameter name wrong, neme

CodePudding user response:

Def next_scene (self, scene_neme) : # scene_neme should change scene_name here, isn't it wrong
Val=Map. Modules. The get (scene_name)
Return val

CodePudding user response:

Is the parameter name written neme, change to come back

CodePudding user response:

Ha ha ha, this is not to solve the problem, it is in the play "feathers" game,
If you have any code to check with the IDE should be can be marked after the finish problem, eyes get really tired of choose and employ persons,
Vs code should be able to solve the problem of this common
  • Related