How do I fix a Stubborn syntax error in my python project?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm working on a school project and I've almost got it done. Doing a hangman game. for the "else:" command below print (char) on line 32 I keep getting a syntax error and nothing I've tried so far fixes it and the compiler wont tell me what the problem is besides it being a syntax error



import time
Name =input("What is your name?")
print ("Hello,"+Name,"Time to play hangman")
print( "")
#wait for 1 second
time.sleep(1)
print("Start guessing...")
time.sleep(0.5)

#here we set the secret

word = "ball"

#creates an variable with an empty value

guesses = ""

#determine the number of turns
turns =10

#create a while loop

#check if the turns are more than zero
while turns > 0:

#make a counter that starts with zero
Failed =0
#for every character in secret_word
for char in word:
if char in guesses:
print (char,)
else:
print ( "_", )
failed += 1

print ("You won")
break
print()
guess = input ("guess a character:")
guesses +=guess
if guess not in word
turns -=1
print ("Wrong")
print ("You have", turns, "more guesses")
if turns ==0:
print ("You Lose the Word was",word)









share|improve this question




















  • 6





    else needs to be indented the same amount as the matching if. The indentation for the rest of your code looks a bit off as well.

    – chepner
    Nov 16 '18 at 15:10











  • ok I fixed that and re worked the indentation on my code and its working now, thank you

    – Pazoink
    Nov 16 '18 at 15:18











  • I recommend using a linter like flake8. These kinds of tools will help you find issues like this early on. You can even configure lots of code editors to run them dynamically for you. Your code has a number of similar problems.

    – Jonah Bishop
    Nov 16 '18 at 15:21













  • actually now its saying "guess" is not defined. didn't I define it as input tho?

    – Pazoink
    Nov 16 '18 at 15:24











  • You define guess in the else clause of your conditional, which means it isn't always available by the time you exit the conditional (consider if the true clause executes, not the else).

    – Jonah Bishop
    Nov 16 '18 at 15:32




















0















I'm working on a school project and I've almost got it done. Doing a hangman game. for the "else:" command below print (char) on line 32 I keep getting a syntax error and nothing I've tried so far fixes it and the compiler wont tell me what the problem is besides it being a syntax error



import time
Name =input("What is your name?")
print ("Hello,"+Name,"Time to play hangman")
print( "")
#wait for 1 second
time.sleep(1)
print("Start guessing...")
time.sleep(0.5)

#here we set the secret

word = "ball"

#creates an variable with an empty value

guesses = ""

#determine the number of turns
turns =10

#create a while loop

#check if the turns are more than zero
while turns > 0:

#make a counter that starts with zero
Failed =0
#for every character in secret_word
for char in word:
if char in guesses:
print (char,)
else:
print ( "_", )
failed += 1

print ("You won")
break
print()
guess = input ("guess a character:")
guesses +=guess
if guess not in word
turns -=1
print ("Wrong")
print ("You have", turns, "more guesses")
if turns ==0:
print ("You Lose the Word was",word)









share|improve this question




















  • 6





    else needs to be indented the same amount as the matching if. The indentation for the rest of your code looks a bit off as well.

    – chepner
    Nov 16 '18 at 15:10











  • ok I fixed that and re worked the indentation on my code and its working now, thank you

    – Pazoink
    Nov 16 '18 at 15:18











  • I recommend using a linter like flake8. These kinds of tools will help you find issues like this early on. You can even configure lots of code editors to run them dynamically for you. Your code has a number of similar problems.

    – Jonah Bishop
    Nov 16 '18 at 15:21













  • actually now its saying "guess" is not defined. didn't I define it as input tho?

    – Pazoink
    Nov 16 '18 at 15:24











  • You define guess in the else clause of your conditional, which means it isn't always available by the time you exit the conditional (consider if the true clause executes, not the else).

    – Jonah Bishop
    Nov 16 '18 at 15:32
















0












0








0








I'm working on a school project and I've almost got it done. Doing a hangman game. for the "else:" command below print (char) on line 32 I keep getting a syntax error and nothing I've tried so far fixes it and the compiler wont tell me what the problem is besides it being a syntax error



import time
Name =input("What is your name?")
print ("Hello,"+Name,"Time to play hangman")
print( "")
#wait for 1 second
time.sleep(1)
print("Start guessing...")
time.sleep(0.5)

#here we set the secret

word = "ball"

#creates an variable with an empty value

guesses = ""

#determine the number of turns
turns =10

#create a while loop

#check if the turns are more than zero
while turns > 0:

#make a counter that starts with zero
Failed =0
#for every character in secret_word
for char in word:
if char in guesses:
print (char,)
else:
print ( "_", )
failed += 1

print ("You won")
break
print()
guess = input ("guess a character:")
guesses +=guess
if guess not in word
turns -=1
print ("Wrong")
print ("You have", turns, "more guesses")
if turns ==0:
print ("You Lose the Word was",word)









share|improve this question
















I'm working on a school project and I've almost got it done. Doing a hangman game. for the "else:" command below print (char) on line 32 I keep getting a syntax error and nothing I've tried so far fixes it and the compiler wont tell me what the problem is besides it being a syntax error



import time
Name =input("What is your name?")
print ("Hello,"+Name,"Time to play hangman")
print( "")
#wait for 1 second
time.sleep(1)
print("Start guessing...")
time.sleep(0.5)

#here we set the secret

word = "ball"

#creates an variable with an empty value

guesses = ""

#determine the number of turns
turns =10

#create a while loop

#check if the turns are more than zero
while turns > 0:

#make a counter that starts with zero
Failed =0
#for every character in secret_word
for char in word:
if char in guesses:
print (char,)
else:
print ( "_", )
failed += 1

print ("You won")
break
print()
guess = input ("guess a character:")
guesses +=guess
if guess not in word
turns -=1
print ("Wrong")
print ("You have", turns, "more guesses")
if turns ==0:
print ("You Lose the Word was",word)






python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 16:38









Tobias Wilfert

83131022




83131022










asked Nov 16 '18 at 15:06









PazoinkPazoink

71




71








  • 6





    else needs to be indented the same amount as the matching if. The indentation for the rest of your code looks a bit off as well.

    – chepner
    Nov 16 '18 at 15:10











  • ok I fixed that and re worked the indentation on my code and its working now, thank you

    – Pazoink
    Nov 16 '18 at 15:18











  • I recommend using a linter like flake8. These kinds of tools will help you find issues like this early on. You can even configure lots of code editors to run them dynamically for you. Your code has a number of similar problems.

    – Jonah Bishop
    Nov 16 '18 at 15:21













  • actually now its saying "guess" is not defined. didn't I define it as input tho?

    – Pazoink
    Nov 16 '18 at 15:24











  • You define guess in the else clause of your conditional, which means it isn't always available by the time you exit the conditional (consider if the true clause executes, not the else).

    – Jonah Bishop
    Nov 16 '18 at 15:32
















  • 6





    else needs to be indented the same amount as the matching if. The indentation for the rest of your code looks a bit off as well.

    – chepner
    Nov 16 '18 at 15:10











  • ok I fixed that and re worked the indentation on my code and its working now, thank you

    – Pazoink
    Nov 16 '18 at 15:18











  • I recommend using a linter like flake8. These kinds of tools will help you find issues like this early on. You can even configure lots of code editors to run them dynamically for you. Your code has a number of similar problems.

    – Jonah Bishop
    Nov 16 '18 at 15:21













  • actually now its saying "guess" is not defined. didn't I define it as input tho?

    – Pazoink
    Nov 16 '18 at 15:24











  • You define guess in the else clause of your conditional, which means it isn't always available by the time you exit the conditional (consider if the true clause executes, not the else).

    – Jonah Bishop
    Nov 16 '18 at 15:32










6




6





else needs to be indented the same amount as the matching if. The indentation for the rest of your code looks a bit off as well.

– chepner
Nov 16 '18 at 15:10





else needs to be indented the same amount as the matching if. The indentation for the rest of your code looks a bit off as well.

– chepner
Nov 16 '18 at 15:10













ok I fixed that and re worked the indentation on my code and its working now, thank you

– Pazoink
Nov 16 '18 at 15:18





ok I fixed that and re worked the indentation on my code and its working now, thank you

– Pazoink
Nov 16 '18 at 15:18













I recommend using a linter like flake8. These kinds of tools will help you find issues like this early on. You can even configure lots of code editors to run them dynamically for you. Your code has a number of similar problems.

– Jonah Bishop
Nov 16 '18 at 15:21







I recommend using a linter like flake8. These kinds of tools will help you find issues like this early on. You can even configure lots of code editors to run them dynamically for you. Your code has a number of similar problems.

– Jonah Bishop
Nov 16 '18 at 15:21















actually now its saying "guess" is not defined. didn't I define it as input tho?

– Pazoink
Nov 16 '18 at 15:24





actually now its saying "guess" is not defined. didn't I define it as input tho?

– Pazoink
Nov 16 '18 at 15:24













You define guess in the else clause of your conditional, which means it isn't always available by the time you exit the conditional (consider if the true clause executes, not the else).

– Jonah Bishop
Nov 16 '18 at 15:32







You define guess in the else clause of your conditional, which means it isn't always available by the time you exit the conditional (consider if the true clause executes, not the else).

– Jonah Bishop
Nov 16 '18 at 15:32














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: "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/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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340428%2fhow-do-i-fix-a-stubborn-syntax-error-in-my-python-project%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
















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%2f53340428%2fhow-do-i-fix-a-stubborn-syntax-error-in-my-python-project%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

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly