Python Forum
if the input is not number, let user input again
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if the input is not number, let user input again
#7
print('hello there')
print('what is your name?')
while True:
    myName = input()
    try:
        if str(myName) == True:
            print('your name is ' + myName + ', it is nice to meet you')
            print('the length of your name is composed of ' + str(len(myName)) + ' letters.')
        else:
            print('Please use the alphabet instead of the number')
         
        continue
        print('what is your age?')
 
        while True:
            myAge = input()
            try:
                myAge = int(myAge)
                print('thank you')
            except ValueError:
                print(f"{myAge} isn't a number. Please enter a number!")
        pass
    except:
        print('thank you') 
        print('you will be ' + str(int(myAge) + 1) + ' next year')
        print('this is the end of this program')
it works but it ends first loop and print wrong sentences and don't ask second question also...
Output:
hello there [b]what is your name?[/b] Samuel [b]Please use the alphabet instead of the number[/b]
Reply


Messages In This Thread
RE: if the input is not number, let user input again - by ibutun - May-31-2020, 02:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 1,051 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  Help with to check an Input list data with a data read from an external source sacharyya 3 408 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  difference between forms of input a list to function akbarza 6 1,031 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  pyaudio seems to randomly halt input. elpidiovaldez5 2 369 Jan-22-2024, 09:07 AM
Last Post: elpidiovaldez5
  Receive Input on Same Line? johnywhy 8 719 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  manually input data jpatierno 0 344 Nov-10-2023, 02:32 AM
Last Post: jpatierno
  Using string input for boolean tronic72 3 694 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
  problem in using input command akbarza 4 1,130 Oct-19-2023, 03:27 PM
Last Post: popejose
  problem in entering address of a file in input akbarza 0 651 Oct-18-2023, 08:16 AM
Last Post: akbarza
  Input network device connection info from data file edroche3rd 6 1,023 Oct-12-2023, 02:18 AM
Last Post: edroche3rd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020