how to make a loop that doesn't lose the value of a name when it loops in python

I have this code:

import random
money = 50
bet = int(input("You have 50 dolars, how much money would you like to bet?"))
if bet > money:
print("You don't have all that money!")
elif bet <= money:
money = money - bet
guess = int(input("Choose one number in between 1 and 10"))
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
random_numbers = random.choice(numbers)
print("The number drawn was:", random_nada, "!")
if guess == random_number:
money = money + bet +bet
print("Congratulations! You guessed right and doubled you bet! You now have:", ponto, "!")
else:
print("You guessed wrong and lost the value that you bet. You now have:", ponto, ".")
ans = input("Would like to play again?")
if ans == "yes" or ans == " yes": print("You guessed wrong and lost the value that you bet. You now have:", ponto, ".")
ans = input("Would like to play again?")
if ans == "yes" or ans == " yes"
here i wanted the code to restart but without losing the current value of "money", or else the player would just have 50 dolars at the start regardless of how much he won or lost beting along the game.

answered Apr 25 by (250 points)
nvm, i got it
answered Apr 25 by (160 points)

Here i add validator for each entry to avoid the errors in the inputs, next i add a bucle while that works everytime you have money

import random

money = 50

while money>0:

while True:

try:

bet = int(input(f"You have {money} dollars, how much money would you like to bet? "))

if bet > money:

print("You don't have all that money!")

elif bet <= money:

money = money - bet

break

except ValueError:

print("You don't have all that money!")

while True:

try:

guess = int(input("Choose one number in between 1 and 10: "))

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

if guess in numbers:

break

except:

print("You don't choose a correct number")

random_numbers = random.choice(numbers)

print("The number drawn was:", random_numbers, "!")

if guess == random_numbers:

money = money + 2*bet

print("Congratulations! You guessed right and doubled you bet! You now have:", money, "!")

else:

print("You guessed wrong and lost the value that you bet. You now have:", money, ".")

if money == 0:

break

while True:

try:

ans = input("Would like to play again? yes/no: ")

if ans == "yes" or ans == " no":

break

except:

print("You don't wire a correct answer")

if ans == "yes":

print("Let's try again")

else:

print("Goodbye Friend")

break

print("Sorry friend you WASTED")