So I was doing some exercises to help me learn python - I had to give it a break during exams, but I'm learning again. I can't get this bit of code to work, there is a logical error in it somewhere which I can't spot.\n\nThe idea is, the user types a number and then the computer tries to guess it. It gets 20 attempts, if it goes through all 20, then the user wins and the game ends - if it guesses the correct number, it's SUPPOSED to break the while loop and tell the user that the computer won. I can't get it to work, all that happens is it goes through all 20 attempts (I've tried 100 attempts for testing to make sure it hits the number without having to run it 10 times) - after it's reached attempt 20 it tells the user that they won - even if it had guessed the number.\n\n# The number guessing game\n#\n# The computer tries to guess your number within 20 tries.\n\n# Random import\n\nimport random\n\n# Introduction\n\nprint("\\tThe Number Guessing Game")\nprint("\\t--Created by me")\n\nprint("\\n\\nWelcome to the game. To play, pick a number between 1 and 100")\n\nnumber = input("What is your number? ")\n\ntries = 1\ncount = 1\n\nwhile tries <=20 and count == 1:\n guess = random.randint(1, 100)\n print("\\n", guess)\n\n if guess == number:\n print("\\n The computer has guessed your number!")\n count += 1\n\n tries += 1\n\nif tries <=20:\n print("\\nThe computer has won! It guessed, ", number)\n print("Thanks for playing!")\n\nelif tries >20:\n print("\\nCongratulations! You have won! The computer couldn't guess your number.")\n\ninput("\\n Press Enter to exit the program")\n\n\nThis always results in the while loop completing, even if the computer hits the right number. I've tried using a break, as below, but it still doesn't work in the above code. What is confusing me most, is that the code below works fine:\n\nimport random\n\ntries = 1\nnumber = 42\n\nwhile tries <=20:\n guess = random.randint(1, 100)\n print("\\n", guess)\n\n if guess == number:\n print("\\n The computer has guessed your number!")\n break\n tries += 1\n\ninput("")\n\n\nIf the computer hits 42, the while loop breaks. Have I messed up the user input somehow? I've tried both the count, and break method to break the loop - now I'm stuck :D.