Python Forum
[supernoob] Can't spot the error...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[supernoob] Can't spot the error...
#1
Noob taking the first steps with Python here, I tried the following:

# guessing game

secret = 'supernoob'
guess = ''
attempts = 0
maxtry = 3
out_of_tries = False

# logic loop
while guess != secret and not out_of_tries:
    if attempts < maxtry:
        guess = input('guess the secret: ')
        attempts =+ 1
    else:
        out_of_tries = True

# outcome
if out_of_tries:
    print('You Lose!')

else:
    print('You Win')
the software (partially) works, but it doesn't stop at maxtry value. What am I doing wrong?
Reply
#2
This line is the problem:
attempts =+ 1
You're setting attempts to the same value (+1) instead of incrementing it.
What you want is:
attempts += 1
Reply
#3
thanks a lot!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can anyone spot why this function is returning an empty list? hhydration 2 1,844 Nov-18-2020, 06:16 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020