guessthenumber print games left

E

eschneider92

Could anyone tell me how to make the program tell me how many games are left before the first game and second game? For example, after one game of guess the number, I want it to tell me that i get one more game. P.S. I'm totally new to python (obviously), and I just added numberofgames variable in hopes of solving this problem. am I on the right track? Thanks for any assistance!
numberofgames=1
while numberofgames<4:
numberofgames=numberofgames+2
import random
print ('type name')
name=input()
print ('guess a number between 1 and 20, ' + name)
number=random.randint(1,20)
guessestaken=0
while guessestaken<5:
guessestaken=guessestaken+1
guess=input()
guess=int(guess)
if guess<number:
print ('your guess is too low')
if guess>number:
print ('your guess is too high0')
if guess==number:
break
if guess==number:
print ('you win!')
if guess!=number:
number=str(number)
print ('you lose. the number was ' + number)

C

Chris Angelico

Could anyone tell me how to make the program tell me how many games are left before the first game and second game? For example, after one game of guess the number, I want it to tell me that i get one more game. P.S. I'm totally new to python (obviously), and I just added numberofgames variable inhopes of solving this problem. am I on the right track? Thanks for any assistance!
numberofgames=1
while numberofgames<4:
numberofgames=numberofgames+2

First off, why are you adding two? Is this a typo?

You have here a counter, but it's counting up. To figure out how many
games are left, just subtract the numberofgames from the total number
of games that you'll be allowing - that's how many there are left. Do
you know how to do that?

ChrisA

E

eschneider92

First off, why are you adding two? Is this a typo?

You have here a counter, but it's counting up. To figure out how many

games are left, just subtract the numberofgames from the total number

of games that you'll be allowing - that's how many there are left. Do

you know how to do that?

ChrisA

Thanks for the quick reply. I've been trying your advice but I can't figureit out. If anyone could show me how to do it in program form, it would be much obliged.

E

eschneider92

First off, why are you adding two? Is this a typo?

You have here a counter, but it's counting up. To figure out how many

games are left, just subtract the numberofgames from the total number

of games that you'll be allowing - that's how many there are left. Do

you know how to do that?

ChrisA

Thanks for the quick reply. I've been trying your advice but I can't figureit out. If anyone could show me how to do it in program form, it would be much obliged.

C

Chris Angelico

Thanks for the quick reply. I've been trying your advice but I can't figure it out. If anyone could show me how to do it in program form, it would be much obliged.

Set your current code aside, and just make a program that counts games
code:

numberofgames=1
while numberofgames<4:
numberofgames=numberofgames+2

That will run, but do nothing. Now add a print call to the loop, and
see if you can work out how to make it count how many games are left.

If you get stuck, post the code for just this program and we'll see
where it takes us!

ChrisA

E

eschneider92

Could anyone tell me how to make the program tell me how many games are left before the first game and second game? For example, after one game of guess the number, I want it to tell me that i get one more game. P.S. I'm totally new to python (obviously), and I just added numberofgames variable inhopes of solving this problem. am I on the right track? Thanks for any assistance!

numberofgames=1

while numberofgames<4:

numberofgames=numberofgames+2

import random

print ('type name')

name=input()

print ('guess a number between 1 and 20, ' + name)

number=random.randint(1,20)

guessestaken=0

while guessestaken<5:

guessestaken=guessestaken+1

guess=input()

guess=int(guess)

if guess<number:

print ('your guess is too low')

if guess>number:

print ('your guess is too high0')

if guess==number:

break

if guess==number:

print ('you win!')

if guess!=number:

number=str(number)

print ('you lose. the number was ' + number)

I can't figure out how to make it count down by itself and state how many are left.

E

eschneider92

(Didn't mean to post the last bit.) Is this possibly what you meant? If it is I still can't figure out how to apply it to the guessthenumber program.
numberofgames=1
while numberofgames<4:
numberofgames=numberofgames+2
print (4-numberofgames)
if numberofguesses>3:
print(numberofgames)

C

Chris Angelico

(Didn't mean to post the last bit.) Is this possibly what you meant? If it is I still can't figure out how to apply it to the guessthenumber program.
numberofgames=1
while numberofgames<4:
numberofgames=numberofgames+2
print (4-numberofgames)
if numberofguesses>3:
print(numberofgames)

That's close to it. I still don't understand why you're adding two,
and the last print seems to be unnecessary. But if you just add one,
then yes, that would be exactly what you want.

ChrisA

E

eschneider92

How do I make it say that I have one game left? I'm having trouble fitting it into my main code. Thanks a lot for the help btw.

C

Chris Angelico

How do I make it say that I have one game left? I'm having trouble fitting it into my main code. Thanks a lot for the help btw.

The main confusion seems to be over whether to add one or two. If you
add one, it'll tell you you have just one game left (at some point).
Try that!

ChrisA

E

eschneider92

The 2 makes the game play twice instead of 3 times, right? I've tried it with the 1, but but I'm still having trouble. Again, to be exact, I want to somehow make it count down from 2 (the number of games)and print. If that's what this does, is it possible to insert it into my original main program?

C

Chris Angelico

The 2 makes the game play twice instead of 3 times, right? I've tried it with the 1, but but I'm still having trouble. Again, to be exact, I want tosomehow make it count down from 2 (the number of games)and print. If that's what this does, is it possible to insert it into my original main program?

Let's leave Python aside for a moment and go back to grade-school arithmetic.

How do you count up to three?
1, 2, 3

How much do you add to a number to get to the next number?

Once you figure out where you're starting, how much you're increasing
at each step, and where you're stopping, you can put those numbers

ChrisA

E

eschneider92

If you get the time, please post an example, because I don't understand.

C

Chris Angelico

If you get the time, please post an example, because I don't understand.

(It helps to include some quoted text to provide context to your post.)

Imagine you had a program that just showed the number of games left,
nothing else. Write me out what you would expect that program to
output. Just do it manually so I can see what you're trying to do.

ChrisA

N

Neil Cerutti

If you get the time, please post an example, because I don't
understand.

Maybe it would help to think about contraints. Write them next to
your variable names, and then check, at every point in your
program, if the contraint is still true.

Here's and example.

maximum_games = 4 # You must stop playing after 4 games.
games_played = 0 # Always equals the number of games played
while games_played < maximum_games:
play_game()
# This is where you update games_played to reflect the number
# of games played.