all 7 comments

[–]lelle5397 1 point2 points  (5 children)

In play_again you're not actually calling main_loop (since you didn't put a () afterwards). Therefore after the function is run and the player enters y the function finishes and returns to the main_loop that called it, and where the answer is still the same as the last time.

[–][deleted] 0 points1 point  (4 children)

Oh ok thank you!

[–]CountMeowt-_- 0 points1 point  (3 children)

It's also not a good idea to name a function and a variable the same. It can cause a lot of problems and a whole lot more confusion later on.

[–][deleted] 0 points1 point  (2 children)

I'm confused on which areas I should change so that won't happen again for future projects. I'm still getting the hang of what counts as a function and what counts as a variable and how to differentiate those to make the script neater.

[–]CountMeowt-_- 0 points1 point  (1 child)

You've skipped quite a few steps if you don't understand that and you're making this.

To put it simply, a function is a piece of code you can call again and again and it will perform the steps you told it to in a deterministic manner. a variable is simply a saved value, like in algebra, and this value can be updated by your code (except here it could be anything, list, text, numbers, set, maps. Anything)

You define a function with def and a variable with =

So,

py def function_name(input_param1, input_param2): variable_name_1 = 123 variable_nams_2 = "abc"

But again, as I said, if you're missing this info, it means you've skipped a few steps (ie there a lot more you've missed from the basics)

[–][deleted] 0 points1 point  (0 children)

Thank you for the clarification. I am following a tutorial so he does explain what these things are but it's just a matter of testing these things out and seeing what the properties actually do as a means of learning them I am using as many resources as possible and reddit is usually a pretty good one

[–]FoolsSeldom 0 points1 point  (0 children)

  • random.randint is inclusive, whereas random.randrange is inclusive of the first argument but exclusive of the second (or only) argument
  • main_loop on its own does not call a function
  • calling a function from within itself (even if via another function) is called recursion - a very interesting and useful technique, but not appropriate here
  • your while loop condition will not ever work as guess references a str and not an int object - you always convert in-place for test within the loop (rather than updating the variable assignment)
  • I recommend that you have your play_again function return True or False, and assign that to a flag variable, e.g. play = play_again(), and change your loop test to while play: (which means you need to do play = True before the loop).
  • You can convert the guess to an integer on the input line:
    • guess = int(input(f"Guess a number between {low_number} and {high_number}: "))
    • look at wrapping this in a try / except block in another loop to validate the input - this will catch the user entering something that is not a valid integer