First Hangman game in Python 3.6 [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





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







up vote
1
down vote

favorite












Should I create a main function, and is everything placed right or should I def more or fewer functions?



import random

# open text file with a word on every new line
# [:-1] removes n, from behind the word, wich is also pulled from the text
with open('sowpods.txt', 'r') as words:
chosen_word = (random.choice(words.readlines()))[:-1]
right_guess = set()
wrong_guess = set()
lives = ['1up', '2up', '3up', '4up', '5up', '6up']
print('Welcome to hangman.nnEnter a letter to start playing, you have six lives.nGoodluck!')


def progress():
# for every character in chosen_word
for i in chosen_word:
# see if the character is in the players guess
if i in right_guess:
# print then out the character
print(i, end=' ')
elif not i in right_guess:
# if not found, print a dash
print('_', end=' ')


def start():
while True:

progress()

# check if the word has been guessed yet
if right_guess == set(chosen_word):
print('nnnCongratulations you've won!')

# forces the userinput to uppercase
x = input('nn').upper()

# check if the letter has already been guessed right
if x in right_guess:
print('You've already guessed this letter!')

# collects all the right guessed letters
elif x in chosen_word:
right_guess.add(x)
print('correctn')

# check if the letter has already been guessed wrong
elif x in wrong_guess:
print('You've already tried this letter.')

# collect wrong guesses and checks if input is a single entry
elif not x in chosen_word and len(x) == 1:
wrong_guess.add(x)
print('wrong')
# remove a live from the list when wrong guess
del lives[0]
# if all lives gone end game
if len(lives) > 0:
print('Lives left:n' + str(len(lives)))
elif len(lives) <= 0:
print('You have no more lives left, restart to try again')
print('Maby you'll get an easier word then:')
print(chosen_word)
print('Good luck')

# for when input isnt a singe entry
else:
print('You must enter a singel letter.')

print(start())






share|improve this question













closed as off-topic by Daniel, Stephen Rauch, Sam Onela, Mast, Graipher May 12 at 20:57


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Daniel, Stephen Rauch, Sam Onela, Mast, Graipher
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Your code is not indented properly as shown. Please edit your post, simply copy from your editor, paste in the body of your post, then select all your code and press Ctrl+K / Command+K (Mac).
    – Phrancis
    May 12 at 5:51










  • Can you add an excerpt of sowpods.txt? Your code is broken, by the way. Did you test it?
    – Daniel
    May 12 at 9:25











  • @Coal_ its a text document on my computer, all it does is generate a random word, the code runs fine. I'm not sure if there is a way i can include it on codereview
    – Sjoerd Gerritsen
    May 12 at 10:07










  • The code runs, but it doesn't work as expected (hint: you're missing a call to chosen_word.upper()).
    – Daniel
    May 12 at 10:30










  • @Sjoerd, I think it's oke to add an excerpt of sowpods.txt reduced to a few tens of lines to the question.
    – Jan Kuiken
    May 12 at 16:15
















up vote
1
down vote

favorite












Should I create a main function, and is everything placed right or should I def more or fewer functions?



import random

# open text file with a word on every new line
# [:-1] removes n, from behind the word, wich is also pulled from the text
with open('sowpods.txt', 'r') as words:
chosen_word = (random.choice(words.readlines()))[:-1]
right_guess = set()
wrong_guess = set()
lives = ['1up', '2up', '3up', '4up', '5up', '6up']
print('Welcome to hangman.nnEnter a letter to start playing, you have six lives.nGoodluck!')


def progress():
# for every character in chosen_word
for i in chosen_word:
# see if the character is in the players guess
if i in right_guess:
# print then out the character
print(i, end=' ')
elif not i in right_guess:
# if not found, print a dash
print('_', end=' ')


def start():
while True:

progress()

# check if the word has been guessed yet
if right_guess == set(chosen_word):
print('nnnCongratulations you've won!')

# forces the userinput to uppercase
x = input('nn').upper()

# check if the letter has already been guessed right
if x in right_guess:
print('You've already guessed this letter!')

# collects all the right guessed letters
elif x in chosen_word:
right_guess.add(x)
print('correctn')

# check if the letter has already been guessed wrong
elif x in wrong_guess:
print('You've already tried this letter.')

# collect wrong guesses and checks if input is a single entry
elif not x in chosen_word and len(x) == 1:
wrong_guess.add(x)
print('wrong')
# remove a live from the list when wrong guess
del lives[0]
# if all lives gone end game
if len(lives) > 0:
print('Lives left:n' + str(len(lives)))
elif len(lives) <= 0:
print('You have no more lives left, restart to try again')
print('Maby you'll get an easier word then:')
print(chosen_word)
print('Good luck')

# for when input isnt a singe entry
else:
print('You must enter a singel letter.')

print(start())






share|improve this question













closed as off-topic by Daniel, Stephen Rauch, Sam Onela, Mast, Graipher May 12 at 20:57


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Daniel, Stephen Rauch, Sam Onela, Mast, Graipher
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Your code is not indented properly as shown. Please edit your post, simply copy from your editor, paste in the body of your post, then select all your code and press Ctrl+K / Command+K (Mac).
    – Phrancis
    May 12 at 5:51










  • Can you add an excerpt of sowpods.txt? Your code is broken, by the way. Did you test it?
    – Daniel
    May 12 at 9:25











  • @Coal_ its a text document on my computer, all it does is generate a random word, the code runs fine. I'm not sure if there is a way i can include it on codereview
    – Sjoerd Gerritsen
    May 12 at 10:07










  • The code runs, but it doesn't work as expected (hint: you're missing a call to chosen_word.upper()).
    – Daniel
    May 12 at 10:30










  • @Sjoerd, I think it's oke to add an excerpt of sowpods.txt reduced to a few tens of lines to the question.
    – Jan Kuiken
    May 12 at 16:15












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Should I create a main function, and is everything placed right or should I def more or fewer functions?



import random

# open text file with a word on every new line
# [:-1] removes n, from behind the word, wich is also pulled from the text
with open('sowpods.txt', 'r') as words:
chosen_word = (random.choice(words.readlines()))[:-1]
right_guess = set()
wrong_guess = set()
lives = ['1up', '2up', '3up', '4up', '5up', '6up']
print('Welcome to hangman.nnEnter a letter to start playing, you have six lives.nGoodluck!')


def progress():
# for every character in chosen_word
for i in chosen_word:
# see if the character is in the players guess
if i in right_guess:
# print then out the character
print(i, end=' ')
elif not i in right_guess:
# if not found, print a dash
print('_', end=' ')


def start():
while True:

progress()

# check if the word has been guessed yet
if right_guess == set(chosen_word):
print('nnnCongratulations you've won!')

# forces the userinput to uppercase
x = input('nn').upper()

# check if the letter has already been guessed right
if x in right_guess:
print('You've already guessed this letter!')

# collects all the right guessed letters
elif x in chosen_word:
right_guess.add(x)
print('correctn')

# check if the letter has already been guessed wrong
elif x in wrong_guess:
print('You've already tried this letter.')

# collect wrong guesses and checks if input is a single entry
elif not x in chosen_word and len(x) == 1:
wrong_guess.add(x)
print('wrong')
# remove a live from the list when wrong guess
del lives[0]
# if all lives gone end game
if len(lives) > 0:
print('Lives left:n' + str(len(lives)))
elif len(lives) <= 0:
print('You have no more lives left, restart to try again')
print('Maby you'll get an easier word then:')
print(chosen_word)
print('Good luck')

# for when input isnt a singe entry
else:
print('You must enter a singel letter.')

print(start())






share|improve this question













Should I create a main function, and is everything placed right or should I def more or fewer functions?



import random

# open text file with a word on every new line
# [:-1] removes n, from behind the word, wich is also pulled from the text
with open('sowpods.txt', 'r') as words:
chosen_word = (random.choice(words.readlines()))[:-1]
right_guess = set()
wrong_guess = set()
lives = ['1up', '2up', '3up', '4up', '5up', '6up']
print('Welcome to hangman.nnEnter a letter to start playing, you have six lives.nGoodluck!')


def progress():
# for every character in chosen_word
for i in chosen_word:
# see if the character is in the players guess
if i in right_guess:
# print then out the character
print(i, end=' ')
elif not i in right_guess:
# if not found, print a dash
print('_', end=' ')


def start():
while True:

progress()

# check if the word has been guessed yet
if right_guess == set(chosen_word):
print('nnnCongratulations you've won!')

# forces the userinput to uppercase
x = input('nn').upper()

# check if the letter has already been guessed right
if x in right_guess:
print('You've already guessed this letter!')

# collects all the right guessed letters
elif x in chosen_word:
right_guess.add(x)
print('correctn')

# check if the letter has already been guessed wrong
elif x in wrong_guess:
print('You've already tried this letter.')

# collect wrong guesses and checks if input is a single entry
elif not x in chosen_word and len(x) == 1:
wrong_guess.add(x)
print('wrong')
# remove a live from the list when wrong guess
del lives[0]
# if all lives gone end game
if len(lives) > 0:
print('Lives left:n' + str(len(lives)))
elif len(lives) <= 0:
print('You have no more lives left, restart to try again')
print('Maby you'll get an easier word then:')
print(chosen_word)
print('Good luck')

# for when input isnt a singe entry
else:
print('You must enter a singel letter.')

print(start())








share|improve this question












share|improve this question




share|improve this question








edited May 12 at 8:08









Daniel

4,1132836




4,1132836









asked May 12 at 5:29









Sjoerd Gerritsen

64




64




closed as off-topic by Daniel, Stephen Rauch, Sam Onela, Mast, Graipher May 12 at 20:57


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Daniel, Stephen Rauch, Sam Onela, Mast, Graipher
If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Daniel, Stephen Rauch, Sam Onela, Mast, Graipher May 12 at 20:57


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Daniel, Stephen Rauch, Sam Onela, Mast, Graipher
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 2




    Your code is not indented properly as shown. Please edit your post, simply copy from your editor, paste in the body of your post, then select all your code and press Ctrl+K / Command+K (Mac).
    – Phrancis
    May 12 at 5:51










  • Can you add an excerpt of sowpods.txt? Your code is broken, by the way. Did you test it?
    – Daniel
    May 12 at 9:25











  • @Coal_ its a text document on my computer, all it does is generate a random word, the code runs fine. I'm not sure if there is a way i can include it on codereview
    – Sjoerd Gerritsen
    May 12 at 10:07










  • The code runs, but it doesn't work as expected (hint: you're missing a call to chosen_word.upper()).
    – Daniel
    May 12 at 10:30










  • @Sjoerd, I think it's oke to add an excerpt of sowpods.txt reduced to a few tens of lines to the question.
    – Jan Kuiken
    May 12 at 16:15












  • 2




    Your code is not indented properly as shown. Please edit your post, simply copy from your editor, paste in the body of your post, then select all your code and press Ctrl+K / Command+K (Mac).
    – Phrancis
    May 12 at 5:51










  • Can you add an excerpt of sowpods.txt? Your code is broken, by the way. Did you test it?
    – Daniel
    May 12 at 9:25











  • @Coal_ its a text document on my computer, all it does is generate a random word, the code runs fine. I'm not sure if there is a way i can include it on codereview
    – Sjoerd Gerritsen
    May 12 at 10:07










  • The code runs, but it doesn't work as expected (hint: you're missing a call to chosen_word.upper()).
    – Daniel
    May 12 at 10:30










  • @Sjoerd, I think it's oke to add an excerpt of sowpods.txt reduced to a few tens of lines to the question.
    – Jan Kuiken
    May 12 at 16:15







2




2




Your code is not indented properly as shown. Please edit your post, simply copy from your editor, paste in the body of your post, then select all your code and press Ctrl+K / Command+K (Mac).
– Phrancis
May 12 at 5:51




Your code is not indented properly as shown. Please edit your post, simply copy from your editor, paste in the body of your post, then select all your code and press Ctrl+K / Command+K (Mac).
– Phrancis
May 12 at 5:51












Can you add an excerpt of sowpods.txt? Your code is broken, by the way. Did you test it?
– Daniel
May 12 at 9:25





Can you add an excerpt of sowpods.txt? Your code is broken, by the way. Did you test it?
– Daniel
May 12 at 9:25













@Coal_ its a text document on my computer, all it does is generate a random word, the code runs fine. I'm not sure if there is a way i can include it on codereview
– Sjoerd Gerritsen
May 12 at 10:07




@Coal_ its a text document on my computer, all it does is generate a random word, the code runs fine. I'm not sure if there is a way i can include it on codereview
– Sjoerd Gerritsen
May 12 at 10:07












The code runs, but it doesn't work as expected (hint: you're missing a call to chosen_word.upper()).
– Daniel
May 12 at 10:30




The code runs, but it doesn't work as expected (hint: you're missing a call to chosen_word.upper()).
– Daniel
May 12 at 10:30












@Sjoerd, I think it's oke to add an excerpt of sowpods.txt reduced to a few tens of lines to the question.
– Jan Kuiken
May 12 at 16:15




@Sjoerd, I think it's oke to add an excerpt of sowpods.txt reduced to a few tens of lines to the question.
– Jan Kuiken
May 12 at 16:15















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Chat program with C++ and SFML

Function to Return a JSON Like Objects Using VBA Collections and Arrays

Will my employers contract hold up in court?