#my Python masterpiece
import sys, subprocess
from time import sleep as delay
################################################################################################################################
code = subprocess.Popen(["python", "randomizer.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
tester = str(code.stderr.readline())[2:-3]
if tester:
print(tester)
while True:
line = str(code.stderr.readline())[2:-3]
if not line:
break
print(line)
sys.exit(1)
line = str(code.stdout.readline())[2:-3]
################################################################################################################################
word = line.lower()
word_list = [letter for letter in word]
current_list = ["_" for l in word]
current_shown = " ".join(current_list)
tries = 0
letters_attempted = []
print("You get 5 chances.")
while True:
print(current_shown)
letter = input().lower()
if (len(letter) == 1) & (letter in __import__("string").ascii_letters):
if letter in letters_attempted:
print("You already guessed that letter.")
elif letter in word_list:
print("Yes, it is in my word.")
for l in range(len(word_list)):
if letter == word_list[l]:
current_list[l] = letter
else:
print("Incorrect.")
tries += 1
current_shown = " ".join(current_list)
letters_attempted += letter
elif (len(letter) == len(word)) & all([l in __import__("string").ascii_letters for l in letter]):
print("You tried to guess my word, and you were...")
letter = letter.lower()
delay(2)
if letter == word:
print("Correct!")
sys.exit(0)
else:
print("Incorrect.")
delay(1)
print("The answer was", "\"" + word + "\".")
sys.exit(1)
else:
print("Invalid.")
if "".join(current_list) == word:
print("You have fully guessed my word!")
print("The answer was", "\"" + word + "\".")
sys.exit(0)
if tries >= 5:
print("You have run out of attempts, sorry.")
delay(1)
print("The answer was", "\"" + word + "\".")
sys.exit(1)
hangman
box
text
hello
greeting
challenge
tintinnabulation
pneumonoultramicroscopicsilicovolcanoconiosis
large
word
stuff
thing
game
no
file
school
block
build
construct
ocarina
eagle
pheonix
necklace
jewelery
money
ball
paper
bed
blanket
pillow
doll
instrument
picture
wallhop
wall
sneer
peer
item
ladder
truss
mushroom
instance
python
iterate
repeat
ibex
dive
rise
up
down
right
left
direction
compass
ruler
protractor
measure
time
sound
noise
hear
tactile
cilia
silica
ion
class DuplicateWordError(Exception):
def __init__(self, word):
Exception.__init__(self, "The word \"" + word + "\" was written more than once.")
namelist = []
for line in open("secret_words.txt", "r"):
line = line.rstrip()
if (line != "") & (line not in namelist):
namelist.append(line)
elif line in namelist:
raise DuplicateWordError(line)
################################################################################################################################
from random import randrange as random
try:
wheelspin = random(0, len(namelist))
except ValueError:
print()
else:
wheelresult = namelist[wheelspin]
print(wheelresult)