1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Oct 2013
Posts
3
Rep Power
0

#### Numbers Game!!

I was wondering if anyone could give me some help with this problem?! Its been killing me!!!

The Numbers Game is played as follows:
1. Person A selects three numbers, for example, (1 2 3).
2. The goal of the game is for Person B to guess the numbers Person A has selected in the correct order.
3. For example, if Person B guesses (7 3 1), then Person A answers (2 0).
a. The 2 means Person B correctly guessed two numbers (digits) selected by Person A. The 0 means no digit was in its correct position.
4. If Person B guesses (1 4 3), then Person A answers (2, 2).
a. The first 2 means Person B correctly guessed two numbers selected by Person A. The second 2 means both of the numbers were in their correct positions.
5. If Person B guesses (6 0 8), then Person A answers (0, 0).
6. If Person B guesses (3 1 2), then Person A answers (3, 0).
7. If Person B guesses (1 3 2), then Person A answers (3, 1).
8. If Person B guesses (1 2 3), then Person A answers, Bravo!!!! (1 2 3) you got it!!!

Required:
Write a program called NumbersGame.py that simulates this game with the Computer playing the role of Person A and you playing the role of Person B. Please note that the user guess is read as a single string containing three digits. For example, the string (1 2 3) or (4 7 0). In Python, a random number may be generated by importing the random module and using either the randint or randrange function. For example, x = random.randrange(min, max). The program should be played using the digits 0 to 9, and should display the following message at the start of the game:

Welcome to the Numbers Game
===========================
I have three digits.
Try to guess the digits in the order in which I listed them
For example, if you entered (1 2 3) and my answer was (1 2 3),
Then, bravo! You would be correct!
However, if you entered (1 2 4), my response would be (2, 2).
The first 2 means you have two of my three numbers.
The second 2 means you have both numbers in their correct positions.
So if you had enter (3 4 1) my answer would be (2, 0) and
If you had entered (5 7 0) my answer would be (0, 0).

The program should use the following functions:
1. def printOpeningMessage()  prints the opening message.
2. def getThreeDigits()  inputs and return three distinct digits.
3. def getUserGuess()  inputs the user guess, extract and return the three digits from the guess.
4. def printOpeningMessage()  prints the opening message.
5. def getCounts(secret1, secret2, secret3, guess1, guess2, guess3)  returns the number of correct digits and the number of digits in correct positions.
6. def printWinningMessage()  prints the winning message.

The program should implement the following main-program algorithm:
1. Print the opening message
2. Input the three distinct integers
3. Set the counters for number of correct digits and number of digits in correct position to zero.
4. Repeat the following steps as long as the guess is incorrect
A. Get guess from user (extract and return 3 digits)
B. Get count of number of correct digits and number of digits in correct positions.
C. If the guess is incorrect then: format and print the clue, and reset the number of correct digits and number of digits in correct position to zero.
5. Print the winning message.
2. We certainly can help you, yes, but you will have to show us what you've done so far with it yourself. We will not and should not simply hand you a solution just for the asking, and even if that isn't what you intended, we would still need to know what specifics you want help with. Show us the code, and we'll happily oblige you.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Oct 2013
Posts
3
Rep Power
0
Originally Posted by Schol-R-LEA
We certainly can help you, yes, but you will have to show us what you've done so far with it yourself. We will not and should not simply hand you a solution just for the asking, and even if that isn't what you intended, we would still need to know what specifics you want help with. Show us the code, and we'll happily oblige you.
I would love to show you what I have....if I had anything to show. I don't even know where to begin.
4. Well, the good news is, you have most of the program design given to you in the assignment. Start with simply writing a function to print the introductory banner, and proceed from there.

Actually, this part is sufficiently trivial that I am willing to do it for you, if only because it gives me a chance to show you something you might find useful: multi-line strings. If you define a string with three quotes (either double or single quotes) on each end, you can span several lines of text in a single string. This is useful for both docstrings and long banner strings like the one the instructor gave you:

Code:
```def printOpeningMessage():
"""  printOpeningMessage() -
Print a banner explaining the game."""

banner = '''Welcome to the Numbers Game
===========================
I have three digits.
Try to guess the digits in the order in which I listed them
For example, if you entered (1 2 3) and my answer was (1 2 3),
Then, bravo! You would be correct!
However, if you entered (1 2 4), my response would be (2, 2).
The first 2 means you have two of my three numbers.
The second 2 means you have both numbers in their correct positions.
So if you had enter (3 4 1) my answer would be (2, 0) and
If you had entered (5 7 0) my answer would be (0, 0).'''
print (banner)```
The string at the beginning, with three double quotes and not being assigned anywhere is a docstring, a type of comment that the pydoc tool can automatically generate documentation from. Including a docstring at the beginning of a function is always a Good Idea, even if it is nothing more than a recapitulation of the function's signature.

Now, take a shot at the getThreeDigits() function. Let us know what you come up with for that, and if you have any problems with it.

BTW, what editor/IDE are you using? You might find it worth your while to pick up either Dr Python or Eric for your development work, as they are both quite easy to use and provide interactive windows for when you want to test a snippet of code. Eric is the more powerful of the two, but Dr Python is better suited to novices.

It would also help if you could tell us which version of Python you are writing for, as Python 2.x and Python 3.x are substantially different.
Last edited by Schol-R-LEA; October 21st, 2013 at 12:45 AM.
5. I don't even know where to begin.
To learn Python begin with tutorial:
http://docs.python.org/3/tutorial/

To learn basics of programming and logic (it looks you really need it since you "do not know how to start") try few simpler tasks for beginners:

If you step-by-step progress to the Code Guesser task you will certainly know how to write your assignment.

Sorry for people here are so evil that they do not want to write the whole thing instead of you, but they naively believe that _your_ assignment is supposed to teach _you_ something. And if you are engaged with this assignment then you supposedly really want to learn yourself.
6. #### Confusion and a little more assitance.

The instructions are confusing. Clearly the task is to implement the scorer of Mastermind using 3 digits. The computer is supposed to take the role of scorer. Then the computer should choose the goal. Why then the algorithmic instruction
"2. Input the three distinct integers"?

Also I'm not sure why instruction 3 has any merit whatsoever:
"3. Set the counters for number of correct digits and number of digits in correct position to zero."

Counting the total number of correct digits while disregarding position is a mathematical set operation. Sets are a native python data type.
Code:
```A = set([39, 52, 21, 'hut', 'hut', 'HIKE!']).intersection(set(['hut', 52, 'flag on play']))
print(A)        # shows the set resulting from intersection.
print(len(A))   # You run the program to see the output.

# non-essential notes
# I chose list instead of tuples to differentiate the bracketing characters
# I'll never understand why Guido chose the method name "intersection" rather than "intersect"
# "intersect" is the verb.```
Last edited by b49P23TIvg; October 21st, 2013 at 07:49 AM. Reason: nasty thought removed.
7. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Oct 2013
Posts
3
Rep Power
0
Originally Posted by Schol-R-LEA
Now, take a shot at the getThreeDigits() function. Let us know what you come up with for that, and if you have any problems with it.

BTW, what editor/IDE are you using? You might find it worth your while to pick up either for your development work, as they are both quite easy to use and provide interactive windows for when you want to test a snippet of code. Eric is the more powerful of the two, but Dr Python is better suited to novices.

It would also help if you could tell us which version of Python you are writing for, as Python 2.x and Python 3.x are substantially different.
1) Here is what i got for the getThreeDigits function:

def getThreeDigits():
import random
num1 = random.randint(0, 20)
num2 = random.randint(0, 20)
num3 = random.randint(0,20)

2) Im using the IDLE provided from the python.org website.

3)Python 3.x

Thank you for your help! :
8. #### Strange choice

Originally Posted by instructions
The program should be played using the digits 0 to 9,
Although the instructions mix the terms "digits" with "numbers", I'm convinced it means "digits". Hence, I find the choice
random.randint(0, 20)
remarkably strange. Having played Mastermind, and coded Mastermind as the puzzle giver and puzzle solver, my informed opinion is that the game is not more fun, nor is the logic different using more colors. Ten digits provide more than enough choice.