I've provided the code below.
What is want to do is run the first input box where it will check the condition if true it will go for next input(), but if not it will run the code again. The problem is first input() is running fine, but second one is not getting out of the loop where I'm checking if the input is integer or not
class AC ():
def __init__(self):
self.owner=input("Enter The Name: ")
while True:
if self.owner.isalpha():
self.balance=(input("Enter The Amount: "))
def lol():
while True:
if self.balance.isdigit():
break
else:
print("Enter The Amount: ")
lol()
break
else:
AC()
break
The problem is that your lol()
function is never being called for, so it will stay in the first while-loop indefinitely.
lol()
function is never being called as Tim saidinput()
function return string value you can change str to float `
def __init__(self):
self.owner = input("Enter The Name: ")
while True:
if self.owner.isalpha():
self.balance = input("Enter The Amount: ")
def lol():
while True:
try:
self.balance = float(self.balance)
except ValueError:
break
if self.balance.isdigit():
break
else:
lol()
else:
AC()
break
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.