Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to continue in loop until correct input received
#1
Hi Guys,
Pls help me out !
while(1):
            fname=input("Enter Father's First name")
            fname = fname.lower()
            if(fname.isalpha()):
                addfname(fname)
                fname+=" "
            else:
                print("Sorry Wrong Format, Try Again Please")
in this if Name is not input correctly then else breaks and send the user out instead of asking again correct name.
So How same can be done?
Yoriz wrote May-03-2019, 08:44 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
change
print("Sorry Wrong Format, Try Again Please")
to
break
Quote
#3
Sir I Want to ask the correct name until get. should not break by else
Quote
#4
(May-03-2019, 08:29 PM)sunnyarora Wrote: if Name is not input correctly then else breaks and send the user out instead of asking again correct name.

(May-03-2019, 08:50 PM)sunnyarora Wrote: Sir I Want to ask the correct name until get. should not break by else

Sorry but you need to explain better what it is you want, what defines a correct name?
Quote
#5
Sir,
Basically i want that program should ask the correct name until same is received from user.
program should not go to next line of code or break the program.

as shown in attachment
Yoriz wrote May-03-2019, 09:23 PM:
Please don't post pictures of code, input or output.


Attached Files Thumbnail(s)
   
Quote
#6
Nope still don't understand.
dont_break_program = True # program should not break the program

while True:
    ask_correct_name = input('ask correct name') # program should ask the correct name
    if ask_correct_name == 'same': # until same is received from user
        while dont_break_program:
            pass
        
        next_line = 'program wont go here' # program should not go to next line of code
sunnyarora likes this post
Quote
#7
got Sir Thankyou Smile
Quote
#8
while True:
ask_correct_name = input('ask correct name')  # program should ask the correct name
    if ask_correct_name == 'same':  # until same is received from user
          while True:
               pass
Quote:Sir,
Please explain about second's while True.
What is it doing / Why is it used for?
Quote
#9
The last code I posted is not necessarily what you want but is one way your requirements can be interpreted due to their vagueness.
while True: creates an endless loop because True will always be True.
Quote
#10
Quote:Sir, by which code loop is getting terminated if right input received?

Error:
Sir if I applied below code in my program then function is showing unresolved name (not linking with function)
        while True:
            fname=input("Enter Father's First name")
            fname = fname.lower()
            if(fname.isalpha()):
                addfname(fname)
                while True:
                    pass
Whereas below code is working fine
        while True:
            name=input("Enter Customer First Name")
            name=name.lower()
            if(name.isalpha()):
                addname(name)
                while True:
                    pass
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to Loop my calculator input Michael1 2 114 Dec-13-2019, 04:57 AM
Last Post: ICanIBB
  Invalid JSON payload received. Unknown name “”: Root element must be a message." hellraiser 4 873 Aug-18-2019, 03:41 PM
Last Post: hellraiser
  Server infinite loop input from user tomislav91 1 540 May-23-2019, 02:18 PM
Last Post: heiner55
  assign the variable to every value received serial from Arduino barry76 4 452 Feb-01-2019, 10:19 AM
Last Post: barry76
  How to rerun the program in a loop with different input? bharaths 3 559 Nov-23-2018, 09:36 AM
Last Post: bharaths
  Read from a file, get user input in a while loop lynden 8 1,003 Nov-05-2018, 12:31 PM
Last Post: lynden
  [Help] sorted() in while loop with user's input() {Screenshot attached} vanicci 5 942 Aug-04-2018, 08:59 PM
Last Post: vanicci
  Unexpected input in While Loop fier259 1 613 May-07-2018, 12:47 AM
Last Post: woooee
  QC input value against dictionary in while loop dadgums 2 759 Apr-23-2018, 11:38 PM
Last Post: dadgums
  Python- Help with try: input() except ValueError: Loop code to start of sequence Aldi 2 1,445 Mar-08-2018, 03:46 AM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)