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;
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
add a comment |
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
read onbreak
statement
– anand_v.singh
Mar 28 at 5:17
Please supply all of your code.
– user11093202
Mar 28 at 5:24
add a comment |
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
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
python-3.x
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 onbreak
statement
– anand_v.singh
Mar 28 at 5:17
Please supply all of your code.
– user11093202
Mar 28 at 5:24
add a comment |
read onbreak
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
add a comment |
3 Answers
3
active
oldest
votes
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.)
add a comment |
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
add a comment |
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.") ```
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.)
add a comment |
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.)
add a comment |
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.)
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.)
answered Mar 28 at 5:25
Ethan J.Ethan J.
36410 bronze badges
36410 bronze badges
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Mar 28 at 5:25
user11093202
answered Mar 28 at 5:17
martiniimartinii
10510 bronze badges
10510 bronze badges
add a comment |
add a comment |
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.") ```
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
add a comment |
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.") ```
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
add a comment |
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.") ```
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.") ```
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
read on
break
statement– anand_v.singh
Mar 28 at 5:17
Please supply all of your code.
– user11093202
Mar 28 at 5:24