I am stuck with trying to find out how I am going to do this while-loop inside my try-except.
What I am trying to do it to let the player type in a new number if what he types in is invalid. How things are now, the code only ends with the raise Exception or Exception if the player types in something "wrong", but I want to make a while-loop that lets the player continue to type in a number after the try-except occurs, and then finally print the else when the player entered a valid number.
This is my code (let me know if you need my whole code, but I only need help with the while-loop inside my try-except):
chip_amount = 5
print("\n==== BLACKJACK GAME ====")
print(f'\nYou have currently have {chip_amount} chips available.')
try:
chips_input = int(input("How many chips do you want to bet? "))
if chips_input < 1:
raise Exception("Sorry, you have to enter a number bigger than 1.")
if chips_input > chip_amount:
raise Exception(f'Sorry, you have to enter a number less than {chip_amount}.')
except ValueError:
print("You have to enter a number!")
else:
print(f'\nYou bet {chips_input} chips out of your total of {chip_amount} chips.')
print(f'\nThe cards have been dealt. You have a {" and a ".join(player_hand)}, with a total value of {player_total}.')
print(f'The dealers visible card is a {dealer_hand[0]}, with a value of {dealer_total_sliced}.')