Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In python 2.7: See image for original assignment. My code doesnt run properly in

ID: 3758395 • Letter: I

Question

In python 2.7: See image for original assignment.

My code doesnt run properly in canopy. Can someone please help me fix it.

My code:

import random

words=('python','jumble','easy','difficult','answer','xylophone')

word=random.choice(words)

correct=word

jumble=""

while word:

position=random.randrange(len(word))

jumble+=word[position]

word=word[:position]+word[(position+1):]

score=0

print "The jumble is:",jumble

guess=raw_input(' Your guess: ')

guess=guess.lower()

lst=range(len(jumble))

hint_str='_'*len(jumble)

while True:

if guess==correct:

print "Thats it! You guessed it! Your score is",score

raw_input(" Press the enter key to exit.")

break

guess=raw_input("Guess or'?' or 'X': ").lower()

elif guess=='?':

i=random.choice(lst)

print correct[i],"is the",i+1,"letter."

score+=1

guess=raw_input("Guess or '?' or 'X': ").lower()

elif guess=='X':

print "Sorry you gave up!"

break

else:

print "Sorry, thats not it. Try again."

Explanation / Answer

import random
hints = dict(
python = "THIS programming language.",
jumble = "To shake things up.",
easy = "The opposite of difficult.",
difficult = "The opposite of easy.",
answer = "Every question has an...",
xylophone = "A whacky instrument.",
)

WORDS = list(hints)   
word = random.choice(WORDS)
score = 0
L = list(word)
random.shuffle(L)
jumble = ''.join(L)   
print("""Welcome to Word Jumble! Unscramble the letters to make a word. (Press the enter key at the prompt to quit.) """)
print("The jumble is:", jumble)
print(" To get a hint, type 'hint'")
guess = input(" Your guess: ")
if guess == "hint":
score += 1
print(hints[word])
guess = input("Your guess: ")
while guess and (guess != word) and (guess != "hint"):
print("Sorry, that's not it.")
guess = input("Your guess: ")
if guess == word: # this was a repeated test, so I nested the subordinates
if score:
print(" That's it! You guessed it!")
print(" Thanks for playing, but there's no reward because you needed help.")
else:
print(" That's it! You guessed it!")
print(" AND you needed NO help, here's a cookie: NOM! NOM! NOM! COOKIE!")
input(" Press the enter key to exit.")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote