How to use “while True”, and “return False” and how to create a function for themHow to flush output of print function?Why does “not(True) in [False, True]” return False?Python - Make if statement in while loops restart the loop, not the condition?Dual password authentication in Pythonreturning to the start of a while loop in a binary searchTry Except when Return from a function is FalseWhile loop exiting instead of returning back to the top of the loop -PythonPython 3.6 - How to search through a 2D list and return true or false if an item matches user inputPython issue with inputAsking for user input while the program keeps running?

Male viewpoint in an erotic novel

What makes an ending "happy"?

Looking for a big fantasy novel about scholarly monks that sort of worship math?

What are some countries where you can be imprisoned for reading or owning a Bible?

1kV DC Circuit - Insulation on ground wire?

Friend is very nit picky about side comments I don't intend to be taken too seriously

Why are some hotels asking you to book through Booking.com instead of matching the price at the front desk?

GFI outlets tripped after power outage

Who's this voice acting performer?

How should Thaumaturgy's "three times as loud as normal" be interpreted?

What quests do you need to stop at before you make an enemy of a faction for each faction?

Pronounceable encrypted text

Add builder hat to other people with tikzpeople

First Number to Contain Each Letter

Non-standard transposition

Examples where "thin + thin = nice and thick"

Why would one hemisphere of a planet be very mountainous while the other is flat?

Why did Boris Johnson call for new elections?

Project Euler Problem 45

Is there some sort of French saying for "a person's signature move"?

Did the US Climate Reference Network Show No New Warming Since 2005 in the US?

Need help figure out a Fibonacci related math trick

Are there mathematical concepts that exist in the fourth dimension, but not in the third dimension?

What's this constructed number's starter?



How to use “while True”, and “return False” and how to create a function for them


How to flush output of print function?Why does “not(True) in [False, True]” return False?Python - Make if statement in while loops restart the loop, not the condition?Dual password authentication in Pythonreturning to the start of a while loop in a binary searchTry Except when Return from a function is FalseWhile loop exiting instead of returning back to the top of the loop -PythonPython 3.6 - How to search through a 2D list and return true or false if an item matches user inputPython issue with inputAsking for user input while the program keeps running?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















When someone enters an incorrect password I want to loop user input, but if they get it correct I want it to stop looping.



return False I need a function for return but I don't know where or what to make it as



while True:
userInput = input("Pass:")
if userInput == password:
print("Correct, welcome to Fahuk Console.")
print("Type "help" for a list of commands.")
userInput = input("-")
else:
print("Incorrect password.") ```


I want to be able to enter a correct password and not have it ask me again










share|improve this question


























  • read on break statement

    – anand_v.singh
    Mar 28 at 5:17











  • Please supply all of your code.

    – user11093202
    Mar 28 at 5:24

















-1















When someone enters an incorrect password I want to loop user input, but if they get it correct I want it to stop looping.



return False I need a function for return but I don't know where or what to make it as



while True:
userInput = input("Pass:")
if userInput == password:
print("Correct, welcome to Fahuk Console.")
print("Type "help" for a list of commands.")
userInput = input("-")
else:
print("Incorrect password.") ```


I want to be able to enter a correct password and not have it ask me again










share|improve this question


























  • read on break statement

    – anand_v.singh
    Mar 28 at 5:17











  • Please supply all of your code.

    – user11093202
    Mar 28 at 5:24













-1












-1








-1


0






When someone enters an incorrect password I want to loop user input, but if they get it correct I want it to stop looping.



return False I need a function for return but I don't know where or what to make it as



while True:
userInput = input("Pass:")
if userInput == password:
print("Correct, welcome to Fahuk Console.")
print("Type "help" for a list of commands.")
userInput = input("-")
else:
print("Incorrect password.") ```


I want to be able to enter a correct password and not have it ask me again










share|improve this question
















When someone enters an incorrect password I want to loop user input, but if they get it correct I want it to stop looping.



return False I need a function for return but I don't know where or what to make it as



while True:
userInput = input("Pass:")
if userInput == password:
print("Correct, welcome to Fahuk Console.")
print("Type "help" for a list of commands.")
userInput = input("-")
else:
print("Incorrect password.") ```


I want to be able to enter a correct password and not have it ask me again







python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 5:14









A.A Noman

1,7635 gold badges16 silver badges30 bronze badges




1,7635 gold badges16 silver badges30 bronze badges










asked Mar 28 at 5:02









fAHUKfAHUK

82 bronze badges




82 bronze badges















  • read on break statement

    – anand_v.singh
    Mar 28 at 5:17











  • Please supply all of your code.

    – user11093202
    Mar 28 at 5:24

















  • read on break statement

    – anand_v.singh
    Mar 28 at 5:17











  • Please supply all of your code.

    – user11093202
    Mar 28 at 5:24
















read on break statement

– anand_v.singh
Mar 28 at 5:17





read on break statement

– anand_v.singh
Mar 28 at 5:17













Please supply all of your code.

– user11093202
Mar 28 at 5:24





Please supply all of your code.

– user11093202
Mar 28 at 5:24












3 Answers
3






active

oldest

votes


















0
















while will continue to execute the code it's given until the condition placed after it is false or until break is used to immediately exit the loop.



Try this:



while input('Please enter your password:') != password:
print('Incorrect password.')
print('Correct, welcome to Fahuk Console.')
# ...


Or if you want to use while True, this:



while True:
if input('Please enter your password') == password:
break
print('Incorrect password.')
print('Correct, welcome to Fahuk Console.')
# ...


(When you store a real password, you shouldn't store the password itself, but instead a difficult-to-reverse hash of that password. You might import hashlib and then instead of comparing input() to the password, you might compare hashlib.sha256(input()).hexdigest() to the password's SHA-256 hash.)






share|improve this answer
































    1
















    Use this code:



    while True:
    userInput = input("Pass:")
    if userInput == password:
    print("Correct, welcome to Fahuk Console.")
    print("Type "help" for a list of commands.")
    userInput = input("-")
    break
    else:
    print("Incorrect password.")


    Use the break keyword






    share|improve this answer


































      0
















      Simplest way would be to use a break condition. Loops iterate over a block of code until an expression is false. Since your expression is always true, break would need to be used to terminate the current iteration/loop.



       while True:
      userInput = input("Pass:")
      if userInput == password:
      print("Correct, welcome to Fahuk Console.")
      print("Type "help" for a list of commands.")
      userInput = input("-")
      break
      else:
      print("Incorrect password.") ```





      share|improve this answer

























      • This answers is exactly the same as @martinii 's answer , plus the function part that the OP wanted is missing

        – anand_v.singh
        Mar 28 at 5:20













      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );














      draft saved

      draft discarded
















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390496%2fhow-to-use-while-true-and-return-false-and-how-to-create-a-function-for-the%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0
















      while will continue to execute the code it's given until the condition placed after it is false or until break is used to immediately exit the loop.



      Try this:



      while input('Please enter your password:') != password:
      print('Incorrect password.')
      print('Correct, welcome to Fahuk Console.')
      # ...


      Or if you want to use while True, this:



      while True:
      if input('Please enter your password') == password:
      break
      print('Incorrect password.')
      print('Correct, welcome to Fahuk Console.')
      # ...


      (When you store a real password, you shouldn't store the password itself, but instead a difficult-to-reverse hash of that password. You might import hashlib and then instead of comparing input() to the password, you might compare hashlib.sha256(input()).hexdigest() to the password's SHA-256 hash.)






      share|improve this answer





























        0
















        while will continue to execute the code it's given until the condition placed after it is false or until break is used to immediately exit the loop.



        Try this:



        while input('Please enter your password:') != password:
        print('Incorrect password.')
        print('Correct, welcome to Fahuk Console.')
        # ...


        Or if you want to use while True, this:



        while True:
        if input('Please enter your password') == password:
        break
        print('Incorrect password.')
        print('Correct, welcome to Fahuk Console.')
        # ...


        (When you store a real password, you shouldn't store the password itself, but instead a difficult-to-reverse hash of that password. You might import hashlib and then instead of comparing input() to the password, you might compare hashlib.sha256(input()).hexdigest() to the password's SHA-256 hash.)






        share|improve this answer



























          0














          0










          0









          while will continue to execute the code it's given until the condition placed after it is false or until break is used to immediately exit the loop.



          Try this:



          while input('Please enter your password:') != password:
          print('Incorrect password.')
          print('Correct, welcome to Fahuk Console.')
          # ...


          Or if you want to use while True, this:



          while True:
          if input('Please enter your password') == password:
          break
          print('Incorrect password.')
          print('Correct, welcome to Fahuk Console.')
          # ...


          (When you store a real password, you shouldn't store the password itself, but instead a difficult-to-reverse hash of that password. You might import hashlib and then instead of comparing input() to the password, you might compare hashlib.sha256(input()).hexdigest() to the password's SHA-256 hash.)






          share|improve this answer













          while will continue to execute the code it's given until the condition placed after it is false or until break is used to immediately exit the loop.



          Try this:



          while input('Please enter your password:') != password:
          print('Incorrect password.')
          print('Correct, welcome to Fahuk Console.')
          # ...


          Or if you want to use while True, this:



          while True:
          if input('Please enter your password') == password:
          break
          print('Incorrect password.')
          print('Correct, welcome to Fahuk Console.')
          # ...


          (When you store a real password, you shouldn't store the password itself, but instead a difficult-to-reverse hash of that password. You might import hashlib and then instead of comparing input() to the password, you might compare hashlib.sha256(input()).hexdigest() to the password's SHA-256 hash.)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 28 at 5:25









          Ethan J.Ethan J.

          36410 bronze badges




          36410 bronze badges


























              1
















              Use this code:



              while True:
              userInput = input("Pass:")
              if userInput == password:
              print("Correct, welcome to Fahuk Console.")
              print("Type "help" for a list of commands.")
              userInput = input("-")
              break
              else:
              print("Incorrect password.")


              Use the break keyword






              share|improve this answer































                1
















                Use this code:



                while True:
                userInput = input("Pass:")
                if userInput == password:
                print("Correct, welcome to Fahuk Console.")
                print("Type "help" for a list of commands.")
                userInput = input("-")
                break
                else:
                print("Incorrect password.")


                Use the break keyword






                share|improve this answer





























                  1














                  1










                  1









                  Use this code:



                  while True:
                  userInput = input("Pass:")
                  if userInput == password:
                  print("Correct, welcome to Fahuk Console.")
                  print("Type "help" for a list of commands.")
                  userInput = input("-")
                  break
                  else:
                  print("Incorrect password.")


                  Use the break keyword






                  share|improve this answer















                  Use this code:



                  while True:
                  userInput = input("Pass:")
                  if userInput == password:
                  print("Correct, welcome to Fahuk Console.")
                  print("Type "help" for a list of commands.")
                  userInput = input("-")
                  break
                  else:
                  print("Incorrect password.")


                  Use the break keyword







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 28 at 5:25







                  user11093202

















                  answered Mar 28 at 5:17









                  martiniimartinii

                  10510 bronze badges




                  10510 bronze badges
























                      0
















                      Simplest way would be to use a break condition. Loops iterate over a block of code until an expression is false. Since your expression is always true, break would need to be used to terminate the current iteration/loop.



                       while True:
                      userInput = input("Pass:")
                      if userInput == password:
                      print("Correct, welcome to Fahuk Console.")
                      print("Type "help" for a list of commands.")
                      userInput = input("-")
                      break
                      else:
                      print("Incorrect password.") ```





                      share|improve this answer

























                      • This answers is exactly the same as @martinii 's answer , plus the function part that the OP wanted is missing

                        – anand_v.singh
                        Mar 28 at 5:20















                      0
















                      Simplest way would be to use a break condition. Loops iterate over a block of code until an expression is false. Since your expression is always true, break would need to be used to terminate the current iteration/loop.



                       while True:
                      userInput = input("Pass:")
                      if userInput == password:
                      print("Correct, welcome to Fahuk Console.")
                      print("Type "help" for a list of commands.")
                      userInput = input("-")
                      break
                      else:
                      print("Incorrect password.") ```





                      share|improve this answer

























                      • This answers is exactly the same as @martinii 's answer , plus the function part that the OP wanted is missing

                        – anand_v.singh
                        Mar 28 at 5:20













                      0














                      0










                      0









                      Simplest way would be to use a break condition. Loops iterate over a block of code until an expression is false. Since your expression is always true, break would need to be used to terminate the current iteration/loop.



                       while True:
                      userInput = input("Pass:")
                      if userInput == password:
                      print("Correct, welcome to Fahuk Console.")
                      print("Type "help" for a list of commands.")
                      userInput = input("-")
                      break
                      else:
                      print("Incorrect password.") ```





                      share|improve this answer













                      Simplest way would be to use a break condition. Loops iterate over a block of code until an expression is false. Since your expression is always true, break would need to be used to terminate the current iteration/loop.



                       while True:
                      userInput = input("Pass:")
                      if userInput == password:
                      print("Correct, welcome to Fahuk Console.")
                      print("Type "help" for a list of commands.")
                      userInput = input("-")
                      break
                      else:
                      print("Incorrect password.") ```






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 28 at 5:18









                      JesseJesse

                      9141 gold badge10 silver badges17 bronze badges




                      9141 gold badge10 silver badges17 bronze badges















                      • This answers is exactly the same as @martinii 's answer , plus the function part that the OP wanted is missing

                        – anand_v.singh
                        Mar 28 at 5:20

















                      • This answers is exactly the same as @martinii 's answer , plus the function part that the OP wanted is missing

                        – anand_v.singh
                        Mar 28 at 5:20
















                      This answers is exactly the same as @martinii 's answer , plus the function part that the OP wanted is missing

                      – anand_v.singh
                      Mar 28 at 5:20





                      This answers is exactly the same as @martinii 's answer , plus the function part that the OP wanted is missing

                      – anand_v.singh
                      Mar 28 at 5:20


















                      draft saved

                      draft discarded















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390496%2fhow-to-use-while-true-and-return-false-and-how-to-create-a-function-for-the%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현