[Tutor] Struggling with logic .....
Barry Drake
bdrake at crosswire.org
Sat Jan 19 12:14:26 CET 2013
Hi there .... Some months ago I decided to have a crack at Python. I
set myself the task of coding the 'Mastermind' game and got into great
problems where the random generated number contained duplicated digits.
I recently decided to get back to it as I have volunteered to introduce
the older kids at the local junior school to programming i initially
using 'Scratch' and then touching on Python.
I found some Mastermind example coding on the internet and took a look.
I'm playing with the attached:
It seemed to work OK so I re-wrote the input code to be (IMO) more
logical, and added more text to make it obvious what is happening. Then
I noticed it doesn't get the scoring right when there are duplicate
digits! I'm no expert, so I wonder if you guys can explain in simple
terms what is happening. I have to say I feel a bit stupid here. Below
is one of the 'mistakes':
$ python mastermind_2.py
I have chosen a random four digit number. You have to guess what it is.
Give me your guess at the four digit number ..... Enter four digits
between 1 and 6: 1234
line is: ['1', '2', '3', '4'] Length: 4
Random Code: (3, 4, 2, 3)
Result: 0 - you have a correct number in an incorrect position
Result: 0 - you have a correct number in an incorrect position
Result: 0 - you have a correct number in an incorrect position
Result: -1 - you have an incorrect number
I have chosen a random four digit number. You have to guess what it is.
Give me your guess at the four digit number ..... Enter four digits
between 1 and 6: 4215
line is: ['4', '2', '1', '5'] Length: 4
Random Code: (3, 4, 2, 3)
Result: 0 - you have a correct number in an incorrect position
Result: 0 - you have a correct number in an incorrect position
Result: -1 - you have an incorrect number
Result: -1 - you have an incorrect number
-- Barry Drake is a member of the the Ubuntu Advertising team.
http://ubuntu.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mastermind_2.py
Type: text/x-python
Size: 2715 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130119/597e6ce7/attachment.py>
More information about the Tutor
mailing list