I made a simple Hearthstone fatigue calculator. For those who don't know, Hearthstone is a card game in which every turn you draw a card from your deck. Once you're out of cards, you start taking fatigue damage, getting 1 more damage each turn. The total damage dealt in X turns is known as the Triangular Number Sequence: 1 (1), 3 (1+2), 6 (1+2+3), 10 (1+2+3+4). For example, at turn 4 the fatigue damage has already dealt 10 dmg (1+2+3+4). This could be used for some decks that make you run out of cards, to calculate how much damage they need to kill the opponent or to just calculate how much damage X fatigue turns will do.
I just wanted to know how my code looks. I know it's a very simple program but I might be doing something wrong and I guess it's better to know as early as possible. Besides, code reviewing a long project is just too boring for everyone. I've been learning by myself and as nobody ever reads my code I might be doing terrible things without knowing it haha
def error(): print("Whoops, something went wrong. Please try again.") def calc_mode(t, s): d = 0 for i in range(s, t+s): d = d + i return d def lethal_mode(d_input, s): d_calc = 0 i = 1 t = 0 while d_calc < d_input: d_calc = d_calc + i i += 1 t += 1 return t while True: # Checks if the mode input is valid try: mode = int(input("\nMODES: " "\n* '1' to get the turns needed for X damage " "\n* '2' to get the damage dealt in X turns " "\nPlease type to select your mode: ")) except ValueError: error() continue else: while True: if mode == 1: # Checks if the input after the mode is valid while True: try: damageInput = int(input("\nPlease input the damage needed for lethal: ")) startInput = int(input("Starting at how much damage? (default is 1): ")) except ValueError: error() continue else: print("\n>> You will need %d fatigue turns for that sweet lethal" % lethal_mode(damageInput, startInput)) continue if mode == 2: while True: try: turnsInput = int(input("\nPlease input how many fatigue turns: ")) startInput = int(input("Starting at how much damage? (default is 1): ")) except ValueError: error() continue else: print("\n>> It will deal %d damage" % calc_mode(turnsInput, startInput)) continue else: error() break
What do you think overall? Thanks!