May-31-2020, 03:17 PM
(May-31-2020, 02:52 PM)menator01 Wrote: Another way. Modified code a little.
#! /usr/bin/env python3.8 while True: try: my_name = input('What is your name: ') if my_name.isdigit(): print(f'{my_name} is a number. Please use letters for a name.') continue else: print(f'Your name is {my_name}. It\'s nice to meet you') print(f'The length of your name is {len(my_name)} letters.') break except ValueError as error: print(f'Error: {error}') break while True: try: my_age = input('What is your age: ') if my_age.isalpha(): print(f'{my_age} is not allowed in age') continue else: age = int(my_age) + 1 print(f'You will be {age} next year.') break except ValueError as error: print(f'Error: {error}') break print(f'{my_name.title()} will be {age} next year.')
Friend i want to do like this... Thank you I understood the working logic of some codes like x.isalpha(): , y.isdigit():, while loop must be end with except code, and also When the application is finished, we have to use the "break" command to switch to the other application.
But i ask another question
this programme work perfect but when i enter my name like 15.1 (float) is says:
Output:What is your name: 15.1
Your name is 15.1. It's nice to meet you
The length of your name is 4 letters.
is this float is not a digit ?