On 9 May 2018 2:30 am, Kerri Murphy <kmur...@easton.k12.ma.us> wrote:
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. My point is that the code you posted can't even run, let alone do a good job. The indentation is all messed up and will yield errors. The 2nd code works, but only outputs all the higher and lower outputs after the 10 guesses. How are you running the code? Are you using the interactive prompt to type it in? Are you running it in an ide like idle? If you put it in a file and run it from the OS command line the second version should more or less work. 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? Yes and your code should do that if you put it in a file. If you try typing it at the python prompt you may well get the result you describe. Alan g. On Tue, May 8, 2018 at 6:18 PM, Alan Gauld <[1]alan.ga...@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 <[2]kmur...@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 - [3]Tutor@python.org To unsubscribe or change subscription options: [4]https://mail.python.org/mailman/listinfo/tutor References Visible links 1. mailto:alan.ga...@yahoo.co.uk 2. mailto:kmur...@easton.k12.ma.us 3. mailto:Tutor@python.org 4. https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor