-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mystery word HW #11
Open
Callus4815
wants to merge
9
commits into
tiyd-python-2015-05:master
Choose a base branch
from
Callus4815:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mystery word HW #11
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
79e45b6
Add normal mode.
Callus4815 4063da1
Added personalization
Callus4815 1391767
one more time
Callus4815 8f8ef76
this should word
Callus4815 ab583b7
small touches
Callus4815 0d6463f
touch
Callus4815 f240c8c
test
Callus4815 f7c08ca
tweaking game flow
Callus4815 398af91
passing all tests
Callus4815 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import random | ||
import re | ||
|
||
def get_file(): | ||
with open('/usr/share/dict/words') as list_of_words: | ||
words = list_of_words.read() | ||
words = words.split() | ||
return words | ||
|
||
def easy_words(words): | ||
easy_words = [] | ||
|
||
for chosen_word in words: | ||
if len(chosen_word) <= 6 and len(chosen_word) >= 4: | ||
easy_words.append(chosen_word) | ||
return easy_words | ||
|
||
def medium_words(word_list): | ||
medium_words = [] | ||
for chosen_word in word_list: | ||
if len(chosen_word) <= 8 and len(chosen_word) >=6: | ||
medium_words.append(chosen_word) | ||
return medium_words | ||
|
||
def hard_words(word_list): | ||
hard_words = [] | ||
for chosen_word in word_list: | ||
if len(chosen_word) >= 8: | ||
hard_words.append(chosen_word) | ||
return hard_words | ||
|
||
def random_word(words): | ||
random_word = [] | ||
random_word = random.choice(words) | ||
return random_word | ||
|
||
def display_word(random_word,guess): | ||
|
||
letter_in_word = [] | ||
for letter in random_word: | ||
if letter in guess: | ||
letter_in_word.append(letter) | ||
else: | ||
letter_in_word.append("_") | ||
letter_in_word = " ".join(letter_in_word) | ||
return letter_in_word.upper() | ||
|
||
|
||
def is_word_complete(word,guess): | ||
for letter in word: | ||
if letter not in guess: | ||
return False | ||
return True | ||
|
||
def user_Input(): | ||
print("Welcome to MYSTERY WORD!!!!!!!!!") | ||
mode = input("What difficulty level would you like this game to be [E]asy, [M]edium, or [H]ard: ") | ||
|
||
mode = re.sub(r'[^A-Za-z0-9]','',mode).upper() | ||
|
||
return mode | ||
|
||
|
||
|
||
def get_word(modage, words): | ||
|
||
if modage == 'E'.upper(): | ||
easy_list = easy_words(words) | ||
word1 = random_word(easy_list).upper() | ||
print("Your word has {} letters in it".format(len(word1))) | ||
|
||
return word1 | ||
elif modage == 'M'.upper(): | ||
medium_list = medium_words(words) | ||
word2 = random_word(medium_list).upper() | ||
print("Your word has {} letters in it".format(len(word2))) | ||
return word2 | ||
elif modage == 'H'.upper(): | ||
hard_list = hard_words(words) | ||
word3 = random_word(hard_list).upper() | ||
print("Your word has {} letters in it".format(len(word3))) | ||
return word3 | ||
|
||
#need to put a catch all here | ||
def guess_letters(any_word): | ||
count = 8 | ||
guessed_letter=[] | ||
missed_letter = [] | ||
while count != 0: | ||
guess1 = input("Please guess a letter: ").upper() | ||
guess1 = re.sub(r'[^A-Za-z0-9]','',guess1) | ||
if guess1 in guessed_letter: | ||
print('You guessed that already but,') | ||
guessed_letter.append(guess1) | ||
if len(guess1) > 1: | ||
print("That is invalid, please try again.") | ||
elif is_word_complete(any_word,guessed_letter)==True: | ||
print("Congratulations, you have solved the mystery word, it was {}.".format(any_word)) | ||
break | ||
|
||
elif guess1 in any_word: | ||
guessed_letter.append(guess1) | ||
print("Good guess!!") | ||
print(display_word(any_word, guessed_letter)) | ||
print("You have {} guesses left".format(count)) | ||
elif guess1 not in any_word: | ||
missed_letter.append(guess1) | ||
print('Sorry that letter is not in the word') | ||
count-=1 | ||
print("You have {} guesses left".format(count)) | ||
if count == 0: | ||
print("Sorry, you lose. The word was {}".format(any_word)) | ||
return | ||
|
||
while True: | ||
if __name__ == '__main__': | ||
words = get_file() | ||
modage = user_Input() | ||
word = get_word(modage, words) | ||
guess_letters(word) | ||
|
||
while True: | ||
answer =input('Would you like to play again? (y/n): ') | ||
if answer in ('y', 'n'): | ||
break | ||
print( 'Invalid input.') | ||
if answer == 'y': | ||
continue | ||
else: | ||
print ('Thanks for playing!, Goodbye') | ||
break |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line will make importing this file hang. I don't think you need it.