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

Using python!! Write a tkinter game Scrambler, that allows the user to guess a s

ID: 3666847 • Letter: U

Question

Using python!!

Write a tkinter game Scrambler, that allows the user to guess a scrambled word.    The game is started by giving a word and packing.   The parent can be specified or omitted, e.g, either:


>>> Scrambler("apple").pack()

>>>

Or

>>> root = Tk()

>>> Scrambler("orange",root).pack()

>>>

The game will then scramble the word and display it in the gui, see images to the right.   The user will then have 3 guesses to guess the original word.   (To scramble a word, make sure you add the import “from random import *”, then use the following code.

scramble = list( word )

shuffle(scramble)

scramble = ''.join( scramble) # this is now the scrambled word

To guess a word, the user types in the Entry and clicks the button. The game then checks the guess against the original. There are three possibilities:

The guess is correct, then the user is told “You got it” in a showinfo.

The guess is incorrect, and there is at least 1 guess left. Then the user is told the number of guesses left.

The guess is incorrect, and no guesses are left. The user is told “You lose”

example picture is here

ppael Guess

Explanation / Answer

import random
words = {'lights':'Something with multiple colors on a Christmas tree',
'santa':'Fat old man who comes around Christmas',
'elves':'Little people with pointy ears that work with Santa',
'ornaments':'Accessories that get hung on a Christmas tree',
'garland':'Think tinsel for a Christmas tree'}
def Intro():
print('Scramble ')
print('Word Scramble! ')
print('I'm going to show you a scrambled word and give you three guesses.')
print('After your second guess, I'll help by giving you a hint. ')
def getWord(word):
wordKey = random.choice(list(word.keys()))
return wordKey
def getHint():
hint = len(wordKey.index)
return hint
def getGuess1():
guess = input(' Enter your first guess: ')
while True:
if guess.isalpha():
return guess
else:
guess = input(' Please enter a letter: ')
def getGuess2():
guess = input(' Enter your second guess: ')
while True:
if guess.isalpha():
return guess
else:
guess = input(' Please enter a letter: ')
def getGuess3():
guess = input(' Enter your final guess: ')
while True:
if guess.isalpha():
return guess
else:
guess = input(' Please enter a letter: ')
def cheatCode(yes, werd):
x = werd[0]
y = werd[1]
print(x, end = '')
print(y)
return x, y
#=====MAIN PROGRAM=======#

ans = 'y'
guesses = 0
while ans == 'y':
Intro()
w0rd = getWord(words)
scramWord = list(w0rd)
random.shuffle(scramWord)
sWord = ''.join(scramWord)
print('The scrambled word is ' +sWord)
guessed = getGuess1()
if guessed == w0rd:
print('Congratulations!')
ans = 'y'
if guessed != w0rd:
print('Nope, sorry')
guesses = guesses + 1
cheat = input('Do you want help? [y/n] ')
if cheat == 'y' or cheat == 'Y':
cheatInput = input('Type "HELPME or HELP": ')
cheatCode(cheatInput, w0rd)
guessed2 = getGuess2()
if guessed2 == w0rd:
print('Congratulations!')
ans = 'y'
if guessed2 != w0rd:
print('Nope, sorry')
guesses = guesses + 1
cheat = input('Do you want help? ')
if cheat == 'y' or cheat == 'Y':
cheatInput = input('Type "HELPME or HELP"')
cheatCode(cheatInput, w0rd)
while guesses == 2:
hint = words[w0rd]
print('Heres a hint ===> '+hint)
guesses = guesses + 1
guessed3 = getGuess3()
if guessed3 == w0rd:
print(' Congratulations! ')
else:
if guessed3 != w0rd:
print(' Nope, sorry. The word was ''+w0rd+'' Better luck next time')
guesses = 0
print(' would you like to play again?[y/n]', end = ' ')
ans = input()
if ans == 'n' or ans == 'N':
print(' Goodbye then')

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