Share your repls and programming experiences

← Back to all posts
Cows and Bulls
TristanArmstron (8)

Cows and Bulls guessing game

(Fixed multiple issues)

Commentshotnewtop
Wai_YiYi (0)

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.

bcostello (0)

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

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!

Minxx73Minxx73 (0)

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

bcostello (0)

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

TristanArmstron (8)

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

bcostello (0)

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

TristanArmstron (8)

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

bcostello (0)

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

Sdcrouse (0)

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.

TristanArmstron (8)

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