Login Register


Legends Python Challenge #2: Guessing The Number filter_list
Author
Message
RE: Python Challenge #2: Guessing The Number #6
(12-17-2015, 04:23 AM)meow Wrote:
Code:
import random def g(): r = random.randint(1,100) gc = 0 g = int(raw_input("Guess a number between 1 and 100: ")) while g != r: gc+=1 if g > r: g = int(raw_input("Try going lower, guess a number between 1 and 100: ")) if g < r: g = int(raw_input("Try going higher, guess a number between 1 and 100: ")) if g == r: gc+=1 gc = str(gc) r = str(r) print('You guessed the number '+r+' in '+gc+' guesses.') def a(): a = raw_input("Would you like to play again? [y/n] ") if a == "y": g() g() a()


The only thing your code does right there is define functions. Nothing is actually running.
Either way, when someone guesses the number, it prints
Code:
('Congratulations! You guessed the number in', x, 'guesses.')
You can fix that by converting "guesses" to a string then concatenating it normally.

Also, if someone enters N or Y whenever the script asks if they want to play again, it'll just throw them an error. That's how it behaves in command prompt at least.

Yeah It's supposed to have guess_check() and start over() at the end of the code but I must have forgotten to copy and paste to the end. I'll edit it so it runs. Thanks.

As for your other comments, it might be because you're running an earlier version of Python? It works fine for me in both command prompt and the python shell.

Reply





Messages In This Thread
Python Challenge #2: Guessing The Number - by Nil - 12-16-2015, 08:04 PM
RE: Python Challenge #2: Guessing The Number - by Nil - 12-17-2015, 08:08 AM



Users browsing this thread: 1 Guest(s)