Oct-15-2020, 01:04 AM
(This post was last modified: Oct-15-2020, 01:04 AM by deanhystad.)
You need to learn about functions. Functions break up large blocks of code into smaller, easier to understand chunks. These chunks can be reused as much as you need by calling the function. In the example below, the improve_stats() function calls the mini_game() function. This separates the mini-game from the improve stats logic. You could design a more interesting or entertaining game without having to change an of the other code.
def mini_game(): ## blah blan blah if correct_answer: return 5 return 0 def improve_stats(): stchoice = input("Improve which Stat? (Strength, Agility, Health):\n ") score = mini_game() if score != 0: if stchoice[0] in 'sS': strength = min(MAX_STRENGTH, strength+score) print("Your new strength stat is", strength) elif strchoice[0] in 'aA': agility = min(MAX_AGILITY, agility+score) print("Your new agility stat is", agility) ## blah blah blah