2

I'm having some trouble working on a basic program I'm making whilst I try and learn Python, the problem is I am trying to compare a users input to a variable that I have set and it is not working when I try and compare them.

This is the loop in question:

    if del_question  == "1":
    symbol = input("What symbol would you like to change?: ")
    while len(symbol) != 1 or symbol not in words:
        print("Sorry, that is not a valid symbol")
        symbol = input("What symbol would you like to change?: ")
    letter = input("What would you like to change it to?: ")
    while letter in words and len(letter) != 1:
        print("Sorry, that is not a valid letter")
        letter = input("What letter would you like to change?: ")
    dictionary[symbol] = letter
    words = words.replace(symbol, letter)
    print("Here is your new code: \n", words)

The game is about breaking the code by pairing letters and symbols, this is where the letters and symbols are paired but on the letter input when I try and make it so that you are unable to pair up the same letter twice it simply bypasses it. It is working on the symbol input but I'm not sure on why it's not working here.

Here is the text file importing:

code_file = open("words.txt", "r")
word_file = open("solved.txt", "r")
letter_file = open("letter.txt", "r")

and:

solved = word_file.read()
words = code_file.read()
clue = clues_file.read()

This is the contents of the words file:

#+/084&"
#3*#%#+
8%203:
,1$&
!-*%
.#7&33&
#*#71%
&-&641'2
#))85
9&330*

1 Answer 1

1

Your bug is a simple logic error. You have an and conditional when you really want an or conditional. Change your second while statement to:

while letter in words or len(letter) != 1
Sign up to request clarification or add additional context in comments.

2 Comments

I've added that to the while loop and it still isn't working. Is it meant to be where len is?
@Kootch I think the point is to change your and into an or; it's unclear not sure if you changed that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.