Skip to main content
2 of 3
deleted 90 characters in body
Daniel
  • 4.5k
  • 2
  • 17
  • 40

Pretty clean looking code, but let's look at a few ways it could be better or more pythonic:

  • Use elif statements:

      if personInput == randnumb:
          # ...
      elif personInput > randnumb:  # You already know they're != at this point
          # ...
      elif ...
    
  • Use snake case for your variable names. E.g., use person_input instead of personInput (which is camel case), and rand_num instead of randnumb. In that second case, it's also more common to shorten "number" to "num" instead of "numb".

  • Use format strings instead of print's argument concatenation, e.g.:

      print("Guess lower ({} guesses left)".format(max_guesses - guesses))
    
  • Check for and handle errors:

      try:
          person_input = int(input("What is your guess? "))
      except ValueError:
          print("Not sure what you meant by that, please input an integer")
          continue
    
  • I prefer to be more safe than sorry when handling my own incrementor, such as guesses, just in case I do something funky that lets it skip over max_guesses:

      # Since you "break" on correct answer, we don't need to check that again
      if guesses >= max_guesses:
          # ...
    
scnerd
  • 2k
  • 6
  • 12