May-31-2020, 04:16 PM
(May-31-2020, 03:17 PM)ibutun Wrote: this programme work perfect but when i enter my name like 15.1 (float) is says:
is this float is not a digit ?
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.
The isdigit() method only returns True if every character in the string is a digit. The '.' in a float value is not a digit, so isdigit() returns False for a float. You can use isalpha() to make sure all of the characters are letters, or you could use isalpha() and istitle() together to ensure the first letter is capitalized. (You could also just use istitle() in your print statement like menator01 does.)
while True: my_name = input('What is your name? ') if not my_name.isalpha(): print('Please use only letters for your name.') continue else: print(f'Your name is {my_name}.') print('The length of your name is', len(my_name), 'characters.') break while True: try: my_age = int(input(f'What is your age, {my_name}? ')) print('Your age is ' + str(my_age) + '.') print('You will be ' + str(my_age + 1) + ' in one year.') break except ValueError: print('Please use only whole numbers for your age.') continue