Skip to content
Sign upLog in
← Back to Community

BAGELS-Deduction!

Profile icon
PYer

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!

Voters
Profile icon
DihainP
Profile icon
WilliamTheProgrammer
Profile icon
Pythonier
Profile icon
Atari7
Profile icon
XavierDD
Profile icon
heins975
Profile icon
MohamedKulmiye
Comments
hotnewtop
Profile icon
WilliamTheProgrammer

I've heard of this game before and I'm actually making one now! Great Job, this is amazing!

Profile icon
PYer

Thank you! This is such an old project hahahaha.

@WilliamTheProgrammer

Profile icon
CyanCoding

Nice! Is this like Mastermind? Great job!

Profile icon
PYer

@microwither
: Thank you!

Profile icon
LoganWright

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

Profile icon
LoganWright

Might need a try/catch or an error exception if the number is too large.

Profile icon
PYer

@loganwright
: Thank you, but for now do not put any value higher than 10.

Profile icon
PYer

@loganwright
: I think I fixed it.

Profile icon
LoganWright

@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.

Profile icon
LoganWright

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.

Profile icon
PYer

@loganwright
: Man, you try to find everything.

Profile icon
LoganWright

@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?

Profile icon
PYer

@loganwright
: Ok. I fixed it, also you can't enter numbers like this: ten
You have to right it as 10.

Profile icon
LoganWright

@fullern000
: Right on dude! Good defensive programming. If I were a professor, I'd be super impressed!