Alan Gauld | 1 Oct 01:19 2011

Re: guess age programme (still stuck!!!!!)

On 30/09/11 21:21, Dave Angel wrote:

>> print "\n\nGood guess!!"
>> input ("\n\nPress the enter key to exit.")
>
> input() returns a character string.

Given the OP's print style I assume he is running Python v2 so input() 
will evaluate a number as an int. But given that using input()  is 
usually frowned on it would probably be better to convert the input() 
calls to raw_input() and then convert to int with int()

To the OP. You don't actually tell us what is going wrong with
your program. How is it failing? Does it just loop forever or
is it giving the wrong messages? When you say you are "still stuck" what 
exactly is happening?

--

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Steven D'Aprano | 1 Oct 04:36 2011

Re: Input

Cameron Macleod wrote:
> Hi,
> 
> When you type
> 
> Input("\n\nPress The Enter Key To Exit")
> 
> it forces you to press the enter key to close the program. Why is it the
> enter key instead of e.g. the 'esc' key?

Because the convention is that you use the Enter key to ENTER 
information. That's why it is called Enter.

Your question is kind of like asking "Why do you use a screw driver for 
driving screws, instead of a socket wrench?" <wink>

In all terminals I know of, the user's input is collected in a buffer 
until the Enter key is pressed. Until then, what the user types isn't 
available to the caller. This is how raw_input (Python 2) and input 
(Python 3) work.

If you want to read the user's input character by character, as they are 
typed, it is actually quite tricky, but it can be done. You can install 
a full-blown GUI tool kit, like wxPython or Tkinter, and use that. Or 
you can use the curses module, which is a bit lighter than Tkinter but 
still pretty heavyweight. For Linux, there's a FAQ:

http://docs.python.org/faq/library.html#how-do-i-get-a-single-keypress-at-a-time

On Windows, you can use msvcrt.getch().
(Continue reading)

Steven D'Aprano | 1 Oct 06:13 2011

Re: guess age programme (please help)

Hi Adrian,

ADRIAN KELLY wrote:
> Hi all, 
> can anyone help me with the attached programme. 

I'd love to, but I can't open it :(

If the truth be known, I could open it if I spent the time and effort. 
But that actually is significant time and effort: in my email, your 
attachment looks like this:

Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="guess age_game(broken)"

DQpwcmludCgiXHRXZWxjb21lIHRvICdHdWVzcyBNeSBOdW1iZXInISIpDQpwcmludCgiSSdtIHRo
aW5raW5nIG9mIGEgbnVtYmVyIGJldHdlZW4gMSBhbmQgMTAwLiIpDQpwcmludCgiVHJ5IHRvIGd1
ZXNzIGl0IGluIGFzIGZldyBhdHRlbXB0cyBhcyBwb3NzaWJsZS5cbiIpDQoNCiMgc2V0IHRoZSBp
bml0aWFsIHZhbHVlcw0KYWdlID0gMzUNCmd1ZXNzID0gIiAiDQp0cmllcyA9IDUNCg0KIyBndWVz
c2luZyBsb29wDQp3aGlsZSBndWVzcyAhPSBhZ2U6DQogICAgDQogICAgZ3Vlc3MgPSBpbnB1dCgi
VGFrZSBhIGd1ZXNzOiAiKQ0KICAgIGlmIGd1ZXNzID4gYWdlOg0KICAgICAgICBwcmludCAiTG93
ZXIuLi4iLHRyaWVzLCJsZWZ0Ig0KICAgIGVsc2U6DQogICAgICAgIHByaW50ICJIaWdoZXIuLi4i
LHRyaWVzLCJsZWZ0Ig0KICAgICAgICAgICAgDQogICAgdHJpZXM9dHJpZXMtMQ0KICAgDQoNCnBy
aW50ICJcblxuWW91IGd1ZXNzZWQgaXQhICBUaGUgYWdlIHdhcyIsIGFnZSwiaXQgb25seSB0b29r
IHlvdSAiK2B0cmllc2ArIiBhdHRlbXB0cyB0byBnZXQgaXQiDQoNCiAgDQppbnB1dCAoIlxuXG5Q
cmVzcyB0aGUgZW50ZXIga2V5IHRvIGV4aXQuIikNCg==

I hope you understand why I don't care enough to go to the time and 
effort of saving it to a file, decoding it, renaming it, and then 
(Continue reading)

R. Alan Monroe | 1 Oct 08:06 2011
Picon

fake defrag revisited

I'm revisiting the fake defrag program I posted about a few months
ago. The concept is basically a screensaver or light show where you
can enjoy watching entropy being reversed as colored blocks order
themselves visually.

I set it aside for a while because it was too slow, but I finally came
up with a better algorithm for the simulated file creation & deletion.
So I can throroughly scramble my imaginary files.

Now I want to come up with a simulated defragging, but I wish it for
cosmetic reasons to visit the various areas of the drive in a way that
appears random, to make it less boring.

The fake "drive" is 64 blocks (shown as 8x8 grid onscreen) for test
purposes.

The files as-is (fragged):
freelist:[1, 3, 6, 7, 9, 10, 11, 13, 14, 15, 16, 18, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33, 34, 36, 38, 39, 40, 41,
42, 43, 44, 46, 47, 49, 52, 57, 58, 59, 60, 61, 62, 63]
1000: [45, 0]
1002: [56, 19, 5, 35, 8]
1014: [21, 54, 2, 20, 53, 17, 12, 4, 37, 48]
1013: [50, 51, 55, 24, 29]

I can predict the arrangement of the files in the ideal end state
(defragged) by sorting the filenames in ascending order then assign
them blocks based on an incrementing number and the files' known
sizes:
freelist: [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
(Continue reading)

Alan Gauld | 1 Oct 10:15 2011

Re: guess age programme (please help)

On 01/10/11 05:13, Steven D'Aprano wrote:

> (2) For larger amounts, say, more than 50 lines, attach it as a file.

Or put it on one of the several public web pastebins.
That will give us all syntax colouring and no ambiguity about 
indentation levels etc that often seems to occur via email.

http://en.wikipedia.org/wiki/Comparison_of_pastebins

provides a list...

--

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Dave Angel | 1 Oct 13:48 2011

Re: fake defrag revisited

On 10/01/2011 02:06 AM, R. Alan Monroe wrote:
> I'm revisiting the fake defrag program I posted about a few months
> ago. The concept is basically a screensaver or light show where you
> can enjoy watching entropy being reversed as colored blocks order
> themselves visually.
>
> I set it aside for a while because it was too slow, but I finally came
> up with a better algorithm for the simulated file creation&  deletion.
> So I can throroughly scramble my imaginary files.
>
> Now I want to come up with a simulated defragging, but I wish it for
> cosmetic reasons to visit the various areas of the drive in a way that
> appears random, to make it less boring.
>
> The fake "drive" is 64 blocks (shown as 8x8 grid onscreen) for test
> purposes.
>
> The files as-is (fragged):
> freelist:[1, 3, 6, 7, 9, 10, 11, 13, 14, 15, 16, 18, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33, 34, 36, 38, 39, 40, 41,
42, 43, 44, 46, 47, 49, 52, 57, 58, 59, 60, 61, 62, 63]
> 1000: [45, 0]
> 1002: [56, 19, 5, 35, 8]
> 1014: [21, 54, 2, 20, 53, 17, 12, 4, 37, 48]
> 1013: [50, 51, 55, 24, 29]
>
> I can predict the arrangement of the files in the ideal end state
> (defragged) by sorting the filenames in ascending order then assign
> them blocks based on an incrementing number and the files' known
> sizes:
> freelist: [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
(Continue reading)

R. Alan Monroe | 1 Oct 17:53 2011
Picon

Re: fake defrag revisited


>> achieve the cosmetic randomness, until I realized the real problem is
>> magically determining the correct sequence in which to perform the
>> moves without ruining a future move inadverently.
>>
>> If I move 0-to-1 first, I've now ruined the future 1-to-22 which ought
>> to have taken place in advance.

> For a deterministic algorithm, simply sort that list of tuples, based on
> the second item.

Thanks, although I'm not seeing how that helps:
[(63, 63), (62, 62), (61, 61), (60, 60), (59, 59), (58, 58), (57, 57),
(52, 56), (49, 55), (47, 54), (46, 53), (44, 52), (43, 51), ( 42, 50),
(41, 49), (40, 48), (39, 47), (38, 46), (36, 45), (34, 44), (33, 43),
(32, 42), (31, 41), (30, 40), (28, 39), (27, 38), (26 , 37), (25, 36),
(23, 35), (22, 34), (18, 33), (16, 32), (15, 31), (14, 30), (13, 29),
(11, 28), (10, 27), (9, 26), (7, 25), (6, 24) , (3, 23), (1, 22), (48,
21), (37, 20), (4, 19), (12, 18), (17, 17), (53, 16), (20, 15), (2,
14), (54, 13), (21, 12), (29, 11), (24, 10), (55, 9), (51, 8), (50,
7), (8, 6), (35, 5), (5, 4), (19, 3), (56, 2), (0, 1), (45, 0)]
This still suffers the same ruin-a-downstream-move problem when you
see 35-to-5 ruining the future move 5-to-4.

Alan

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
(Continue reading)

Dave Angel | 1 Oct 20:03 2011

Re: fake defrag revisited

On 10/01/2011 11:53 AM, R. Alan Monroe wrote:
>>> achieve the cosmetic randomness, until I realized the real problem is
>>> magically determining the correct sequence in which to perform the
>>> moves without ruining a future move inadverently.
>>>
>>> If I move 0-to-1 first, I've now ruined the future 1-to-22 which ought
>>> to have taken place in advance.
>> For a deterministic algorithm, simply sort that list of tuples, based on
>> the second item.
> Thanks, although I'm not seeing how that helps:
> [(63, 63), (62, 62), (61, 61), (60, 60), (59, 59), (58, 58), (57, 57),
> (52, 56), (49, 55), (47, 54), (46, 53), (44, 52), (43, 51), ( 42, 50),
> (41, 49), (40, 48), (39, 47), (38, 46), (36, 45), (34, 44), (33, 43),
> (32, 42), (31, 41), (30, 40), (28, 39), (27, 38), (26 , 37), (25, 36),
> (23, 35), (22, 34), (18, 33), (16, 32), (15, 31), (14, 30), (13, 29),
> (11, 28), (10, 27), (9, 26), (7, 25), (6, 24) , (3, 23), (1, 22), (48,
> 21), (37, 20), (4, 19), (12, 18), (17, 17), (53, 16), (20, 15), (2,
> 14), (54, 13), (21, 12), (29, 11), (24, 10), (55, 9), (51, 8), (50,
> 7), (8, 6), (35, 5), (5, 4), (19, 3), (56, 2), (0, 1), (45, 0)]
> This still suffers the same ruin-a-downstream-move problem when you
> see 35-to-5 ruining the future move 5-to-4.
>
> Alan
You missed the rest of the paragraph.  Don't wait for the sort to 
finish, you do the swapping in the compare function.

+++
For a deterministic algorithm, simply sort that list of tuples, based on 
the second item.  The sort will swap two tuples each time, and they will 
gradually become more ordered.  Whether this will appear visually random 
(Continue reading)

Ed Hughes | 1 Oct 20:52 2011
Picon

Re: Input

Have a look at the Windows/Unix/Linux solution posted in the ActiveState Python Recipes, (a fantastic resource),  here - a bit long winded maybe but it works fine under Linux and Windows for me. It's pretty much based on the standard docs solution as already mentioned for Linux/Unix. It use the tty and termios modules in Unix/Linux and the msvcrt module in Windows, again, as already mentioned. 


BgEddy

On 1 October 2011 11:00, <tutor-request <at> python.org> wrote:
Send Tutor mailing list submissions to
       tutor <at> python.org

To subscribe or unsubscribe via the World Wide Web, visit
       http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
       tutor-request <at> python.org

You can reach the person managing the list at
       tutor-owner <at> python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

  1. Re: Input (Steven D'Aprano)
  2. Re: guess age programme (please help) (Steven D'Aprano)
  3. fake defrag revisited (R. Alan Monroe)
  4. Re: guess age programme (please help) (Alan Gauld)


----------------------------------------------------------------------

Message: 1
Date: Sat, 01 Oct 2011 12:36:57 +1000
From: Steven D'Aprano <steve <at> pearwood.info>
To: tutor <at> python.org
Subject: Re: [Tutor] Input
Message-ID: <4E867CC9.3050500 <at> pearwood.info>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Cameron Macleod wrote:
> Hi,
>
> When you type
>
> Input("\n\nPress The Enter Key To Exit")
>
> it forces you to press the enter key to close the program. Why is it the
> enter key instead of e.g. the 'esc' key?

Because the convention is that you use the Enter key to ENTER
information. That's why it is called Enter.

Your question is kind of like asking "Why do you use a screw driver for
driving screws, instead of a socket wrench?" <wink>

In all terminals I know of, the user's input is collected in a buffer
until the Enter key is pressed. Until then, what the user types isn't
available to the caller. This is how raw_input (Python 2) and input
(Python 3) work.

If you want to read the user's input character by character, as they are
typed, it is actually quite tricky, but it can be done. You can install
a full-blown GUI tool kit, like wxPython or Tkinter, and use that. Or
you can use the curses module, which is a bit lighter than Tkinter but
still pretty heavyweight. For Linux, there's a FAQ:

http://docs.python.org/faq/library.html#how-do-i-get-a-single-keypress-at-a-time

On Windows, you can use msvcrt.getch().


--
Steven


------------------------------

Message: 2
Date: Sat, 01 Oct 2011 14:13:43 +1000
From: Steven D'Aprano <steve <at> pearwood.info>
To: tutor <at> python.org
Subject: Re: [Tutor] guess age programme (please help)
Message-ID: <4E869377.5030503 <at> pearwood.info>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Adrian,

ADRIAN KELLY wrote:
> Hi all,
> can anyone help me with the attached programme.

I'd love to, but I can't open it :(

If the truth be known, I could open it if I spent the time and effort.
But that actually is significant time and effort: in my email, your
attachment looks like this:

Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="guess age_game(broken)"

DQpwcmludCgiXHRXZWxjb21lIHRvICdHdWVzcyBNeSBOdW1iZXInISIpDQpwcmludCgiSSdtIHRo
aW5raW5nIG9mIGEgbnVtYmVyIGJldHdlZW4gMSBhbmQgMTAwLiIpDQpwcmludCgiVHJ5IHRvIGd1
ZXNzIGl0IGluIGFzIGZldyBhdHRlbXB0cyBhcyBwb3NzaWJsZS5cbiIpDQoNCiMgc2V0IHRoZSBp
bml0aWFsIHZhbHVlcw0KYWdlID0gMzUNCmd1ZXNzID0gIiAiDQp0cmllcyA9IDUNCg0KIyBndWVz
c2luZyBsb29wDQp3aGlsZSBndWVzcyAhPSBhZ2U6DQogICAgDQogICAgZ3Vlc3MgPSBpbnB1dCgi
VGFrZSBhIGd1ZXNzOiAiKQ0KICAgIGlmIGd1ZXNzID4gYWdlOg0KICAgICAgICBwcmludCAiTG93
ZXIuLi4iLHRyaWVzLCJsZWZ0Ig0KICAgIGVsc2U6DQogICAgICAgIHByaW50ICJIaWdoZXIuLi4i
LHRyaWVzLCJsZWZ0Ig0KICAgICAgICAgICAgDQogICAgdHJpZXM9dHJpZXMtMQ0KICAgDQoNCnBy
aW50ICJcblxuWW91IGd1ZXNzZWQgaXQhICBUaGUgYWdlIHdhcyIsIGFnZSwiaXQgb25seSB0b29r
IHlvdSAiK2B0cmllc2ArIiBhdHRlbXB0cyB0byBnZXQgaXQiDQoNCiAgDQppbnB1dCAoIlxuXG5Q
cmVzcyB0aGUgZW50ZXIga2V5IHRvIGV4aXQuIikNCg==


I hope you understand why I don't care enough to go to the time and
effort of saving it to a file, decoding it, renaming it, and then
finally reading it.

You can make it easier for your readers (and therefore increase the
number of people able and willing to help) if you do this:

(1) For small amounts of code, just copy and paste it into your email.
Make sure you send ordinary plain text. No HTML email or "rich text", as
that will often break the formatting of the code.

(2) For larger amounts, say, more than 50 lines, attach it as a file.
Make sure the file has a file extension .txt or .py even if you are
using a computer system that doesn't need file extensions. If .py,
please make sure the file name is legal for Python: no spaces or
brackets or parentheses or dashes.


Thanks in advance,



--
Steven


------------------------------

Message: 3
Date: Sat, 1 Oct 2011 02:06:36 -0400
From: "R. Alan Monroe" <amonroe <at> columbus.rr.com>
To: tutor <at> python.org
Subject: [Tutor] fake defrag revisited
Message-ID: <145120072334.20111001020636 <at> columbus.rr.com>
Content-Type: text/plain; charset=us-ascii

I'm revisiting the fake defrag program I posted about a few months
ago. The concept is basically a screensaver or light show where you
can enjoy watching entropy being reversed as colored blocks order
themselves visually.

I set it aside for a while because it was too slow, but I finally came
up with a better algorithm for the simulated file creation & deletion.
So I can throroughly scramble my imaginary files.

Now I want to come up with a simulated defragging, but I wish it for
cosmetic reasons to visit the various areas of the drive in a way that
appears random, to make it less boring.

The fake "drive" is 64 blocks (shown as 8x8 grid onscreen) for test
purposes.

The files as-is (fragged):
freelist:[1, 3, 6, 7, 9, 10, 11, 13, 14, 15, 16, 18, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33, 34, 36, 38, 39, 40, 41, 42, 43, 44, 46, 47, 49, 52, 57, 58, 59, 60, 61, 62, 63]
1000: [45, 0]
1002: [56, 19, 5, 35, 8]
1014: [21, 54, 2, 20, 53, 17, 12, 4, 37, 48]
1013: [50, 51, 55, 24, 29]

I can predict the arrangement of the files in the ideal end state
(defragged) by sorting the filenames in ascending order then assign
them blocks based on an incrementing number and the files' known
sizes:
freelist: [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
1000: [0, 1]
1002: [2, 3, 4, 5, 6]
1013: [7, 8, 9, 10, 11]
1014: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21]


Which gives this list of before and after blocks: i.e. block 0 is
destined to live at 1 after defrag, block 1 is destined to live at 22,
etc.

[(0, 1), (1, 22), (2, 14), (3, 23), (4, 19), (5, 4), (6, 24), (7, 25),
(8, 6), (9, 26), (10, 27), (11, 28), (12, 18), (13, 29), (14, 30),
(15, 31), (16, 32), (17, 17), (18, 33), (19, 3), (20, 15), (21, 12),
(22, 34), (23, 35), (24, 10), (25, 36), (26, 37), (27, 38 ), (28, 39),
(29, 11), (30, 40), (31, 41), (32, 42), (33, 43), (34, 44), (35, 5),
(36, 45), (37, 20), (38, 46), (39, 47), (40, 48), (41, 49), (42, 50),
(43, 51), (44, 52), (45, 0), (46, 53), (47, 54), (48, 21), (49, 55),
(50, 7), (51, 8), (52, 56), (53, 16), (54, 13), (55, 9), (56, 2), (57,
57), (58, 58), (59, 59), (60, 60), (61, 61), (62, 62), (63, 63)]

I initially thought I could just do a random.shuffle on this list to
achieve the cosmetic randomness, until I realized the real problem is
magically determining the correct sequence in which to perform the
moves without ruining a future move inadverently.

If I move 0-to-1 first, I've now ruined the future 1-to-22 which ought
to have taken place in advance.

Is there a deterministic-yet-seemingly-random algorithm out there
whose name I wasn't aware of to be able to google it?

Alan



------------------------------

Message: 4
Date: Sat, 01 Oct 2011 09:15:15 +0100
From: Alan Gauld <alan.gauld <at> btinternet.com>
To: tutor <at> python.org
Subject: Re: [Tutor] guess age programme (please help)
Message-ID: <j66i6k$ge1$1 <at> dough.gmane.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 01/10/11 05:13, Steven D'Aprano wrote:

> (2) For larger amounts, say, more than 50 lines, attach it as a file.

Or put it on one of the several public web pastebins.
That will give us all syntax colouring and no ambiguity about
indentation levels etc that often seems to occur via email.

http://en.wikipedia.org/wiki/Comparison_of_pastebins

provides a list...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



------------------------------

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


End of Tutor Digest, Vol 92, Issue 2
************************************

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Walter Prins | 1 Oct 23:11 2011
Picon

Re: guess age programme (please help)

Hi,

On 1 October 2011 05:13, Steven D'Aprano <steve <at> pearwood.info> wrote:
Hi all, can anyone help me with the attached programme.

ADRIAN KELLY wrote:
I'd love to, but I can't open it :(

If the truth be known, I could open it if I spent the time and effort. But that actually is significant time and effort: in my email, your attachment looks like this:

Strange, does your mail program not allow you to just save the attachment as an untyped file without extension?  I had no problem saving the attachement and renaming it to have a .py extension (use GMail). 

Walter
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Gmane