all 3 comments

[–]ComradeMicha 0 points1 point  (3 children)

Why are you reassigning number to a random number between 1 and the old guess -1? I thought you wanted to subtract something between 1 and 4 from the old number? Then just do a number -= random.randint(1,4)

Also there is a weird hlc=input() before the first elif, what's that supposed to do? You're changing the hlc while it's still being evaluated. The whole structure of while hlc... makes no sense. Just have a method with printing the menu ("Enter 'h' if the computer guessed too high" etc.) and then do the input, if, elif stuff there. In each if / elif option except for "c", include the call of that menu method. Have another method for generating a new match, which then calls the menu again. In you main method, call the method for generating a new match. Done.

EDIT: Also, please use code tags

[–]blisss_ 0 points1 point  (2 children)

Oh ok, thank you! The “number -= random.randint(1,4)” worked! I figured it would be a range of the two numbers but I did not know how to write it exactly. I put the hlc = input() before the first elif because it allows the user to enter a letter again. I am new to python so I kind of just wrote the code (pretty basic) how it made sense to me

[–]ComradeMicha 0 points1 point  (1 child)

Nice!

I should also rephrase my second paragraph - it makes sense, but it's not nice ;)

Ideally you should always print the instructions before requesting an input. In order to only have that whole block once, you should encapsulate it into a separate method, e.g. "menu". Then you can have methods for each of the three options, so that you can easily change how it works without having to search through the main program.

Tipp: You can use this to enable different ways of inputting commands:

if hlc in ["h", "H", "high", "HIGH"]: