Thursday 15 July 2010

python - How do I pull individual words from a list when needed? -



python - How do I pull individual words from a list when needed? -

#word jumble game import random import string def jumbled(): words = ['jumble', 'star']#, 'candy', 'wings', 'power', 'string', 'shopping', 'blonde', 'steak', 'speakers', 'case', 'stubborn', 'cat', 'marker', 'elevator', 'taxi', 'eight', 'tomato', 'penguin', 'custard'] count = 0 loop = true loop2 = true while loop: word = string.lower(random.choice(words) jumble = list(word) random.shuffle(jumble) scrambled = "".join(jumble) while loop2: print '\n',scrambled,'\n' guess = raw_input('guess word: ') quit = set(['quit','quit']) selection = 'quit' if guess.lower() == word: print '\ncorrect!' count+=1 print "you took",count,"trie(s) in order right answer",jumbled() else: print '\ntry again!\n' count+=1 if count == 3: if words[0]*2: print "it looks you're having trouble!" print 'your hint is: %s'(words) # i'm trying pull word above list here. jumbled()

so here am, playing game i've programmed chooses random word list, mixes have correctly guess it. process works , if wrong, message saying seek 1 time again , if correct, congratulate me onto next word!

a problem i'm having want able give hint if user incorrectly guesses after 3 times. however, if programme gives me, 'jumble' word have guess , guess wrong 3 times, hint based off word. can't word star hint has jumble, can i?

with code have (i have commented line i'm having problem with), error saying string not callable, don't know call...

please help!

if it's not much trouble, need able type in quit game quit itself, unfortunately, don't know how this.

thanks in advance!

you have unjumbled word in word illustration use

print 'your hint is: %s'%word

very easy hint though

you create dict map words clues eg

hint_dict = {'jumble': 'name of game.", "star": ...}

and use

print 'your hint is: %s'%hint_dict[word]

python words mixed

No comments:

Post a Comment