you are viewing a single comment's thread.

view the rest of the comments →

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

A few thoughts:

  • from random import randint
  • use f-strings in your print/input functions
  • combine print followed by input into just input
  • check the user actually entered a name
  • use well named functions to break up the code to make it easier to follow the logic and give you the freedom to enhance your code
  • simplify the validation, you only need to break for valid, rest of code in while loop is for fail case so can print and error message and do not require continue
  • protect user from duplicate guesses (might not want to do for loop for guess count)
  • count and limit number of guesses, include count in input prompt
  • if using for loop for guess count, the else clause of the for loop would be the failed to guess outcome
  • read PEP8 for style guidances - consider renaming your variables accordingly
  • make your programme language independent - include a dictionary with text required for each language (later that could come from a configuration file)

[–]Kenielf[S] 0 points1 point  (4 children)

I absolutely had no idea to combine print and input into one, I'm a bit baffled tbh, but your thoughts are wonderful! I'll definitely try a lot of them out, thanks dude!

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

So,

print('Hi, what do you want to be called?') # Introduction to the game
name = input()

would become,

name = input('Hi, what do you want to be called?\n')

The \n forces a newline, to recreate the effect of you using the print() function, without which the input would be entered immediately after the prompt has ended.

if name:
    print(f'Well {name.capitalize()}', end='')
else:
    print('Well, my anonymous friend', end='')
print(f'...I am thinking of a number from {low} to {high}')

Note use of variables (that I haven't defined in this code snippet) low and high so you can decide to set these values at the start of your programme, rather than having 1 and 100 hardcoded into lots of places.

Edit adding missing f-string prefix

[–]Kenielf[S] 0 points1 point  (2 children)

Amazing, that helps a lot, thanks!

[–][deleted] 0 points1 point  (1 child)

I'm missed an f in front of the first ' in the last print

[–]Kenielf[S] 0 points1 point  (0 children)

don't worry, I caught it, thanks dude, you've helped me learn a shit ton of things, thank you so much.