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
  Invalid JSON payload received. Unknown name “”: Root element must be a message." hellraiser 4 149 Aug-18-2019, 03:41 PM
Last Post: hellraiser
  Not quite getting the correct Output from a function twinpiques 3 156 Aug-04-2019, 11:53 PM
Last Post: twinpiques
  read text file and write into html with correct link jacklee26 4 153 Aug-02-2019, 05:48 AM
Last Post: jacklee26
  Help with finding correct topic in Python learning yahya01 1 282 Jun-06-2019, 05:01 PM
Last Post: buran
  error using 'continue' in my code ilcaa72 1 138 Jun-05-2019, 08:05 PM
Last Post: vindo
  Server infinite loop input from user tomislav91 1 408 May-23-2019, 02:18 PM
Last Post: heiner55
  Com Error with macro within for loop due to creating new workbook in the loop Lastwizzle 0 136 May-18-2019, 09:29 PM
Last Post: Lastwizzle
  Return in correct json format UtiliseIT 3 343 May-13-2019, 11:24 AM
Last Post: snippsat
  How "continue" in another indentation? CaptainCsaba 6 304 May-07-2019, 10:38 AM
Last Post: avorane
  How to continue after "return" Helmi 4 400 Mar-17-2019, 09:26 PM
Last Post: Helmi

Forum Jump:


Users browsing this thread: 1 Guest(s)