I have a code to make a banking app. I need to make sure that the input can take in any number including decimals but not take in letters or other symbols.
Ive tried using a float instead of int
if selection == 1:
if initial_balance > 1:
print("\nAn account has already been opened. Please select another
option.")
print(menu)
else:
name = input("\nEnter the account owner's name: ")
# While loop to make sure user puts valid initial deposite
while True:
initial_balance = input("Enter your initial balanc: $")
try:
float(initial_balance)
except ValueError:
print("Sorry, Please deposit one or more dollars.")
continue
if initial_balance < 1:
print("Please deposit one or more dollars.")
continue
else:
balance += initial_balance
print("\nAccount owner: " + name)
account = BankAccount(initial_balance)
print("Initial balance: $ " + str(initial_balance))
print(menu)
break
break
expected: enter an initial balance : 20.75
account owner: jimmy initial balance: $20.75
actual:
enter an initial balance : $20.75
sorry please deposit one or more dollars