RE: 100 Program Challenge..For everyone 05-13-2016, 11:28 PM
#8
(05-13-2016, 11:16 PM)Oni Wrote: I'll try and do Hangman.
Spoiler: python version
Code:
from random import randint
from os import system
def cls():
if __import__('os').name=="nt": system('cls')
else: system('clear')
words=["animal","vast","brilliant","exit","passenger","binding","loyal","cold","generation","cruise","abstract","raspberry","prime","red","episode","forgotten","dust","virgin","alien","focus","tactic","cut","pink","skin","goggles","crawling","heart"]
word=list(words[randint(0,len(words)-1)])
disp=['_']*len(word)
left=12
guessed=[]
while left>=0:
cls()
print("Guesses left:\t "+str(left)+"\nAlready guessed:",', '.join(guessed),"\nProgress:\t",' '.join(disp),"\n\n")
guess=input("Guess a letter: ")
while guess in guessed or len(guess)>1:
guess=input("Invalid option. Choose another letter: ")
guessed.append(guess)
if word.count(guess)>0:
for i in range(len(word)):
if word[i]==guess: disp[i]=guess
if disp==word:
print("\nYou Win! The word is "+''.join(word))
exit()
else:
left-=1
print("Out of guesses, you lose. The word was "+''.join(word))It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.
















![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)