In every case

In the guessing game I have this code:

numOfTries += 1     
if theNumber > given:
  print("NO it's larger")
elif theNumber < given:
  print("No it's smaller")
else:
  print("You guessed it in %d guesses" % numOfTries)

Before that I had done the following:

if theNumber > given:
  print("NO it's larger")
  numOfTries += 1
elif theNumber < given:
  print("No it's smaller")
  numOfTries += 1
else:
  print("You guessed it in %d guesses" % numOfTries)

but it didn’t work because even if you get it right, you have tried!
So I turned it to:

if theNumber > given:
  print("NO it's larger")
  numOfTries += 1
elif theNumber < given:
  print("No it's smaller")
  numOfTries += 1
else:
  numOfTries += 1
  print("You guessed it in %d guesses" % numOfTries)

and only then I thought that numOfTries += 1 should go on top.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s