BAGELS-Deduction!
A number guessing game. It gives you clues and you have to guess what the number is with a limited amount of digits and guesses!
https://repl.it/@PYer/bagelsDeductionpy
Please Upvote!
Nice! Is this like Mastermind? Great job!
@microwither: Thank you!
Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
*****BAGELS DEDUCTION***** (A number guessing game.)
How many digits?
18
How many guesses?
4
Traceback (most recent call last):
File "python", line 50, in <module>
File "python", line 18, in getSecretNum
IndexError: list index out of range
Might need a try/catch or an error exception if the number is too large.
@loganwright: Thank you, but for now do not put any value higher than 10.
@loganwright: I think I fixed it.
@fullern000: I still get the IndexError.
Traceback (most recent call last):
File "python", line 50, in <module>
File "python", line 18, in getSecretNum
IndexError: list index out of range
A good solution might be this: but the error also might be coming from getSecretNum
def digits():
try:
print('*****BAGELS DEDUCTION***** (A number guessing game.)')
print('How many digits?')
NUM_DIGITS = input()
NUM_DIGITS = int(NUM_DIGITS)
return NUM_DIGITS
except IndexError:
print('You have entered an error that is out of range. Please enter a smaller number.")
It also looks like it might be throwing the error in getSecretNum when it converts to int, then string, then back to int.
I also broke it by entering a negative number. It's not really necessary that you catch the error. But senior developers and employers will be really impressed by defensive programming.
@loganwright: Man, you try to find everything.
@fullern000: Not exactly. Anytime you're dealing with user input, they'll break it. I didn't break it on purpose the first time. But if I were a professor, I would be so impressed if you programmed defensively. The logic is good. Have you studied or looked into Errors and Exceptions?
@loganwright: Ok. I fixed it, also you can't enter numbers like this: ten
You have to right it as 10.
@fullern000: Right on dude! Good defensive programming. If I were a professor, I'd be super impressed!
I've heard of this game before and I'm actually making one now! Great Job, this is amazing!
Thank you! This is such an old project hahahaha. @WilliamTheProgrammer