Explanation: So I am trying to check if two variables (which are equal) and then changing the points of the game. The problem I am having is that the if statement: "if str(word) == str(guess):" is returning false even though both values are true? I deeply confused about why this is happening and hoping someone has the answer thanks!
All Code:
from tkinter import *
import random, time
root = Tk()
root.title("Anagrams")
#### MODLE (Data,Methods) ####
points = 0
word = ""
word_shuffled = ""
guess = ""
difficulty = 0
words = [["hug", "its", "leg", "lee", "mad", "map", "mug", "nap", "nay", "won", "wed"],
["cone", "cool", "crap", "dads", "deaf", "dear", "dial", "dice", "maps", "mace"],
["dairy", "dikes", "dozen", "fiber", "eager", "exist", "field", "flesh", "fuels", "glare"],
["expect", "former", "filler", "framed", "friend", "fringe", "heater", "hocked", "hustle", "insect"]]
def start():
global difficulty, points
update_points()
get_word()
difficulty = 0
points = 0
root.after_cancel(get_word)
def get_word():
global word, difficulty, word_shuffled
if difficulty <= 3:
word = words[difficulty][random.randint(0,9)]
word_shuffled = shuffle_word(word)
output.config(state=NORMAL)
output.delete('1.0', END)
output.insert(END, "You letters to make an anagram with: " + str(word_shuffled))
output.see(END)
output.config(state=DISABLED)
root.after(10000, change_dificulty)
else:
root.after_cancel(get_word)
end()
def enter_word():
global guess, points, word, guess
guess = str(textenter.get('1.0', END))
print(word + " " + guess)
if str(word) == str(guess):
points += ((difficulty + 1) * 10)
root.after_cancel(get_word)
change_dificulty()
else:
points -= ((difficulty + 1) * 10)
update_points()
def change_dificulty():
global difficulty
difficulty += 1
get_word()
def shuffle_word(word1):
word1 = list(word1)
random.shuffle(word1)
return ''.join(word1)
def end():
global points
output.config(state=NORMAL)
output.delete('1.0', END)
output.insert(END, "You final points are: " + str(points))
output.see(END)
output.config(state=DISABLED)
def update_points():
global points
point.config(state=NORMAL)
point.delete('1.0', END)
point.insert(END, str(points))
point.see(END)
point.config(state=DISABLED)
#### Controlers (Widgets that change data) ####
start = Button(root, text="Press to Start", command=start)
start.grid(row=0, column=0, sticky="W")
enter = Button(root, text="Press to Enter", command=enter_word)
enter.grid(row=0, column=9)
textenter = Text(root, height=1, width=10)
textenter.grid(row=0, column=10, sticky="W")
label = Label(root, text="Points:")
label.grid(row=0, column=4, sticky="E")
point = Text(root, height=1, width=5)
point.grid(row=0, column=5)
point.insert(END, points)
point.see(END)
point.config(state=DISABLED)
#### VIEW (Widgets that display outputs) ####
output = Text(root, width=60, height=1)
output.grid(row=1, column=0, columnspan="11")
output.insert(END, "Points: 3 Letters:+/-10, 4 Letters:+/-20 etc...")
output.see(END)
output.config(state=DISABLED)
root.mainloop()
Where I am having the problem:
def enter_word():
global guess, points, word, guess
guess = str(textenter.get('1.0', END))
print(word + " " + guess)
if str(word) == str(guess):
points += ((difficulty + 1) * 10)
root.after_cancel(get_word)
change_dificulty()
else:
points -= ((difficulty + 1) * 10)
update_points()
Outputs for the strings "guess" and "word":
D:\Devlopment\Python\AP Comp Project #1\venv\Scripts\python.exe" C:/Users/lucia/Desktop/main.py
hug hug