[Tutor] guess my number game

Kerri Murphy kmurphy at easton.k12.ma.us
Tue May 8 21:30:13 EDT 2018


Hi there,

Yes, the first code does a good job by asking them to go higher or lower
after each guess, in the pop up window.

The 2nd code works, but only outputs all the higher and lower outputs after
the 10 guesses.  Everyone in the class has the same result basically.  When
I searched on various sites, they also work this way.  I can allow them to
be finished at this point, but we just wanted the game to tell the user if
he should go lower or higher after every guess.

Does this make sense?

Thank you,
Kerri

On Tue, May 8, 2018 at 6:18 PM, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:

> The first block of code is full of errors and couldn't work so I have no
> idea what you were really doing!
>
>  The second block should kind of work. From your description I'd guess you
> have an indentation error such that most of the code that should be inside
> the loop is being bypassed. Are you sure the code you sent us exactly what
> you are running?
>
> Alan g
>
> On 8 May 2018, at 10:39, Kerri Murphy <kmurphy at easton.k12.ma.us> wrote:
>
> My students are creating a guess my number game.
>
> They are trying to take this type of code (the flow of it), and turn it
> into a code using a while loop.
> Here is the first code
>
> n = int(input('Guess my number: '))if (n <= 172 and n >= 174):
>     print('Correct')elif (n >= 174):
>     a = int(input('Go Down'))
>     if (a >= 174):
>         c = int(input('Go Down'))
>         if (c >= 174):
>             g = int(input('Last Guess Go Down'))
>             if (g == 173):
>                 print('Correct')
>         elif (c <= 172):
>             i = int(input('Last Guess Go Up'))
>             if (i == 173):
>                 print('Correct')
>         else:
>             print('Correct')
>     elif (a <= 172):
>         e = int(input('Go up'))
>         if (e >= 174):
>             f = int(input('Last Guess Go Down'))
>             if (f == 173):
>                 print('Correct')
>         elif (e <= 172):
>             h = int(input('Last Guess Go Up'))
>             if (h == 173):
>                 print('Correct')
>         else:
>             print('Correct')
>     else:
>         print('Correct')elif (n <= 172):
>     b = int(input('Go Up'))
>     if (b >= 174):
>         d = int(input('Go Down'))
>         if (d >= 174):
>             j = int(input('Last Guess Go Down'))
>             if (j == 173):
>                 print('Correct')
>         elif (d <= 172):
>             m = int(input('Last Guess Go Up'))
>             if (m == 173):
>                 print('Correct')
>         else:
>             print('Correct')
>     elif (b <= 172):
>         e = int(input('Go Up'))
>         if (e >= 174):
>             k = int(input('Last Guess Go Down'))
>             if (k == 173):
>                 print('Correct')
>         elif (e <= 172):
>             l = int(input('Last Guess Go Up'))
>             if (l == 173):
>                 print('Correct')
>         else:
>             print('Correct')
>     else:
>         print('Correct')else:
>     print('Correct')
>
>
>
> Here is the code with the while loop
> import random
> n = (random.randint(0,100))
> g = int(input('Guess my number, 0 to 100, you have 10 chances'))
> c = 0
> while (c < 10):
>     g = int(input('Guess my number, 0 to 100, you have 10 chances'))
>     c = c + 1
>     if (g >= n):
>         print('Lower!')
>     elif (g <= n):
>         print('Higher!')
>     elif (g == n):
>         break
> if (g == n):
>     print('You guess my number! It took you ' + str(c) + ' tries!')
>
>
> Everyone's code just keeps asking for numbers without giving feedback,
> except for the longer code above.
>
> Can you help us consolidate the code?  We are using random.randint.
>
> Thank you!
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list