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

Using t kinter, create a widget called GuessGame that, when passed a number and

ID: 3667156 • Letter: U

Question

Using t kinter, create a widget called GuessGame that, when passed a number and packed, creates a gui that allows the user to guess the number. The guessing game widget can be created either by creating a widget and packing it (in which case a default Tk window Is created): >>> GuessGame(7).pack() Or by creating a parent window and adding the widget to it: >>> from tkinter import Tk >>> root - Tk() >>> GuessGame (7, root) .pack () When created, the game remembers the secret number. When the user types a number and dicks the Guess button, one of the following three show info windows is shown depending on whether the guessed number is too low, too high, or just night The user should be able to repeatedly guess until the main window is closed:

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