How to stop repeating lines in a while loop
Question:
my code:
def login():
print("Welcome to David's and John's Tenant Management System!")
print("(1)Admin (2)Customer (3)Exit")
while True:
if selection() == "1":
print("f") # admin login
if selection() == "2":
print("Are you an existing user? Enter 1 if YES, 2 for NO.")
break
login()
output:
Welcome to David's and John's Tenant Management System!
(1)Admin (2)Customer (3)Exit
Please enter a number: 2
Please enter a number: 2
it keeps on repeating "Please enter a number" twice, instead of once. Sorry if I’m asking a dumb question.
Answers:
you didn’t show your function selection()
but looks like you can fix your code next way:
while True:
selected = selection()
if selected == "1":
print("f") # admin login
elif selected == "2":
print("Are you an existing user? Enter 1 if YES, 2 for NO.")
break
my code:
def login():
print("Welcome to David's and John's Tenant Management System!")
print("(1)Admin (2)Customer (3)Exit")
while True:
if selection() == "1":
print("f") # admin login
if selection() == "2":
print("Are you an existing user? Enter 1 if YES, 2 for NO.")
break
login()
output:
Welcome to David's and John's Tenant Management System!
(1)Admin (2)Customer (3)Exit
Please enter a number: 2
Please enter a number: 2
it keeps on repeating "Please enter a number" twice, instead of once. Sorry if I’m asking a dumb question.
you didn’t show your function selection()
but looks like you can fix your code next way:
while True:
selected = selection()
if selected == "1":
print("f") # admin login
elif selected == "2":
print("Are you an existing user? Enter 1 if YES, 2 for NO.")
break