Most basic fantasy combat simulator I was wondering if anyone had anything to recommend for how to clean up the code I made below. Essentially I am asking if my code is messy or not and if there are any recommendations for my improvement.

# Most basic fantasy combat simulator
import random

p_health = 5
g_health = 5
goblin_alive = True

def status():
    if g_health == 5:
        return "\nA menacing goblin stands before you..."
    elif g_health &gt;= 3:
        return "\nThe goblin is looking a little tired, and is bleeding..."
    elif g_health &gt;= 1:
        return "\nThe goblin is bleeding horribly and looks enraged..."

while goblin_alive:
    if g_health &lt;= 0:
        goblin_alive = False
        print("\nCongrats you slayed the goblin!")
        again = input("Play again? Y/N: ")

        if again == 'y' or again == 'Y':
            goblin_alive = True
        elif again == 'N' or again == 'n':
            print("\nGoodbye")
            exit()
    if p_health &lt;= 0:
        print("Oh dear you have died horribly and the goblin cuts your head off for a trophy...")
        again = input("Play again? Y/N: ")

        if again == 'y' or again == 'Y':
            p_health = 5
            g_heath = 5
            goblin_alive = True
        elif again == 'N' or again == 'n':
            print("\nGoodbye")
            exit()

    desc = status()
    print(desc)
    print("You have " + str(p_health) + ' hit points.')

    attack = input("Press enter to attack: ")
    if attack == '':
        print("\nYou swing your sword fiercely at the goblin!")
        hit_type = random.randint(1, 2)
        if hit_type == 1:
            damage = random.randint(1, 3)
            print("You deal a fierce blow for " + str(damage) + " damage to the goblin.")
            g_health = g_health - damage
        elif hit_type == 2:
            damage = random.randint(1, 3)
            print("The goblin slashes you for " + str(damage) + " damage, uh oh...")
            p_health = p_health - damage
    else:
        print("\nYou better do something...")
Your code looks good and was easy to understand, at least for me :)

A few things you can do to improve it:

Python String Format and Upper

Consider using python format() method, instead of:

print("You have " + str(p_health) + ' hit points.')


try:

print('You have {} hit points.'.format(p_health))


And when checking if a char equals to a given char, you don't have to check both cases you can just use Python upper/lower function so instead of:

if again == 'y' or again == 'Y':


try:

if again.lower() == 'y':
    do stuff




Better Practice

The status() function could be improved by assigning a value to result and returning it, this is just better practice:

def status():
    res = ''
    if g_health == 5:
        res = "\nA menacing goblin stands before you..."
    elif g_health &gt;= 3:
        res = "\nThe goblin is looking a little tired, and is bleeding..."
    elif g_health &gt;= 1:
        res = "\nThe goblin is bleeding horribly and looks enraged..."
    return res




Python Class

Perhaps this code will be better in a GoblinGame class, this class will have properties such as goblin_health, player_health and goblin_alive that can be assigned when initializing the class instance, and a run() method to play a round of the game, I've wrote a quick sample class you can follow along from there:

class GoblinGame:
    def __init__(self):
        self.player_health = 5
        self.goblin_health = 5

    def goblin_alive(self):
        return self.goblin_health &gt; 0

    @property
    def status(self):
        res = ''
        if self.goblin_health == 5:
            res = "\nA menacing goblin stands before you..."
        elif self.goblin_health &gt;= 3:
            res = "\nThe goblin is looking a little tired, and is bleeding..."
        elif self.goblin_health &gt;= 1:
            res = "\nThe goblin is bleeding horribly and looks enraged..."
        return res

    def run(self):
        while self.goblin_alive:
         # write the game logic...


Good Luck!