can someone help me am trying to create a game that scrambles words then you have guess the corect words for it this what i have doen so far but it dint seem to work can sometell me what the problem.
import tinker
import random
words_list = []
f = open("words.txt")
for thing in f:
words_list.append(thing[:-1])
def jumble_word(word):
# create a list of characters of the word
char_list = list(word)
# shuffle sequence in place
random.shuffle(char_list)
# joint to form a word again
return "".join(char_list)
# create a list of jumbled words
jumbles = []
for word in words_list:
jumbles.append(jumble_word(word))
# create a dictionary from the two lists
words_dict = dict(zip(words_list, jumbles))
global tot_words
tot_words = len(words_dict)
global correct
correct = 0
# the flag variable will ensure the correctful working of score system
# otherwise, if player had got a question right, pressing "Guess" button multiple times
# would have incremented the score that many times until the "Next" button was pressed
global flag
def func():
'This is the core function of the program'
# The result of popitem() method is a tuple
# The following is an example of "sequence unpacking"
word, jumbled = words_dict.popitem()
return word, jumbled
def guess(even):
ans = input_word.GetValue()
global flag
global correct
if(ans == query[0]):
result.SetLabel(label="Congrats! You got it right.")
# remind this function that "correct" is a global variable
if(flag==1):
correct+=1
score.SetLabel(label="Your score is: "+str(correct)+"/"+str(tot_words)
flag ==0
else:
result.SetLabel(label="Sorry, wrong answer. Better luck next time!")
flag = 1
def next(event):
# After a person clicks the Start button for the first time, this will happen
nextButton.SetLabel("Next")
guessButton.Enable()
hintButton.Enable()
input_word.SetValue("")
global query
query = func()
if(words_dict!={}):
question.SetLabel(label="The jumbled word is: "+query[1])
result.SetLabel(label="Waiting for your input...")
global flag
flag = 1
else:
question.SetLabel(label="Game Over!")
result.SetLabel(label="Yup, the game is finally over!")
#create a GUI window.
root = tkinter.Tk()
#set the title.
root.title("jumbled Game")
root.mainloop()