I am trying to make a "guess the word" type game. Right now I have made two classes, each one for the computers random number (called cpu_input
in the code). And a class for the user input, called user_input
in the code.
class UserInput:
def __init__(self, useri):
self.useri = useri
def get_char1(self):
return self.useri[0]
def get_char2(self):
return self.useri[1]
def get_char3(self):
return self.useri[2]
The goal here is to have a three letter word generated, and have each character from the user input and the random word be accessible. For the purpose I need, this part is working fine.
The second class is identical to this one. Just for the randomly generated number.
class CpuInput:
def __init__(self, cpui):
self.cpui = cpui
def get_char1(self):
return self.cpui[0]
def get_char2(self):
return self.cpui[1]
def get_char3(self):
return self.cpui[2]
As before, this class is working perfectly fine, for its purpose in my program.
However, I run into a problem when I want to start comparing the user_input to the cpu_input. This is what I have written:
cpu_input = CpuInput("Jet")
user_input = UserInput(input("Place user input here: "))
if cpu_input == user_input:
print("Guessed correctly.")
Here I have set the cpu_input
to ALWAYS be Jet for the sake of testing, whenever I enter Jet in the user input the program just comes to an end. Like, it just skips over the if
completely?:
This is the output:
Place user input here: Jet
Process finished with exit code 0
Am I doing something obviously wrong? Or a concept I'm just completely missing from my program? I really don't understand why the if statement isn't happening.