Skip to content
Sign upLog in
← Back to Community

Cows and Bulls

Profile icon
TristanArmstron

Cows and Bulls guessing game

(Fixed multiple issues)

Voters
Profile icon
Totallynotnic
Profile icon
Equation
Profile icon
Sdcrouse
Profile icon
Joseph_Parsons
Profile icon
Nanowrimoijk
Profile icon
21natzil
Profile icon
Jaythrex
Profile icon
mkhoi
Profile icon
Minxx73Minxx73
Profile icon
TristanArmstron
Comments
hotnewtop
Profile icon
Wai_YiYi

Enter a whole number between 1 and 9: 7
Enter a whole number between 1 and 9: 4
Enter a whole number between 1 and 9: 9
Enter a whole number between 1 and 9: 5
One of the numbers is not a whole number between 1 and 9. Please try again
Your guess: [7, 4, 9, 5]

The error message is displayed no matter what.

Profile icon
bcostello

I see why it's possible to get repeated numbers.

Cannot infer image mime type

The code ensures that Rand1 is not equal to 2,3 or 4. But the next while loop allows Rand2 to be changed and doesn't check it against Rand 1.
I had a student re-work the game. Here is the link.
https://repl.it/@RonanJones/Bulls-and-Cows-Guessing-Game

Very fun for him. Thanks!

Profile icon
Minxx73Minxx73

@bcostello
I see, tell your student good job from me.

Profile icon
bcostello

It doesn't appear that this game works. Just FYI.

Profile icon
TristanArmstron

@bcostello
What doesn't work on it? I have a feeling I made it a little confusing with the instructions.

Profile icon
bcostello

@TristanArmstron
Sorry, my comment was vague and not helpful! Technically it does work, but let's say the number is 5512. If we enter 5500, we get 2 cows and 2 bulls. I see why, but 2 cows and 0 bulls seems to make more sense.

Profile icon
TristanArmstron

@bcostello
I see, I did specify that there will be no repeated numbers so that normally wouldn't be a problem. I couldn't figure out how to do it otherwise with the time frame I had. I also just realized that I do specify that I need a number between 1 and 10 in which you should never enter a 0, but that means they could also enter the number 10, which isn't what I meant by that. It should be fixed now.

Profile icon
bcostello

@TristanArmstron
We did have an answer with a repeated number. Is that what you fixed?

Profile icon
TristanArmstron

@bcostello
It should be yes

Profile icon
Sdcrouse

This is good, but the "Restart" bar blocks the line that tells me how many guesses it took me to get the right number, at least in my Chrome browser.

Profile icon
TristanArmstron

@Sdcrouse
Thanks for reporting it. I fixed it by making it print another "enter" after.

Profile icon
Sdcrouse

@TristanArmstron
Excellent! That works.