I have this assignment to check if names and an age are input, if they're blank it prompts the user for the input again.
When it gets to the age input if the user enters a blank input then it will prompt them correctly but if a user enters a non-valid input and then enters a blank input again it does not give them the blank input prompt again, just the non-valid input. I'm unsure how to fix this problem.
Here is my code:
import test_module as module
print("\nAssignment 4")
def main():
"""
Collects first name input, checks if input was blank and prompts for entry until entered.
"""
firstname=input("\nPlease enter your first name. ")
while module.is_field_blank(firstname)==False:
print("\nFirst name must be entered.")
firstname=input("\nPlease enter your first name. ")
continue
"""
Collects last name input, checks if input was blank and prompts for entry until entered.
"""
lastname=input("\nPlease enter your last name. ")
while module.is_field_blank(lastname)==False:
print("\nLast name must be entered.")
lastname=input("\nPlease enter your last name. ")
continue
"""
Collects age input, checks if field is blank, if field is not blank checks if field is a number, prompts for entry until entered for both
"""
raw_age=input("\nWhat is your age? ")
while module.is_field_blank(raw_age)==False:
print("\nAge must be entered.")
raw_age=input("\nwhat is your age? ")
continue
while module.is_field_a_number(raw_age)==False:
print("\nAge must be a number.")
raw_age=input("\nWhat is your age? ")
continue
"""
Changes raw_age string to age integer
"""
age=int(raw_age)
"""
Brigns all inputs together, checks against age integer and outputs depending.
"""
if age>40:
print("\nWell, "+firstname+" "+lastname+" it looks like you are over the hill.")
else:
print("\nIt looks like you have many programming years ahead of you "+firstname+" "+lastname)
if __name__ == "__main__":
main()
print("\nEnd of assignment 4")
Here is my module code:
def is_field_blank(arg):
"""
This checks if the field is blank
"""
if arg == "":
return False
else:
return True
def is_field_a_number(yrs):
"""
This checks if the entered field is a number or not
"""
if yrs.isdigit() !=True:
return False
else:
return True