0
well, I have some exercises in python because I am studying, I learned to format strings and use the other tools, however, I could not find a solution not to let the user make a mistake while executing the code, for example, write a string where it should be an integer number. the first part of the exercise does not have a prevention of user error, when I ask the age of the person to register, in other parts the while loop can meet well and does not let the user pass to the next step if the information typed is incorrect. If anyone has a solution that can help me I’d appreciate it.
print(f'REGISTER A PERSON')
conts = 0
conta = 0
cont2 = 0
while True:
print(f'---' * 10)
age = int(input(f'Type a age: '))
sex = ' '
while sex not in 'MmFf':
sex = str(input(f'Type a sex: [M/F] ')).strip().upper()[0]
if age < 18:
conta += 1
if sex in 'M':
conts += 1
if sex in 'F':
if age < 20:
cont2 += 1
q = ' '
while q not in 'YyNn':
q = str(input(f'Do you want to continue? [Y/N] ')).upper().split()[0]
if q == 'N':
break
print(f'The total number of people under 18 is {conta}')
print(f'The total number of man registered is {conts}')
print(f'The total number of womans under 20 years old is {cont2}')