Hangman help: invalid print statement
up vote
-6
down vote
favorite
My Hangman code has errors on line 40 , line 40
print ('_'+ end=' ')
My code:
import time
import random
print('Lets play hangman')
print("""
_______
| |
| O
| |
| - -/
| |
| | |
| | |
____|____
""")
random_words = ['string', 'loop', 'python', 'print', 'run' , 'graphics window', 'variable', 'iteration', 'modules', 'module', 'input', 'logic', 'output ']
time.sleep(2)
print ("What level would you like to play at? Too bad, you get random! Better type it in tho...")
level_of_difficulty = "Random"
time.sleep(2)
print ("The program is now generating your word...")
if level_of_difficulty == 'Random':
generated_word = random.choice(random_words)
guessed = ''
lives = 7
while lives > 0:
missed = 0
print()
for letter in generated_word:
if letter in guessed:
print("Congrats ya dumb animal, you got one")
else:
print ('_'+ end=' ')
missed = missed + 1
if missed == 0:
print ('nnYou win!')
quit()
break
guess=input("Well what are you waiting for? guess a letter!:")
guessed = guessed + guess
if guess not in generated_word:
print ('n People like you are the reason why the human race will fail')
print ('Fool')
lives = lives - 1
missed = missed + 1
print('your new lives value is ' + str(lives))
if lives < 7:
print(''' _______
| | ''')
if lives < 6:
print(' | O ')
if lives < 5:
print(' | | ')
if lives < 4:
print(' | - -/ ')
if lives < 3:
print(' | | ')
if lives < 2:
print(' | | | ')
if lives < 1:
print(' | | | ')
if lives == 0:
print('___|___ ')
print('Game Over Boi')
print('The secret word was ' + str(generated_word) + "fool")
quit()
python
|
show 6 more comments
up vote
-6
down vote
favorite
My Hangman code has errors on line 40 , line 40
print ('_'+ end=' ')
My code:
import time
import random
print('Lets play hangman')
print("""
_______
| |
| O
| |
| - -/
| |
| | |
| | |
____|____
""")
random_words = ['string', 'loop', 'python', 'print', 'run' , 'graphics window', 'variable', 'iteration', 'modules', 'module', 'input', 'logic', 'output ']
time.sleep(2)
print ("What level would you like to play at? Too bad, you get random! Better type it in tho...")
level_of_difficulty = "Random"
time.sleep(2)
print ("The program is now generating your word...")
if level_of_difficulty == 'Random':
generated_word = random.choice(random_words)
guessed = ''
lives = 7
while lives > 0:
missed = 0
print()
for letter in generated_word:
if letter in guessed:
print("Congrats ya dumb animal, you got one")
else:
print ('_'+ end=' ')
missed = missed + 1
if missed == 0:
print ('nnYou win!')
quit()
break
guess=input("Well what are you waiting for? guess a letter!:")
guessed = guessed + guess
if guess not in generated_word:
print ('n People like you are the reason why the human race will fail')
print ('Fool')
lives = lives - 1
missed = missed + 1
print('your new lives value is ' + str(lives))
if lives < 7:
print(''' _______
| | ''')
if lives < 6:
print(' | O ')
if lives < 5:
print(' | | ')
if lives < 4:
print(' | - -/ ')
if lives < 3:
print(' | | ')
if lives < 2:
print(' | | | ')
if lives < 1:
print(' | | | ')
if lives == 0:
print('___|___ ')
print('Game Over Boi')
print('The secret word was ' + str(generated_word) + "fool")
quit()
python
what version of python are you using, and what is the exact error message?
– wpercy
Nov 9 at 19:51
lemme check on that
– Timothy Johnson
Nov 9 at 19:51
3
Well, you haven't actually asked a question. You've basically just said, "here's my code, figure out what's wrong." What you should do instead is say, here's my code; i'm getting an error on line XXX, and here's the error message, and here's what I've tried to do to fix it. In other words: stackoverflow.com/help/how-to-ask
– Kenneth K.
Nov 9 at 19:51
3
@TimothyJohnson hate is the wrong word, but there are a few things wrong with your post. firstly: please include a Minimal Complete Verifiable Example (the only thing missing is theminimalpart). secondly, don't call for sympathy with phrases like "I'm new to $Language or $Concept". thirdly, include the errors you're getting, don't just say that you're getting errors. and, lastly: don't ever write things likeplease help me, um... yeah.
– Tilman B. aka Nerdyyy
Nov 9 at 19:52
1
@TimothyJohnson if you're using python 2.x you can't passend=as an argument to the print function.
– wpercy
Nov 9 at 19:57
|
show 6 more comments
up vote
-6
down vote
favorite
up vote
-6
down vote
favorite
My Hangman code has errors on line 40 , line 40
print ('_'+ end=' ')
My code:
import time
import random
print('Lets play hangman')
print("""
_______
| |
| O
| |
| - -/
| |
| | |
| | |
____|____
""")
random_words = ['string', 'loop', 'python', 'print', 'run' , 'graphics window', 'variable', 'iteration', 'modules', 'module', 'input', 'logic', 'output ']
time.sleep(2)
print ("What level would you like to play at? Too bad, you get random! Better type it in tho...")
level_of_difficulty = "Random"
time.sleep(2)
print ("The program is now generating your word...")
if level_of_difficulty == 'Random':
generated_word = random.choice(random_words)
guessed = ''
lives = 7
while lives > 0:
missed = 0
print()
for letter in generated_word:
if letter in guessed:
print("Congrats ya dumb animal, you got one")
else:
print ('_'+ end=' ')
missed = missed + 1
if missed == 0:
print ('nnYou win!')
quit()
break
guess=input("Well what are you waiting for? guess a letter!:")
guessed = guessed + guess
if guess not in generated_word:
print ('n People like you are the reason why the human race will fail')
print ('Fool')
lives = lives - 1
missed = missed + 1
print('your new lives value is ' + str(lives))
if lives < 7:
print(''' _______
| | ''')
if lives < 6:
print(' | O ')
if lives < 5:
print(' | | ')
if lives < 4:
print(' | - -/ ')
if lives < 3:
print(' | | ')
if lives < 2:
print(' | | | ')
if lives < 1:
print(' | | | ')
if lives == 0:
print('___|___ ')
print('Game Over Boi')
print('The secret word was ' + str(generated_word) + "fool")
quit()
python
My Hangman code has errors on line 40 , line 40
print ('_'+ end=' ')
My code:
import time
import random
print('Lets play hangman')
print("""
_______
| |
| O
| |
| - -/
| |
| | |
| | |
____|____
""")
random_words = ['string', 'loop', 'python', 'print', 'run' , 'graphics window', 'variable', 'iteration', 'modules', 'module', 'input', 'logic', 'output ']
time.sleep(2)
print ("What level would you like to play at? Too bad, you get random! Better type it in tho...")
level_of_difficulty = "Random"
time.sleep(2)
print ("The program is now generating your word...")
if level_of_difficulty == 'Random':
generated_word = random.choice(random_words)
guessed = ''
lives = 7
while lives > 0:
missed = 0
print()
for letter in generated_word:
if letter in guessed:
print("Congrats ya dumb animal, you got one")
else:
print ('_'+ end=' ')
missed = missed + 1
if missed == 0:
print ('nnYou win!')
quit()
break
guess=input("Well what are you waiting for? guess a letter!:")
guessed = guessed + guess
if guess not in generated_word:
print ('n People like you are the reason why the human race will fail')
print ('Fool')
lives = lives - 1
missed = missed + 1
print('your new lives value is ' + str(lives))
if lives < 7:
print(''' _______
| | ''')
if lives < 6:
print(' | O ')
if lives < 5:
print(' | | ')
if lives < 4:
print(' | - -/ ')
if lives < 3:
print(' | | ')
if lives < 2:
print(' | | | ')
if lives < 1:
print(' | | | ')
if lives == 0:
print('___|___ ')
print('Game Over Boi')
print('The secret word was ' + str(generated_word) + "fool")
quit()
python
python
edited Nov 9 at 19:55
Prune
41.1k133454
41.1k133454
asked Nov 9 at 19:48
Timothy Johnson
12
12
what version of python are you using, and what is the exact error message?
– wpercy
Nov 9 at 19:51
lemme check on that
– Timothy Johnson
Nov 9 at 19:51
3
Well, you haven't actually asked a question. You've basically just said, "here's my code, figure out what's wrong." What you should do instead is say, here's my code; i'm getting an error on line XXX, and here's the error message, and here's what I've tried to do to fix it. In other words: stackoverflow.com/help/how-to-ask
– Kenneth K.
Nov 9 at 19:51
3
@TimothyJohnson hate is the wrong word, but there are a few things wrong with your post. firstly: please include a Minimal Complete Verifiable Example (the only thing missing is theminimalpart). secondly, don't call for sympathy with phrases like "I'm new to $Language or $Concept". thirdly, include the errors you're getting, don't just say that you're getting errors. and, lastly: don't ever write things likeplease help me, um... yeah.
– Tilman B. aka Nerdyyy
Nov 9 at 19:52
1
@TimothyJohnson if you're using python 2.x you can't passend=as an argument to the print function.
– wpercy
Nov 9 at 19:57
|
show 6 more comments
what version of python are you using, and what is the exact error message?
– wpercy
Nov 9 at 19:51
lemme check on that
– Timothy Johnson
Nov 9 at 19:51
3
Well, you haven't actually asked a question. You've basically just said, "here's my code, figure out what's wrong." What you should do instead is say, here's my code; i'm getting an error on line XXX, and here's the error message, and here's what I've tried to do to fix it. In other words: stackoverflow.com/help/how-to-ask
– Kenneth K.
Nov 9 at 19:51
3
@TimothyJohnson hate is the wrong word, but there are a few things wrong with your post. firstly: please include a Minimal Complete Verifiable Example (the only thing missing is theminimalpart). secondly, don't call for sympathy with phrases like "I'm new to $Language or $Concept". thirdly, include the errors you're getting, don't just say that you're getting errors. and, lastly: don't ever write things likeplease help me, um... yeah.
– Tilman B. aka Nerdyyy
Nov 9 at 19:52
1
@TimothyJohnson if you're using python 2.x you can't passend=as an argument to the print function.
– wpercy
Nov 9 at 19:57
what version of python are you using, and what is the exact error message?
– wpercy
Nov 9 at 19:51
what version of python are you using, and what is the exact error message?
– wpercy
Nov 9 at 19:51
lemme check on that
– Timothy Johnson
Nov 9 at 19:51
lemme check on that
– Timothy Johnson
Nov 9 at 19:51
3
3
Well, you haven't actually asked a question. You've basically just said, "here's my code, figure out what's wrong." What you should do instead is say, here's my code; i'm getting an error on line XXX, and here's the error message, and here's what I've tried to do to fix it. In other words: stackoverflow.com/help/how-to-ask
– Kenneth K.
Nov 9 at 19:51
Well, you haven't actually asked a question. You've basically just said, "here's my code, figure out what's wrong." What you should do instead is say, here's my code; i'm getting an error on line XXX, and here's the error message, and here's what I've tried to do to fix it. In other words: stackoverflow.com/help/how-to-ask
– Kenneth K.
Nov 9 at 19:51
3
3
@TimothyJohnson hate is the wrong word, but there are a few things wrong with your post. firstly: please include a Minimal Complete Verifiable Example (the only thing missing is the
minimal part). secondly, don't call for sympathy with phrases like "I'm new to $Language or $Concept". thirdly, include the errors you're getting, don't just say that you're getting errors. and, lastly: don't ever write things like please help me, um... yeah.– Tilman B. aka Nerdyyy
Nov 9 at 19:52
@TimothyJohnson hate is the wrong word, but there are a few things wrong with your post. firstly: please include a Minimal Complete Verifiable Example (the only thing missing is the
minimal part). secondly, don't call for sympathy with phrases like "I'm new to $Language or $Concept". thirdly, include the errors you're getting, don't just say that you're getting errors. and, lastly: don't ever write things like please help me, um... yeah.– Tilman B. aka Nerdyyy
Nov 9 at 19:52
1
1
@TimothyJohnson if you're using python 2.x you can't pass
end= as an argument to the print function.– wpercy
Nov 9 at 19:57
@TimothyJohnson if you're using python 2.x you can't pass
end= as an argument to the print function.– wpercy
Nov 9 at 19:57
|
show 6 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
so here is some code that partially belongs to me
This appears to be the root of the problem. The main issue aside from a type is the use of Python 3 functionality when you are using Python 2.
print ('_'+ end=' ')
Aside from the typo that + needs to be a ,. In Python 2 the end keyword is not used for print, which is only used in python 3. Instead you can do the same thing in Python 2 by doing:
print '_',
The next issue will be with line:
guess=input("Well what are you waiting for? guess a letter!:")
This will give you a error because in Python 2 it tries to evaluate what you entered as an expression instead of a string. Instead you will need to do:
guess=raw_input("Well what are you waiting for? guess a letter!:")
With both these fixes you will have a working game. Although you may want to add in a way to see what letters the user got right.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
so here is some code that partially belongs to me
This appears to be the root of the problem. The main issue aside from a type is the use of Python 3 functionality when you are using Python 2.
print ('_'+ end=' ')
Aside from the typo that + needs to be a ,. In Python 2 the end keyword is not used for print, which is only used in python 3. Instead you can do the same thing in Python 2 by doing:
print '_',
The next issue will be with line:
guess=input("Well what are you waiting for? guess a letter!:")
This will give you a error because in Python 2 it tries to evaluate what you entered as an expression instead of a string. Instead you will need to do:
guess=raw_input("Well what are you waiting for? guess a letter!:")
With both these fixes you will have a working game. Although you may want to add in a way to see what letters the user got right.
add a comment |
up vote
0
down vote
so here is some code that partially belongs to me
This appears to be the root of the problem. The main issue aside from a type is the use of Python 3 functionality when you are using Python 2.
print ('_'+ end=' ')
Aside from the typo that + needs to be a ,. In Python 2 the end keyword is not used for print, which is only used in python 3. Instead you can do the same thing in Python 2 by doing:
print '_',
The next issue will be with line:
guess=input("Well what are you waiting for? guess a letter!:")
This will give you a error because in Python 2 it tries to evaluate what you entered as an expression instead of a string. Instead you will need to do:
guess=raw_input("Well what are you waiting for? guess a letter!:")
With both these fixes you will have a working game. Although you may want to add in a way to see what letters the user got right.
add a comment |
up vote
0
down vote
up vote
0
down vote
so here is some code that partially belongs to me
This appears to be the root of the problem. The main issue aside from a type is the use of Python 3 functionality when you are using Python 2.
print ('_'+ end=' ')
Aside from the typo that + needs to be a ,. In Python 2 the end keyword is not used for print, which is only used in python 3. Instead you can do the same thing in Python 2 by doing:
print '_',
The next issue will be with line:
guess=input("Well what are you waiting for? guess a letter!:")
This will give you a error because in Python 2 it tries to evaluate what you entered as an expression instead of a string. Instead you will need to do:
guess=raw_input("Well what are you waiting for? guess a letter!:")
With both these fixes you will have a working game. Although you may want to add in a way to see what letters the user got right.
so here is some code that partially belongs to me
This appears to be the root of the problem. The main issue aside from a type is the use of Python 3 functionality when you are using Python 2.
print ('_'+ end=' ')
Aside from the typo that + needs to be a ,. In Python 2 the end keyword is not used for print, which is only used in python 3. Instead you can do the same thing in Python 2 by doing:
print '_',
The next issue will be with line:
guess=input("Well what are you waiting for? guess a letter!:")
This will give you a error because in Python 2 it tries to evaluate what you entered as an expression instead of a string. Instead you will need to do:
guess=raw_input("Well what are you waiting for? guess a letter!:")
With both these fixes you will have a working game. Although you may want to add in a way to see what letters the user got right.
edited Nov 9 at 20:38
answered Nov 9 at 20:33
Spencer Wieczorek
17.3k43043
17.3k43043
add a comment |
add a comment |
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%2f53232385%2fhangman-help-invalid-print-statement%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
what version of python are you using, and what is the exact error message?
– wpercy
Nov 9 at 19:51
lemme check on that
– Timothy Johnson
Nov 9 at 19:51
3
Well, you haven't actually asked a question. You've basically just said, "here's my code, figure out what's wrong." What you should do instead is say, here's my code; i'm getting an error on line XXX, and here's the error message, and here's what I've tried to do to fix it. In other words: stackoverflow.com/help/how-to-ask
– Kenneth K.
Nov 9 at 19:51
3
@TimothyJohnson hate is the wrong word, but there are a few things wrong with your post. firstly: please include a Minimal Complete Verifiable Example (the only thing missing is the
minimalpart). secondly, don't call for sympathy with phrases like "I'm new to $Language or $Concept". thirdly, include the errors you're getting, don't just say that you're getting errors. and, lastly: don't ever write things likeplease help me, um... yeah.– Tilman B. aka Nerdyyy
Nov 9 at 19:52
1
@TimothyJohnson if you're using python 2.x you can't pass
end=as an argument to the print function.– wpercy
Nov 9 at 19:57