Struggling to get ValueError to work in python 3 guessing game The 2019 Stack Overflow...
Does Parliament hold absolute power in the UK?
Take groceries in checked luggage
Converting from Markdown-with-biblatex-commands to LaTeX
Did the new image of black hole confirm the general theory of relativity?
He got a vote 80% that of Emmanuel Macron’s
The following signatures were invalid: EXPKEYSIG 1397BC53640DB551
Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?
Do working physicists consider Newtonian mechanics to be "falsified"?
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
RT6224D-based step down circuit yields 0V - why?
Road tyres vs "Street" tyres for charity ride on MTB Tandem
Simulating Exploding Dice
How do I add random spotting to the same face in cycles?
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
What aspect of planet Earth must be changed to prevent the industrial revolution?
how can a perfect fourth interval be considered either consonant or dissonant?
Why not take a picture of a closer black hole?
Finding the path in a graph from A to B then back to A with a minimum of shared edges
Derivation tree not rendering
Single author papers against my advisor's will?
Change bounding box of math glyphs in LuaTeX
Semisimplicity of the category of coherent sheaves?
Do warforged have souls?
A pet rabbit called Belle
Struggling to get ValueError to work in python 3 guessing game
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Guessing Game in PythonNumber guessing game for beginnersBeginner - Guessing GamePython number guessing gamePython guessing gameBeginning guessing game in PythonBeginning Python guessing gameGuessing Number(s) Game in PythonNumber guessing game learncpp.com challenge C++Guess-the-number game by a Python beginner
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
I have followed a tutorial to create a guessing game in python 3 and i thought i could make it better so i created a timed intro with error inputs recognition and it all seemed to be going well.
However, when i came time to ensure when a player inputted anything other than a number(IE exception handling) it just fails out.
The game it self functions just not the non integer in the guessgame
I have tried the following with ValueError:
- if, else
- try, except
- if guess == ValueError
All to no avail, anyway, code is below. Any help to solve this would be much appreciated.
import time
def guessgame():
import random # brings in random generator
number = random.randint(1, 20) # assigns random value between 1, 20
numofguesses = 0 # sets number of guesses to 0
print("Hello what is your name?")
name = input()
print("The number i am thinking of is between 1 and 20", name) # user
defined name
for numofguesses in range(6):# if number of guesses left is less that 6
do the following
print("Take a guess")
guess = input() # assign guess variable to user input
guess = int(guess) # ensures guess is an number
if guess < number:
print("Number is too low!")
if guess > number:
print("Number is too high!")
if guess == number:
break
else:
if ValueError:#THIS IS THE JERK THAT DOESNT WORK!!!!
print("Please enter a number")
if guess == number:
numofguesses = str(numofguesses)
print("Well done", name, "You guessed the number in: ", numofguesses)
gameiniate()
if guess != number:
number = str(number)
print(" Wrong! unlucky, the number was: ", number)
def gameiniate():
print("Would you like to play a game? Yes or No")
game = input().lower()
yeschoice = ("yes", "y")
nochoice = ("no", "n")
if game in yeschoice:
guessgame()
elif game in nochoice: # command to exit script if no or n typed
print("thats too bad")
print("type exit to close")
if input() == "exit":
exit()
else:
print("Please respond with Yes or No")
gameiniate()
time.sleep(4)
gameiniate()
python-3.x number-guessing-game
New contributor
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I have followed a tutorial to create a guessing game in python 3 and i thought i could make it better so i created a timed intro with error inputs recognition and it all seemed to be going well.
However, when i came time to ensure when a player inputted anything other than a number(IE exception handling) it just fails out.
The game it self functions just not the non integer in the guessgame
I have tried the following with ValueError:
- if, else
- try, except
- if guess == ValueError
All to no avail, anyway, code is below. Any help to solve this would be much appreciated.
import time
def guessgame():
import random # brings in random generator
number = random.randint(1, 20) # assigns random value between 1, 20
numofguesses = 0 # sets number of guesses to 0
print("Hello what is your name?")
name = input()
print("The number i am thinking of is between 1 and 20", name) # user
defined name
for numofguesses in range(6):# if number of guesses left is less that 6
do the following
print("Take a guess")
guess = input() # assign guess variable to user input
guess = int(guess) # ensures guess is an number
if guess < number:
print("Number is too low!")
if guess > number:
print("Number is too high!")
if guess == number:
break
else:
if ValueError:#THIS IS THE JERK THAT DOESNT WORK!!!!
print("Please enter a number")
if guess == number:
numofguesses = str(numofguesses)
print("Well done", name, "You guessed the number in: ", numofguesses)
gameiniate()
if guess != number:
number = str(number)
print(" Wrong! unlucky, the number was: ", number)
def gameiniate():
print("Would you like to play a game? Yes or No")
game = input().lower()
yeschoice = ("yes", "y")
nochoice = ("no", "n")
if game in yeschoice:
guessgame()
elif game in nochoice: # command to exit script if no or n typed
print("thats too bad")
print("type exit to close")
if input() == "exit":
exit()
else:
print("Please respond with Yes or No")
gameiniate()
time.sleep(4)
gameiniate()
python-3.x number-guessing-game
New contributor
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I have followed a tutorial to create a guessing game in python 3 and i thought i could make it better so i created a timed intro with error inputs recognition and it all seemed to be going well.
However, when i came time to ensure when a player inputted anything other than a number(IE exception handling) it just fails out.
The game it self functions just not the non integer in the guessgame
I have tried the following with ValueError:
- if, else
- try, except
- if guess == ValueError
All to no avail, anyway, code is below. Any help to solve this would be much appreciated.
import time
def guessgame():
import random # brings in random generator
number = random.randint(1, 20) # assigns random value between 1, 20
numofguesses = 0 # sets number of guesses to 0
print("Hello what is your name?")
name = input()
print("The number i am thinking of is between 1 and 20", name) # user
defined name
for numofguesses in range(6):# if number of guesses left is less that 6
do the following
print("Take a guess")
guess = input() # assign guess variable to user input
guess = int(guess) # ensures guess is an number
if guess < number:
print("Number is too low!")
if guess > number:
print("Number is too high!")
if guess == number:
break
else:
if ValueError:#THIS IS THE JERK THAT DOESNT WORK!!!!
print("Please enter a number")
if guess == number:
numofguesses = str(numofguesses)
print("Well done", name, "You guessed the number in: ", numofguesses)
gameiniate()
if guess != number:
number = str(number)
print(" Wrong! unlucky, the number was: ", number)
def gameiniate():
print("Would you like to play a game? Yes or No")
game = input().lower()
yeschoice = ("yes", "y")
nochoice = ("no", "n")
if game in yeschoice:
guessgame()
elif game in nochoice: # command to exit script if no or n typed
print("thats too bad")
print("type exit to close")
if input() == "exit":
exit()
else:
print("Please respond with Yes or No")
gameiniate()
time.sleep(4)
gameiniate()
python-3.x number-guessing-game
New contributor
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
I have followed a tutorial to create a guessing game in python 3 and i thought i could make it better so i created a timed intro with error inputs recognition and it all seemed to be going well.
However, when i came time to ensure when a player inputted anything other than a number(IE exception handling) it just fails out.
The game it self functions just not the non integer in the guessgame
I have tried the following with ValueError:
- if, else
- try, except
- if guess == ValueError
All to no avail, anyway, code is below. Any help to solve this would be much appreciated.
import time
def guessgame():
import random # brings in random generator
number = random.randint(1, 20) # assigns random value between 1, 20
numofguesses = 0 # sets number of guesses to 0
print("Hello what is your name?")
name = input()
print("The number i am thinking of is between 1 and 20", name) # user
defined name
for numofguesses in range(6):# if number of guesses left is less that 6
do the following
print("Take a guess")
guess = input() # assign guess variable to user input
guess = int(guess) # ensures guess is an number
if guess < number:
print("Number is too low!")
if guess > number:
print("Number is too high!")
if guess == number:
break
else:
if ValueError:#THIS IS THE JERK THAT DOESNT WORK!!!!
print("Please enter a number")
if guess == number:
numofguesses = str(numofguesses)
print("Well done", name, "You guessed the number in: ", numofguesses)
gameiniate()
if guess != number:
number = str(number)
print(" Wrong! unlucky, the number was: ", number)
def gameiniate():
print("Would you like to play a game? Yes or No")
game = input().lower()
yeschoice = ("yes", "y")
nochoice = ("no", "n")
if game in yeschoice:
guessgame()
elif game in nochoice: # command to exit script if no or n typed
print("thats too bad")
print("type exit to close")
if input() == "exit":
exit()
else:
print("Please respond with Yes or No")
gameiniate()
time.sleep(4)
gameiniate()
python-3.x number-guessing-game
python-3.x number-guessing-game
New contributor
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 9 mins ago
Nerdalert3000Nerdalert3000
1
1
New contributor
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Nerdalert3000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
0
active
oldest
votes
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: "196"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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/3.0/"u003ecc by-sa 3.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
});
}
});
Nerdalert3000 is a new contributor. Be nice, and check out our Code of Conduct.
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%2fcodereview.stackexchange.com%2fquestions%2f217414%2fstruggling-to-get-valueerror-to-work-in-python-3-guessing-game%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Nerdalert3000 is a new contributor. Be nice, and check out our Code of Conduct.
Nerdalert3000 is a new contributor. Be nice, and check out our Code of Conduct.
Nerdalert3000 is a new contributor. Be nice, and check out our Code of Conduct.
Nerdalert3000 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
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%2fcodereview.stackexchange.com%2fquestions%2f217414%2fstruggling-to-get-valueerror-to-work-in-python-3-guessing-game%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