Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

+7 votes
asked Apr 23 by trash disposal (230 points)
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.

1 Answer

0 votes
answered Apr 25 by trash disposal (230 points)
nvm, i got it
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...