-10

I'm creating a game in python and it's a number game in which the user must add the sum of random numbers to get the answer with a certain amount of tries.When I ran it, the user may get the number before their tries are over ,but the game will continue and sometimes when they win...it won't tell them that they have won.How do I stop this problem and what statement should I use.

The number being used it 31 and my program uses the computer to randomize numbers and the player has to chose if they want to keep or delete the random number.They have 15 tries to get 31.

If it helps I use python 2.7.5 on MAC

Thank You!!!!

Doseph
  • 199
  • 3
  • 17

2 Answers2

0

Try using a while loop.

counter = 0
while counter < 15:
    if guess == number:
        break
    counter += 1
    guess = int(input('Input your new guess'))
Eli Sadoff
  • 7,173
  • 6
  • 33
  • 61
-1

If you are using a while loop, you could do something like:

tries = 0

while guess != answer or tries < 15:
    """Do stuff here"""
    ...
    tries += 1

if tries < 15:
    print("Winner!")
else:
    print("Loser!")

I hope this helps!

pat
  • 69
  • 2
  • 10