+ 8

I am trying to make a game.

Hello and good day. I'm trying to make a "guess the number" game but have a problem. The game works great right now but It's very simple. I'm trying to make it so that I can have a user input a number, and if it is wrong, they can try again using one of their lives. I'm off to a good start so far I think. Problem: How can I make it so that a user can input again if they guess incorrectly? Currently when the user guesses incorrectly, the game is over as I can't figure out how to let the user add another input. Can anyone help me? The code is below...: import random rnum = random.randint(0, 5) guess = int(input()) chances = 0 while chances >= 0: if guess == rnum: print("you got it!") break elif guess != rnum: print("That's not it!") chances = 0+1 print('You have used', chances, 'of your chances.') break continue

3rd Sep 2020, 5:12 AM
Parallel Visions
Parallel Visions - avatar
41 Respuestas
+ 4
Slick Excuse me are you babysitting...? i just commented because i care and speaking of long enough,i am long ENOUGH .........
4th Sep 2020, 2:31 AM
Xavier Christian
Xavier Christian - avatar
+ 4
try making the guess=int(input()) inside the while block
4th Sep 2020, 7:42 AM
Bot
Bot - avatar
+ 3
Parallel Visions import random rnum = random.randint(0, 5) chances = 0 while chances >= 0: guess = int(input()) if guess == rnum: print("you got it!") break elif guess != rnum: print("That's not it!") chances = 0+1 print('You have used', chances, 'of your chances.') Try this.
3rd Sep 2020, 6:01 AM
Allamprabhu Hiremath
+ 3
Why are you using chances=0+1 instead of chances++ ?
4th Sep 2020, 10:46 PM
Sonic
Sonic - avatar
+ 3
The break statement needs to be executed when the guess is correct not when incorrect.
4th Sep 2020, 10:47 PM
Sonic
Sonic - avatar
+ 2
Sorry buddy, especially to someone whos been here long enough and knows the same as i. I dont have to conform to what you consider polite, or are you too up your own self to see that? You call it a problem, I dont care. Xavier Christian Im here to help, not to babysit.
4th Sep 2020, 2:21 AM
Slick
Slick - avatar
+ 2
I think it is very difficult with python , i can do with web , do u know about web(html,css,js,etc.)Parallel Visions
4th Sep 2020, 11:04 AM
Priyanshu Gupta(प्रियांशु गुप्ता)
Priyanshu Gupta(प्रियांशु गुप्ता) - avatar
+ 2
Good
4th Sep 2020, 3:00 PM
Aashutøsh
Aashutøsh - avatar
+ 2
Check out this code , it's quite similar to what you are to do, you'll understand it easily:- Parallel Visions :- https://repl.it/@HindBiswas/Riddle-10#main.py
4th Sep 2020, 4:27 PM
Hind Biswas
Hind Biswas - avatar
+ 2
You are only taking one guess.
4th Sep 2020, 10:45 PM
Sonic
Sonic - avatar
+ 2
You don't need the continue statement.
4th Sep 2020, 10:46 PM
Sonic
Sonic - avatar
+ 1
Kind of but not exactly. Look at the parenthesis underneath in my last post, it shows the equivalent equation, just spread out so you can see how it works. You can use either one
3rd Sep 2020, 6:01 AM
Slick
Slick - avatar
+ 1
So I've done what you said slick, but the code infinitely loops but counts up by 1 each line. Because of the += of course. I’ll keep trying though.
3rd Sep 2020, 6:06 AM
Parallel Visions
Parallel Visions - avatar
+ 1
Cool, since this guy just served up the code like a waiter you can take a look. Pay attension to where the input is placed and keep trying. Youre on the right track
3rd Sep 2020, 6:08 AM
Slick
Slick - avatar
+ 1
You don't have to keep replying and helping of course, but even using his code it doesn't work. Its just an infinite loop. His code is cleaner because of the elif loop. https://code.sololearn.com/cVhmFHW7iGWi/?ref=app
3rd Sep 2020, 6:20 AM
Parallel Visions
Parallel Visions - avatar
+ 1
That bottom while loop shouldnt be there. What would really help is an ide with a debugger. You can stop the code wherever you want and single step through it to see exactly how everything is working
3rd Sep 2020, 6:24 AM
Slick
Slick - avatar
+ 1
Take input inside the loop so that after every guess it will ask for input,change chances=0+1to Chance+=1 sothat its values increases one after every guess And remove that break and continue
3rd Sep 2020, 8:07 AM
Pulluri Sai Lalith
Pulluri Sai Lalith - avatar
+ 1
Maybe also enter the number of chances used so far into the input, as well as your guess, each time you run it? It's open to cheating of course but where's the fun in that?
4th Sep 2020, 12:42 AM
Matthew Spurrier
Matthew Spurrier - avatar
+ 1
Hey Slick, Allamprabhu Hiremath was just trying to helpm ,to me you're kinda rude
4th Sep 2020, 1:28 AM
Xavier Christian
Xavier Christian - avatar
+ 1
Xavier Christian And? This isnt a place to just give code away. You need to do things for yourself. Thats why its SOLOlearn. We are here to help, not to do your homework.
4th Sep 2020, 2:11 AM
Slick
Slick - avatar