Moving hero but hero is stuck

world_map = [['H/T', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', 'T', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', 'T', ' ', ' ', ' '],
             [' ', 'T', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', 'T', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', 'K', ' ']]

player = {'Name': 'The Hero', 'Min Damage': 2, 'Max Damage': 4,'Defence': 1, 'HP': 20, 'Inventory': [], 'fought': False, 'Y': 0, 'X': 0}

day = 1
col = 0
row = 0
player['Y'] = col
player['X'] = row

save = open('C:/test/savegame.csv', 'r+')
print("Welcome to Ratventure!")
print("----------------------")

# Code your main program here
#main text
def displaymenu():
    global player
    for i in range(len(main_text)):
        print('{}) {}'.format(i+1, main_text[i]))
    choice = int(input('Enter choice: '))
    if choice == 1:
        displaytown()
    elif choice == 2:

    elif choice == 3:
        print('Exiting game')
    else:
        print('\nInvalid choice please try again')
        displaymenu()

def resumegame():
    filename = 'C:/test/savegame.csv'
    if not os.path.isfile(filename):
        return {}
    with open(filename) as ifh:
        return yaml.load(ifh)

#town text
def displaytown():
    print()
    global day
    global player
    print('Day {}: You are in a town.'.format(day))
    for i in range(len(town_text)):
        print('{}) {}'.format(i+1, town_text[i]))
    choice = int(input('Enter choice: '))

    if choice == 1:
        print(player.get('Name'))
        print('{:>8} {}-{}'.format("Damage:", player.get('Min Damage'), player.get('Max Damage')))
        print('{:>8} {}'.format('Defence:', player.get('Defence')))
        print('{:>8} {}'.format('HP:', player.get('HP')))
        displaytown()
    if choice == 2:
        displaymap()
        displaytown()
    if choice == 3:
        movehero()
    if choice == 4:
        print('You are fully healed.')
        day += 1
        displaytown()
    if choice == 5:
        print('Game saved.')
        with open('C:/test/savegame.csv', 'r+') as data:
            data.write(str(player))
        displaytown()
    if choice == 6:
        'Exiting game.'

#world map
def displaymap():
    global world_map
    for r in world_map:
        print('\n{}+'.format('+---' * 8))
        for c in r:
            print('|{:^3}'.format(c), end='')
    print('\n{}+'.format('+---' * 8))

#move hero
def movehero():
    displaymap()
    global row
    global col
    global world_map

    move = False
    while not move:
        print('W = up; A = left; S = down; D = right')
        move = str(input('Your move: '))
        if move == 'W' or move == 'w':
            if player['Y'] > 0:
                if world_map[col][row] == 'H/T':
                    world_map[col][row] = 'T'
                    col -= 1
                    world_map[col][row] += 'H'
                elif world_map[col][row] == 'H':
                    world_map[col][row] = ' '
                    col -= 1
                    world_map[col][row] += 'H'
                player['Y'] -= 1
                move = True
                displaymap()
                displaytown()
            else:
                print('End of world please try again')
                move = False

        elif move == 'A' or move == 'a':
            if player['X'] > 0:
                if world_map[col][row] == 'H/T':
                    world_map[col][row] = 'T'
                    row -= 1
                    world_map[col][row] += 'H'
                elif world_map[col][row] == 'H':
                    world_map[col][row] = ' '
                    row -= 1
                    world_map[col][row] += 'H'
                player['X'] -= 1
                move = True
                displaymap()
                displaytown()
            else:
                print('End of world please try again')
                move = False

        elif move == 'S' or move == 's':
            if player['Y'] < 7:
                if world_map[col][row] == 'H/T':
                    world_map[col][row] = 'T'
                    col += 1
                    world_map[col][row] += 'H'
                elif world_map[col][row] == 'H':
                    world_map[col][row] = ' '
                    col += 1
                    world_map[col][row] += 'H'
                player['Y'] += 1
                move = True
                displaymap()
                displaytown()
            else:
                print('End of world please try again')
                move = False

        elif move == 'D' or move == 'd':
            if player['X'] < 7:
                if world_map[col][row] == 'H/T':
                    world_map[col][row] = 'T'
                    row += 1
                    world_map[col][row] += 'H'
                elif world_map[col][row] == 'H':
                    world_map[col][row] = ' '
                    row += 1
                    world_map[col][row] += 'H'
                player['X'] += 1
                move = True
                displaymap()
                displaytown()
            else:
                print('End of world please try again')
                move = False

###########
this code that i use can move the hero only onces and it will be stuck at the spot even if i move it again

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

hi, you can do like this, an extra space has been added every time you move your hero ‘H’, so change the code like this

import os
import yaml
world_map = [['H/T', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', 'T', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', 'T', ' ', ' ', ' '],
             [' ', 'T', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', 'T', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', 'K', ' ']]

player = {'Name': 'The Hero', 'Min Damage': 2, 'Max Damage': 4,'Defence': 1, 'HP': 20, 'Inventory': [], 'fought': False, 'Y': 0, 'X': 0}

day = 1
col = 0
row = 0
player['Y'] = col
player['X'] = row

save = open('C:/test/savegame.csv', 'r+')
print("Welcome to Ratventure!")
print("----------------------")

# Code your main program here
#main text

main_text="1).New Game \n2).Resume Game \n3).Exit Game"

town_text="1) View Character\n2) View Map\n3) Move\n4) Rest\n5) Save Game\n6) Exit Game"


    
def displaymenu():
    global player
    
    print(main_text)
    choice = int(input('Enter choice: '))
    if choice == 1:
        displaytown()
    elif choice == 2:
        resumegame()
        displaytown()
    elif choice == 3:
        print('Exiting game')
    
           
    else:
        print('\nInvalid choice please try again')
        displaymenu()

def resumegame():
    filename = 'C:/test/savegame.csv'
    if not os.path.isfile(filename):
        return {}
    with open(filename) as ifh:
        return yaml.safe_load(ifh)

#town text
def displaytown():
    print()
    global day
    global player
    print('Day {}: You are in a town.'.format(day))
    print(town_text)
    choice = int(input('Enter choice: '))

    if choice == 1:
        print(player.get('Name'))
        print('{:>8} {}-{}'.format("Damage:", player.get('Min Damage'), player.get('Max Damage')))
        print('{:>8} {}'.format('Defence:', player.get('Defence')))
        print('{:>8} {}'.format('HP:', player.get('HP')))
        displaytown()
    if choice == 2:
        displaymap()
        displaytown()
    if choice == 3:
        movehero()
    if choice == 4:
        print('You are fully healed.')
        day += 1
        displaytown()
    if choice == 5:
        print('Game saved.')
        with open(r'C:/test/savegame.csv', 'r+') as data:
            data.write(str(player))
        displaytown()
    if choice == 6:
        'Exiting game.'

#world map
def displaymap():
    global world_map
    for r in world_map:
        print('\n{}+'.format('+---' * 8))
        for c in r:
            print('|{:^3}'.format(c), end='')
    print('\n{}+'.format('+---' * 8))

#move hero
def movehero():
    displaymap()
    global row
    global col
    global world_map
    print('row= ',row)
    print('col=',col)
    move = False
    while not move:
        print('W = up; A = left; S = down; D = right')
        move = str(input('Your move: '))
        if move == 'W' or move == 'w':
            print("map=", world_map[col][row])
            if player['Y'] > 0:
                if world_map[col][row] == 'H/T':
                    world_map[col][row] = 'T'
                    
                    col -= 1
                    world_map[col][row] += 'H'
                elif world_map[col][row] == ' H':
                    world_map[col][row] = ' '
                    col -= 1
                    world_map[col][row] += 'H'
                    if world_map[col][row] == 'TH':
                        world_map[col][row] = 'T/H' 
                elif world_map[col][row] == 'T/H':
                    world_map[col][row] = 'T'
                    row += 1
                    world_map[col][row] += 'H'
                player['Y'] -= 1
                move = True
                displaymap()
                displaytown()
            else:
                print('End of world please try again')
                move = False

        elif move == 'A' or move == 'a':
            print("map=", world_map[col][row])
            if player['X'] > 0:
                if world_map[col][row] == 'H/T':
                    world_map[col][row] = 'T'
                    row -= 1
                    world_map[col][row] += 'H'
                elif world_map[col][row] == ' H':
                    world_map[col][row] = ' '
                    row -= 1
                    world_map[col][row] += 'H'
                    if world_map[col][row] == 'TH':
                        world_map[col][row] = 'T/H' 
                elif world_map[col][row] == 'T/H':
                    world_map[col][row] = 'T'
                    row += 1
                    world_map[col][row] += 'H'
                player['X'] -= 1
                move = True
                displaymap()
                displaytown()
            else:
                print('End of world please try again')
                move = False

        elif move == 'S' or move == 's':
            print("map=", world_map[col][row])
            if player['Y'] < 7:
                if world_map[col][row] == 'H/T':
                    print("move-1")
                    world_map[col][row] = 'T'
                    print("move-2")
                    col += 1
                    world_map[col][row] += 'H'
                    print("move-3")
                elif world_map[col][row] == ' H':
                    print("move-4")
                    world_map[col][row] = ' '
                    print("move-5")
                    col += 1
                    world_map[col][row] += 'H'
                    if world_map[col][row] == 'TH':
                        world_map[col][row] = 'T/H' 
                elif world_map[col][row] == 'T/H':
                    world_map[col][row] = 'T'
                    row += 1
                    world_map[col][row] += 'H'
                player['Y'] += 1
                move = True
                displaymap()
                displaytown()
            else:
                print('End of world please try again')
                move = False

        elif move == 'D' or move == 'd':
            print("map=", world_map[col][row])
            if player['X'] < 7:
                
                    
                if world_map[col][row] == 'H/T':
                    world_map[col][row] = 'T'
                    row += 1
                    world_map[col][row] += 'H'
                    
                    
                elif world_map[col][row] == ' H':
                    world_map[col][row] = ' '
                    row += 1
                    world_map[col][row] += 'H'
                    if world_map[col][row] == 'TH':
                        world_map[col][row] = 'T/H' 
                elif world_map[col][row] == 'T/H':
                    world_map[col][row] = 'T'
                    row += 1
                    world_map[col][row] += 'H'
                    
                
                player['X'] += 1
                move = True
                displaymap()
                displaytown()
            else:
                print('End of world please try again')
                move = False
while True:
    displaymenu()