Can anyone please show me their hangman code in Python.
import random
wordDict = { 'orange' : 'fruit for winter',
'apple' : 'fruit that keeps the doctor away',
'momo' : 'Nepal\' national food',
'sekuwa' : 'drunken delights',
'boost' : 'secret of my energy',
'rain' : 'falls from the sky'}
randomSelection = random.randint(0,len(wordDict)-1)
selectedWord = wordDict.keys()[randomSelection]
selectedMeaning = wordDict[selectedWord]
noOfLettersInWord = len(selectedWord)
print selectedWord, selectedMeaning
print "__ " * noOfLettersInWord
Hope that helps.
Pravin
#this selects the word that is indexed by the random number generated above
selectedWord = wordDict.keys()[randomSelection]
#this gives the meaning of the word
#the word and meaning are arranged in the dictionary as a key - value pair
#where key is the word and value is the meaning of the word
#the meaning is utilized to provide hint in the game
selectedMeaning = wordDict[selectedWord]
#gets the number of characters in the word
noOfLettersInWord = len(selectedWord)
#just prints the selected word and its meaning
print selectedWord, selectedMeaning
#prints blanks to enter the word. The number of blanks equals the number
of letters in the randomly selected word.
print "__ " * noOfLettersInWord
I hope that helps.
Pravin