1

Disclaimer I am a noob. Just started learning python. I know no computer languages, I just thought it would be nice to change my career for me and my family. I'm learning from online video on youtube. I think he is good... I still don't understand/know what he is talking about(terminology and stuff) but im trying to follow along and hoping I will understand wth he is talking about after hearing him say the words over and over again....

The problem is, if I win, it still says that I lose... If I lose it doesn't say that I WON... so what do I have to do differently?

I tried … if guess =/= secret_number: but apparently that / doesn't mean not equal to...

My code -

secret_number = 9
guess_count = 0
guess_limit = 3
while guess_count < guess_limit:
    guess = int(input('Guess: '))
    guess_count += 1
    if guess == secret_number:
            print('You Won!')
    else:
            print('You Lose!')
Red
  • 26,798
  • 7
  • 36
  • 58
clonekorea
  • 21
  • 2
  • 8
    Please [edit] and fix your indentation. – 001 May 21 '20 at 00:44
  • 1
    Does this answer your question? [Is there a "not equal" operator in Python?](https://stackoverflow.com/questions/11060506/is-there-a-not-equal-operator-in-python) – c2huc2hu May 21 '20 at 00:50
  • 1
    You really do need to make sure the indentation shown here looks exactly as you have it in your actual code. If you've done it properly, then the code should work and you need to be more clear about what's happening. I can think of exactly one way you might have done it improperly, though. – Karl Knechtel May 21 '20 at 01:02
  • hi sorry it didn't transfer properly. but the code is working. the problem which I didn't know till now is that when you guess correctly the 1st time it just says you win... which is good... but if you guess correctly on the third try it says you win AND you lose – clonekorea May 21 '20 at 16:02
  • ok I found it out guys... got to add a break after you won line. Thank you for your input!!! – clonekorea May 21 '20 at 16:08
  • also thanks I found out "not equal" can also be showed as != – clonekorea May 21 '20 at 16:21

2 Answers2

3
secret_number = 9
guess_count = 0
guess_limit = 3
while guess_count < guess_limit:
    guess = int(input('Guess: '))
    guess_count += 1
    if guess == secret_number:
        print('You Won!')
        break
else:
    print('You Lose!')

your code is right. I guess your problem is the indentation of if statement. you need to have if in your while loop so every time you get a number you can check if it's right or not

hamid.khb
  • 432
  • 2
  • 11
  • hi thanks for the response. So I guess it didn't transfer properly. I had trouble inputing the code properly into the stackoverflow website. I guess I didn't clarify enough... but at the time I didn't know…. If you win by guessing 9 the first time it says You won... but if you wait till the 3rd try to guess correctly it will say you won... AND you lose … so I guess I didn't explain the problem correctly but I had assumed that You lose displayed after every win... didn't know it was only if you win on the 3rd attempt – clonekorea May 21 '20 at 15:20
  • So did my code solve your problem or you still need to change it? – hamid.khb May 21 '20 at 16:59
1
secret_number = 9
guess_count = 0
guess_limit = 3
status = False
while guess_count < guess_limit:
    guess = int(input('Guess: '))
    guess_count += 1
    if guess == secret_number:
        print('You Won!')
        status = True
        break
if status == False:
    print('You Lose!')
  • I didn't see you posted how to fix it... I didn't know about adding break... but I found the answer thanks for the fast response ! – clonekorea May 21 '20 at 16:10