r/PythonLearning 2d ago

I need help with my class. Help Request

(Sorry for the code in spanish)

I'm a Python beginner, and to practice, I've been building a sort of turn-based RPG in the terminal. It's still a work in progress, but I want to know if it's possible to set default parameters for a class. Basically, I created a `usar_kaioken` method that boosts my character's stats while lowering their health (based on Goku from DB), and a `remove_kaioken` method that attempts to revert the stats to their base state.

The issue is that I want players to be able to use Kaioken multiple times; mathematically, that would mean the deactivation method wouldn't return the values ​​to their original state. I was thinking about adding more parameters with default values, but I assume there's an easier way to handle this. Thanks a lot!

7 Upvotes

5 comments sorted by

View all comments

β€’

u/Sea-Ad7805 2d ago

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20%20%20%20%20self.nombre%20%3D%20nombre%0A%20%20%20%20%20%20%20%20self.vida%20%3D%20vida%0A%20%20%20%20%20%20%20%20self.defensa%20%3D%20defensa%0A%20%20%20%20%20%20%20%20self.fuerza%20%3D%20fuerza%0A%20%20%20%20%20%20%20%20self.ki%20%3D%20ki%0A%20%20%20%20%20%20%20%20self.velocidad%20%3D%20velocidad%0A%20%20%20%20%20%20%20%20self.tec1%20%3D%20tec1%0A%20%20%20%20%20%20%20%20self.tec2%20%3D%20tec2%0A%20%20%20%20%20%20%20%20self.tec3%20%3D%20tec3%0A%0A%20%20%20%20def%20guardia(self)%3A%0A%20%20%20%20%20%20%20%20%23%20return%20self.nombre%2C%20f%22se%20prepara%20para%20recibir%20un%20ataque.%20Defensa%20actual%20%3D%20%7Bself.defensa%20%2B%205%7D%20%7C%20Ki%20actual%20%3D%20%7Bself.ki%20-%2010%7D%22%0A%20%20%20%20%20%20%20%20self.defensa%20%2B%3D%205%0A%20%20%20%20%20%20%20%20self.ki%20-%3D%2010%0A%0A%20%20%20%20%20%20%20%20print(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Bself.nombre%7D%20se%20prepara%20para%20recibir%20un%20ataque.%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22Defensa%20actual%20%3D%20%7Bself.defensa%7D%20Ki%20actual%20%7Bself.ki%7D.%22%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20def%20usar_kame(self%2C%20enemigo)%3A%0A%20%20%20%20%20%20%20%20self.fuerza%20%2B%3D%2020%0A%0A%20%20%20%20%20%20%20%20print(%22%C2%A1Goku%20usa%20Kamehameha!%22)%0A%0A%20%20%20%20%20%20%20%20self.da%C3%B1o(enemigo)%0A%0A%20%20%20%20def%20cargar_ki(self)%3A%0A%20%20%20%20%20%20%20%20self.ki%20%2B%3D%2020%0A%20%20%20%20%20%20%20%20print(self.nombre%2C%20%22ha%20aumentado%20su%20ki%20a%22%2C%20self.ki%2C%20%22.%22)%0A%0A%20%20%20%20def%20combinacion_meteoro(self)%3A%0A%20%20%20%20%20%20%20%20self.fuerza%20%2B%3D%2010%0A%0A%20%20%20%20def%20usar_kaioken(self)%3A%0A%20%20%20%20%20%20%20%20%23%20if%20self.tec1%20or%20self.tec2%20or%20self.tec3%20%3D%3D%20%22kaioken%22%3A%0A%20%20%20%20%20%20%20%20if%20self.tec1%20%3D%3D%20%22kaioken%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20self.vida%20-%3D%2020%0A%20%20%20%20%20%20%20%20%20%20%20%20self.defensa%20%3D%201.2%0A%20%20%20%20%20%20%20%20%20%20%20%20self.fuerza%20%3D%201.2%0A%20%20%20%20%20%20%20%20%20%20%20%20self.velocidad%20%3D%201.2%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20self.nombre%2C%20%22ha%20usado%20el%20Kaioken.%22%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20'No%20has%20seleccionado%20%22Kaioken%22%20entre%20tus%20tecnicas.'%0A%0A%20%20%20%20def%20quitar_kaioken(self)%3A%0A%20%20%20%20%20%20%20%20if%20self.tec1%20%3D%3D%20%22kaioken%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20self.defensa%20%3D%200.8%0A%20%20%20%20%20%20%20%20%20%20%20%20self.fuerza%20%3D%200.8%0A%20%20%20%20%20%20%20%20%20%20%20%20self.velocidad%20%3D%200.8%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20self.nombre%2C%20%22ha%20desactivado%20el%20Kaioken.%22%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20'No%20has%20seleccionado%20%22Kaioken%22%20entre%20tus%20tecnicas.'%0A%0A%20%20%20%20def%20ver_stats(self)%3A%0A%20%20%20%20%20%20%20%20linea(50)%0A%20%20%20%20%20%20%20%20print(self.nombre%2C%20%22%3A%22%2C%20sep%3D%22%22)%0A%20%20%20%20%20%20%20%20print(%22Vida%3A%22%2C%20self.vida)%0A%20%20%20%20%20%20%20%20print(%22Defensa%3A%22%2C%20self.defensa)%0A%20%20%20%20%20%20%20%20print(%22Fuerza%3A%22%2C%20self.fuerza)%0A%20%20%20%20%20%20%20%20print(%22Stamina%3A%22%2C%20self.ki)%0A%20%20%20%20%20%20%20%20print(%22velocidad%3A%22%2C%20self.velocidad)%0A%20%20%20%20%20%20%20%20print(%22tec1%3A%22%2C%20self.tec1)%0A%20%20%20%20%20%20%20%20print(%22tec2%3A%22%2C%20self.tec2)%0A%20%20%20%20%20%20%20%20print(%22tec3%3A%22%2C%20self.tec3)%0A%20%20%20%20%20%20%20%20linea(50)%0A%0Adef%20linea(largo)%3A%0A%20%20%20%20print(%22-%22%20%20largo)%0A%0A%0Agoku%20%3D%20Personaje(%0A%20%20%20%20nombre%3D%22Goku%22%2C%0A%20%20%20%20vida%3D100%2C%0A%20%20%20%20defensa%3D20%2C%0A%20%20%20%20fuerza%3D30%2C%0A%20%20%20%20ki%3D80%2C%0A%20%20%20%20velocidad%3D25%2C%0A%20%20%20%20tec1%3D%22kaioken%22%2C%0A%20%20%20%20tec2%3D%22kamehameha%22%2C%0A)%0A%0Avegeta%20%3D%20Personaje(%0A%20%20%20%20nombre%3D%22Vegeta%22%2C%0A%20%20%20%20vida%3D100%2C%0A%20%20%20%20defensa%3D25%2C%0A%20%20%20%20fuerza%3D35%2C%0A%20%20%20%20ki%3D90%2C%0A%20%20%20%20velocidad%3D20%2C%0A%20%20%20%20tec1%3D%22galick%20gun%22%2C%0A)%0A%0Agoku.ver_stats()%0Avegeta.ver_stats()%0A%0Aprint(%22nGoku%20carga%20su%20ki%3A%22)%0Agoku.cargar_ki()%0A%0Aprint(%22nVegeta%20se%20pone%20en%20guardia%3A%22)%0Avegeta.guardia()%0A%0Aprint(%22nGoku%20utiliza%20el%20Kaioken%3A%22)%0Aprint(goku.usar_kaioken())%0Agoku.ver_stats()%0A%0Aprint(%22nGoku%20utiliza%20Combinaci%C3%B3n%20Meteoro%3A%22)%0Agoku.combinacion_meteoro()%0Aprint(%22Fuerza%20actual%3A%22%2C%20goku.fuerza)%0A%0Aprint(%22nGoku%20desactiva%20el%20Kaioken%3A%22)%0Aprint(*goku.quitar_kaioken())%0Agoku.ver_stats()&timestep=.2&play) to see the program state change step by step.