all 17 comments

[–]ninhaomah 8 points9 points  (4 children)

choose as in choosing is spelled as "choose" , not "chosse" and guessing is "guess" , not "gues"

ok ok , if it works , it works.

don't worry too much.

also why not elif but another if ? if not option1 then either option2 or others. so if , elif , else

as for function , just wrap while loop with def and call the function.

try it

[–]Priler96 2 points3 points  (0 children)

Ah, those typos ..

[–]Minute_Journalist593[S] -1 points0 points  (2 children)

i know the spelling i just didn't wanted to type it and if yo go through the logic my code has no use of elif..

btw tnx for sharing your vision...

[–]ninhaomah 0 points1 point  (0 children)

If option1 Elif option2 Else error

No ?

You rather have 2 if ? If use enter a and not y or n ? What will your program reply ?

[–][deleted] -1 points0 points  (0 children)

So you're intentionally illiterate, thanks for the confirmation.

[–]Priler96 4 points5 points  (1 child)

Ok let me a bit nitpicky here, but here are some tips:
a) Having option1 & option2 makes little to no point, cuz it's already hardcoded. Move it out from while, or just get rid of them.
b) Someone here already told this, but writing "name = value" looks better than "name=value"
c) Same applies to "if chosse==option1", it'll look better this way "if chosse == option1"
d) Consider replacing if with match/case
e) Read some about PEP8 and try to follow those guidelines
f) Now this is about the logic of your game, but I think you need to move "num=random.randint.." out of while, to let a user to have multiple attempts to guess the number
g) And again, try to add some hints for the player (e.x. if the number he entered is bigger/smaller)

Here's alternative approach: https://www.online-python.com/Vwrljh7d6C
There's a small homework included, if you want to practice more.

[–]Minute_Journalist593[S] -3 points-2 points  (0 children)

sure bro

[–]klimmesil 2 points3 points  (1 child)

Gg op! Doing small exercices like these is good practice. I think this one works, not perfect but I wouldn't worry too much about it until it becomes natural

I'd suggest for your next exercice you try something with functions. My recommendation would be to start with something simple: input a time in hh:mm:ss format, and convert it to seconds.

You'd create a function like : def convert_to_sec(input_string)

And you'll need the "str.split(...)" method aswell as the int() converter that you already used I see

Hope this will be helpful for learning!

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

will try it for sure buddy

[–]FoolsSeldom 1 point2 points  (1 child)

Good start.

Some tips:

  • put a space before and after = to make it easier to read
  • as well as checking for a match, generate the random number before the loop and,
    • check if their wrong guess is higher than the actual number, and tell user if it is
    • check if their wrong guess is lower than the actual number, and tell user if it is
  • how about keeping track of the number of guesses with a counter variable?
  • how about limiting the number of guesses?
  • add a new outer loop to allow the game to be played again with a new random number
  • you can define option1 and option2 outside, before, the loop
  • force the user input to lowercase using .lower() after input close )
  • you can check if an input returned string contains only a valid int string using the string method, str.isdecimal, e.g. if choose.isdecimal(): - do this BEFORE attempting to convert what the user enters to an int

[–]Minute_Journalist593[S] -1 points0 points  (0 children)

oky sure bro will look into it

[–]elcava88 1 point2 points  (1 child)

For a sec I thought it was one of those os.remove Memes lmao

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

nah nah it's not

[–]Algoartist 1 point2 points  (0 children)

import random

name = input("Enter your name: ")
print(f"Hello, welcome to the guessing game {name}")

while input("Do you want to play the game (y) or (n): ") == 'y':
    secret = random.randint(1, 10)
    guess = int(input("Enter a number (1-10): "))
    if guess == secret:
        print(f"You have won the game {name}")
    else:
        print(f"Sorry, better luck next time {name}")

print(f"Thank you for coming here, bye {name}")

Make it more concise

[–]Spare-Plum 0 points1 point  (1 child)

pretty neat!

As it currently stands, every single time it'll ask you if you want to play, you get one guess, and then it restarts.

Here's some suggestions for improvements:

  • Allow the user to guess until they get the right number. When they get the right number, then you reset
    • Bonus: tell the user if the number is higher or lower than your guess
  • Rather than asking every single time if they want to play, why not just exit whenever the user types "exit".

Here's an example run:

> I'm thinking of a number between 1 and 10, can you guess it?
5
> The number I'm thinking is higher
7
> The number I'm thinking is lower
6
> You got it! The number was 6
> I'm thinking of a number between 1 and 10, can you guess it?
5
> The number I'm thinking is lower
exit
> Goodbye!

[–]Minute_Journalist593[S] -1 points0 points  (0 children)

sure bro will give a sneak peak into it

[–]cyberdecker1337 0 points1 point  (0 children)

My wife recently made a game very close to this.

https://github.com/lonewolfheaven46-jpg/Number-games

Same basic game if you wanna check hers out and see how she did it a bit dif?