Posted by: Sourav | January 4, 2017

Jumbled Word Game in Python,Python Teacher Sourav,Kolkata 09748184075


import random
words=(‘album’,’window’,’session’,’cookies’,’variable’)
word=random.choice(words)
fixedword=word
jumble=”
answer=”
yorn=’y’
count=0
while word!=”:
#print word

pos=random.randrange(len(word))
#print ‘pos is ‘,pos

#print ‘word is ‘,word
jumble=jumble+word[pos]
word=word.replace(word[pos],”,1)
#print ‘jumble is ‘,jumble

while answer!=fixedword:
print ‘the jumbled version is ‘,jumble
answer=raw_input(‘take a guess’)
count=count+1
if answer==fixedword:
break
print ‘the word was ‘,fixedword,’\nthe jumbled version is ‘,jumble,’\nyou have guessed the word in ‘,count,’ guesses’

#pos=random.randrange(len(word))

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: