Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43261 > unrolled thread

guessthenumber print games left

Started byeschneider92@comcast.net
First post2013-04-10 02:39 -0700
Last post2013-04-11 12:31 +0000
Articles 15 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  guessthenumber print games left eschneider92@comcast.net - 2013-04-10 02:39 -0700
    Re: guessthenumber print games left Chris Angelico <rosuav@gmail.com> - 2013-04-10 19:44 +1000
      Re: guessthenumber print games left eschneider92@comcast.net - 2013-04-10 14:01 -0700
        Re: guessthenumber print games left Chris Angelico <rosuav@gmail.com> - 2013-04-11 08:31 +1000
      Re: guessthenumber print games left eschneider92@comcast.net - 2013-04-10 14:01 -0700
    Re: guessthenumber print games left eschneider92@comcast.net - 2013-04-10 22:34 -0700
    Re: guessthenumber print games left eschneider92@comcast.net - 2013-04-10 22:41 -0700
      Re: guessthenumber print games left Chris Angelico <rosuav@gmail.com> - 2013-04-11 15:48 +1000
    Re: guessthenumber print games left eschneider92@comcast.net - 2013-04-10 22:56 -0700
      Re: guessthenumber print games left Chris Angelico <rosuav@gmail.com> - 2013-04-11 16:02 +1000
    Re: guessthenumber print games left eschneider92@comcast.net - 2013-04-10 23:15 -0700
      Re: guessthenumber print games left Chris Angelico <rosuav@gmail.com> - 2013-04-11 16:27 +1000
    Re: guessthenumber print games left eschneider92@comcast.net - 2013-04-11 00:15 -0700
      Re: guessthenumber print games left Chris Angelico <rosuav@gmail.com> - 2013-04-11 17:27 +1000
      Re: guessthenumber print games left Neil Cerutti <neilc@norwich.edu> - 2013-04-11 12:31 +0000

#43261 — guessthenumber print games left

Fromeschneider92@comcast.net
Date2013-04-10 02:39 -0700
Subjectguessthenumber print games left
Message-ID<0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com>
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)

[toc] | [next] | [standalone]


#43262

FromChris Angelico <rosuav@gmail.com>
Date2013-04-10 19:44 +1000
Message-ID<mailman.403.1365587062.3114.python-list@python.org>
In reply to#43261
On Wed, Apr 10, 2013 at 7:39 PM,  <eschneider92@comcast.net> wrote:
> 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

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

[toc] | [prev] | [next] | [standalone]


#43291

Fromeschneider92@comcast.net
Date2013-04-10 14:01 -0700
Message-ID<a183cc9a-9a8b-4bf1-9710-e1e5aafaafe8@googlegroups.com>
In reply to#43262
On Wednesday, April 10, 2013 5:44:20 AM UTC-4, Chris Angelico wrote:
> On Wed, Apr 10, 2013 at 7:39 PM,  <eschneider92@comcast.net> wrote:
> 
> > 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
> 
> 
> 
> 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 figure it out. If anyone could show me how to do it in program form, it would be much obliged.

[toc] | [prev] | [next] | [standalone]


#43298

FromChris Angelico <rosuav@gmail.com>
Date2013-04-11 08:31 +1000
Message-ID<mailman.427.1365633088.3114.python-list@python.org>
In reply to#43291
On Thu, Apr 11, 2013 at 7:01 AM,  <eschneider92@comcast.net> wrote:
> On Wednesday, April 10, 2013 5:44:20 AM UTC-4, Chris Angelico wrote:
>> On Wed, Apr 10, 2013 at 7:39 PM,  <eschneider92@comcast.net> wrote:
>>
>> 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?
>>
>
> 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
without actually playing them. Start with this part of your existing
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

[toc] | [prev] | [next] | [standalone]


#43292

Fromeschneider92@comcast.net
Date2013-04-10 14:01 -0700
Message-ID<mailman.424.1365627722.3114.python-list@python.org>
In reply to#43262
On Wednesday, April 10, 2013 5:44:20 AM UTC-4, Chris Angelico wrote:
> On Wed, Apr 10, 2013 at 7:39 PM,  <eschneider92@comcast.net> wrote:
> 
> > 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
> 
> 
> 
> 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 figure it out. If anyone could show me how to do it in program form, it would be much obliged.

[toc] | [prev] | [next] | [standalone]


#43317

Fromeschneider92@comcast.net
Date2013-04-10 22:34 -0700
Message-ID<dbc15ed0-e3b8-4166-b9e5-1c287e39993b@googlegroups.com>
In reply to#43261
On Wednesday, April 10, 2013 5:39:23 AM UTC-4, eschne...@comcast.net wrote:
> 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)

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

[toc] | [prev] | [next] | [standalone]


#43318

Fromeschneider92@comcast.net
Date2013-04-10 22:41 -0700
Message-ID<2177e45e-2f1d-45f0-8970-5dda0220922a@googlegroups.com>
In reply to#43261
(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)

[toc] | [prev] | [next] | [standalone]


#43319

FromChris Angelico <rosuav@gmail.com>
Date2013-04-11 15:48 +1000
Message-ID<mailman.439.1365659300.3114.python-list@python.org>
In reply to#43318
On Thu, Apr 11, 2013 at 3:41 PM,  <eschneider92@comcast.net> wrote:
> (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

[toc] | [prev] | [next] | [standalone]


#43321

Fromeschneider92@comcast.net
Date2013-04-10 22:56 -0700
Message-ID<7326d558-0aad-4059-ba85-d5bf078201e6@googlegroups.com>
In reply to#43261
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.

[toc] | [prev] | [next] | [standalone]


#43322

FromChris Angelico <rosuav@gmail.com>
Date2013-04-11 16:02 +1000
Message-ID<mailman.441.1365660139.3114.python-list@python.org>
In reply to#43321
On Thu, Apr 11, 2013 at 3:56 PM,  <eschneider92@comcast.net> wrote:
> 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

[toc] | [prev] | [next] | [standalone]


#43323

Fromeschneider92@comcast.net
Date2013-04-10 23:15 -0700
Message-ID<3ede3be7-f008-407f-8d48-d2cff2bd1c81@googlegroups.com>
In reply to#43261
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?

[toc] | [prev] | [next] | [standalone]


#43324

FromChris Angelico <rosuav@gmail.com>
Date2013-04-11 16:27 +1000
Message-ID<mailman.442.1365661639.3114.python-list@python.org>
In reply to#43323
On Thu, Apr 11, 2013 at 4:15 PM,  <eschneider92@comcast.net> wrote:
> 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?

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
into your program.

ChrisA

[toc] | [prev] | [next] | [standalone]


#43329

Fromeschneider92@comcast.net
Date2013-04-11 00:15 -0700
Message-ID<ff5fe3a8-4cf7-4c26-967a-376d7942a459@googlegroups.com>
In reply to#43261
If you get the time, please post an example, because I don't understand.

[toc] | [prev] | [next] | [standalone]


#43331

FromChris Angelico <rosuav@gmail.com>
Date2013-04-11 17:27 +1000
Message-ID<mailman.445.1365665262.3114.python-list@python.org>
In reply to#43329
On Thu, Apr 11, 2013 at 5:15 PM,  <eschneider92@comcast.net> wrote:
> 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.

That'll also help you sort out, in your own mind, what you're doing.

ChrisA

[toc] | [prev] | [next] | [standalone]


#43360

FromNeil Cerutti <neilc@norwich.edu>
Date2013-04-11 12:31 +0000
Message-ID<asnopsFfh28U3@mid.individual.net>
In reply to#43329
On 2013-04-11, eschneider92@comcast.net
<eschneider92@comcast.net> wrote:
> 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.
  
-- 
Neil Cerutti

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web