Skip to content

Instantly share code, notes, and snippets.

@NithishKolli
Forked from nit99kumar/dictionary
Created January 16, 2014 10:41
Show Gist options
  • Save NithishKolli/8452874 to your computer and use it in GitHub Desktop.
Save NithishKolli/8452874 to your computer and use it in GitHub Desktop.
https://raw.github.com/ravi3054/Jumble-Word-Game/master/dictionary
from random import randint
def find_indices(word, c):
l = len(word)
n = list()
for i in range(0,l):
if(c == word[i]):
n.append(i)
return n
def hangman():
a = 'no'
gaali = ['\nchut! kitni baar likhega', '\ngaand maar li jayegi, phir likha toh', '\ndobara mat likhna', '\nmaa chuda, chakke']
while(a == 'no'):
print "\nlet's start the game!!"
chances_remaining = 4
score = 0
count = 0
fob = open('dict', 'r').read().split('\n')
word = fob[randint(0, len(fob)-1)]
hangman = 'HANGMAN'
word_len = len(word)
l = word_len
final = ''
final_list = list('_') * word_len
while(chances_remaining > 0 and l > 0):
a = raw_input("\nenter character: ")
if(a in word and not(a in final)):
score += 1
index_list = find_indices(word, a)
list_len = len(index_list)
for i in range(0, list_len):
final_list[index_list[i]] = a
l -= 1
final = ' '.join(final_list)
print final + '\tscore: ', str(score) + '\tcharacters remaining: ' + str(l)
elif(a in final):
print gaali[randint(0,3)]
chances_remaining -= 1
count += 2
print hangman[0:count] + '\t' + 'chances remaining: ', chances_remaining
else:
chances_remaining -= 1
count += 2
print hangman[0:count] + '\t' + 'chances remaining: ', chances_remaining
if(chances_remaining > 0 and l == 0):
print '\n\n***************\nYAY! YOU WIN :D\n***************\n\n'
if(chances_remaining == 0):
print '\nthe correct word is: ' + word
a = raw_input("want to quit: (yes/no) ")
if __name__ == "__main__":
hangman()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment