Created
May 26, 2014 09:06
-
-
Save anonymous/1135f8575f9bec4fa8e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import random | |
f = open("enable1.txt") | |
words = [x.strip().upper() for x in f.readlines()] | |
def CreateWords(difficulty=1): | |
"""Take the difficulty number and a list of words, return | |
a list of words accordingly""" | |
newwords = [] | |
i = 0 | |
temp = "" | |
while i < 5: | |
temp = random.choice(words) | |
if len(temp) == difficulty + 4: | |
newwords.append(temp) | |
i += 1 | |
return newwords | |
def CheckMatch(userinput, answer): | |
"""Take user input and the answer word, return number of letters user | |
matched""" | |
i = 0 | |
count = 0 | |
for x in answer: | |
if i >= len(userinput): | |
break | |
if x == userinput[i]: | |
count += 1 | |
i += 1 | |
return count | |
def PrintResult(count, answer): | |
"""Take number of correct matches and the answer and print the results""" | |
if count == len(answer): | |
print "You win!" | |
else: | |
print "%d out of %d correct" % (count, len(answer) ) | |
while True: | |
difficultynum = input("Difficulty (1-5) ? ") | |
if 1 <= difficultynum <= 5: | |
break | |
wordlist = CreateWords(difficultynum) | |
for x in wordlist: | |
print x | |
y = count = 0 | |
answer = random.choice(wordlist) | |
while y < range(4) and count != len(answer): | |
userword = input() | |
count = CheckMatch(userword, answer) | |
PrintResult(count, answer) | |
print "%d / 4 tries left" % y | |
y += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment