Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Ben Finney
Ben Finney  writes:

> So, you have one name ‘guess_number’ bound to the function's parameter.
> Don't bind anything else to it!

By which I mean, don't bind that name to anything else in the function
(don't re-assign any other value to that name in the function). Keep
that name's meaning by leaving it bound to the parameter value.

-- 
 \“When I was a baby I kept a diary. Recently I was re-reading |
  `\   it, it said ‘Day 1: Still tired from the move. Day 2: Everybody |
_o__)  talks to me like I'm an idiot.’” —Steven Wright |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Ben Finney
Scott W Dunning  writes:

> On Mar 1, 2014, at 12:47 AM, Ben Finney  wrote:
>
> > You've bound the name ‘current_guess’ to the user's input, but then do
> > nothing with it for the rest of the function; it will be discarded
> > without being used.

> Hmm, I’m not quite sure I understand.  I got somewhat confused because
> the directions were changed a little and current_guess was removed
> from the get_guess function.

Removed by whom? It is still there in the example you posted, and it's
ideal for use.

> Is this more like what I should be doing?
>
> def get_guess(guess_number):
>   raw_input(“Please enter a guess”)
>   guess_number = int(guess_number)
>   return (guess_number)
> get_guess(1)

No, that's the opposite direction :-) Inside the ‘get_guess’ function
you should use as many names as you need for the different purposes.

So, you have one name ‘guess_number’ bound to the function's parameter.
Don't bind anything else to it!

Then, for the return value from ‘raw_input’, you should choose a
different suitable name and bind that name to the value (with an
assignment statement).

Then, for the computed result, you should choose yet another suitable
name, and bind *that* name to the computed value.

All these different names will make clear in the code what the meaning
of each value is.

-- 
 \  “Why should I care about posterity? What's posterity ever done |
  `\for me?” —Groucho Marx |
_o__)  |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Scott W Dunning

On Mar 1, 2014, at 6:53 AM, spir  wrote:
> 
> I find directions very confusing. Also, they completely control you while 
> explaining about nothing, like a user manual saying "press this, turn that". 
> This is inappropriate for programming (and anything else): you need to 
> understand! You need the why's and the how's, not only the what’s.
Trust me I’m confused by the directions as well.  The point of the ‘project’ is 
to learn the conditional operators (if, else, elif).
> 
> If not enough, they seem to teach you pretty weird practices: what is the 
> point of the parameter guess_number?
guess_number is the number of guesses the user has used because there are only 
10 allowed.

So;
(1) Please enter a number
(2) Please try again:
(3) “……….”
(4) “…….."

> It is not a parameter, less so of this function, but a counter proper to the 
> game control, possibly used at the end to write "You won in [counter] 
> trials." But it is not and cannot be used as a parameter to get_guess. Also, 
> what is the point of requiring you to write this game without a loop? You 
> need a loop. If they want to teach you other notions first, they must find 
> another sample program.
We haven’t learned loops yet so he wanted us to try and just use conditional 
functions and be repetitive I guess.  I’m not even worries about that part, I’m 
just trying to get through this part first because it’s confusing me.  

I can post more of the instructions if needed too.

> 
> If the rest of the book is similar, I would encourage you to change. Maybe 
> try one of those (or why not both in //):
> 
> * Alan Gauld's "Learning to Program": a very good point is this guide teaches 
> to program, in general, *using* Python, mainly:
>  http://www.alan-g.me.uk/l2p/index.htm
> 
> * Al sweigart's "invent with python": this one teaches python & programming, 
> using games as learning material:
>  http://inventwithpython.com/
Thank you for the links!!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the Number" script

2014-03-01 Thread Scott W Dunning

On Mar 1, 2014, at 8:57 AM, Mark Lawrence  wrote:

> On 01/03/2014 06:05, Scott Dunning wrote:
> 
> In addition to the answers you've already had, I suggest that you learn to 
> run code at the interactive prompt, it's a great way of seeing precisely what 
> snippets of code actually do.  Also use the print statement in Python 2 or 
> print function in Python 3, again a great way to observe what your code is 
> doing.
That makes sense, easier then running the script over and over.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Scott W Dunning

On Mar 1, 2014, at 12:47 AM, Ben Finney  wrote:

> You've bound the name ‘current_guess’ to the user's input, but then do
> nothing with it for the rest of the function; it will be discarded
> without being used.
Hmm, I’m not quite sure I understand.  I got somewhat confused because the 
directions were changed a little and current_guess was removed from the 
get_guess function.  Is this more like what I should be doing?

def get_guess(guess_number):
raw_input(“Please enter a guess”)
guess_number = int(guess_number)
return (guess_number)
get_guess(1)

> 
> Then, you use the parameter ‘guess_number’, create a new integer from
> it, and return that integer. I think you've used the wrong name for the
> ‘int()’ parameter.
Well, since there are no loops allowed I’m guessing get_guess will be called 9 
times.  I believe guess_number is the number of tries the user has used.
So;
(1) Please enter a guess: 
(2) Please enter a guess:

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Alan Gauld

On 01/03/14 17:16, Alan Gauld wrote:


Scott W Dunning  writes:


def get_guess(guess_number):
 print "(",guess_number,")""Plese enter a guess:"


Aren't you missing a comma before the last string?


I just realized it will work because Python auto joins adjacent
string literals. But in this case you should probably just
remove both quotes and make it more readable.

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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Alan Gauld


Scott W Dunning  writes:


def get_guess(guess_number):
 print "(",guess_number,")""Plese enter a guess:"


Aren't you missing a comma before the last string?

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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When to use multiprocessing Managers?

2014-03-01 Thread eryksun
On Fri, Feb 28, 2014 at 6:31 AM, James Chapman  wrote:
>
> log_Q = multiprocessing.Queue()

This is a Queue from multiprocessing.queues. It uses system resources
(e.g. a semaphore for the queue capacity) that can be shared with
processes on the same machine.

A value `put` in a queue.Queue is available immediately:

>>> import queue
>>> q1 = queue.Queue()
>>> try: q1.put('value'); q1.get_nowait()
... except queue.Empty: 'empty'
...
'value'

On the other hand, a Queue from multiprocessing.queues writes to a
pipe using a background thread, so there can be a small delay:

>>> import multiprocessing as mp
>>> q2 = mp.Queue()
>>> try: q2.put('value'); q2.get_nowait()
... except queue.Empty: 'empty'
...
'empty'
>>> q2.get_nowait()
'value'

> or whether I create it like this:
>
> multimanager = multiprocessing.Manager()
> log_Q = multimanager.Queue()

This is a queue.Queue wrapped by an AutoProxy. For example, its `get`
method calls _callmethod('get', *args, **kwds), which connects to the
manager, sends the request, and receives the result.

The docs demonstrate using a manager with remote processes:

http://docs.python.org/3/library/multiprocessing#using-a-remote-manager

You can also proxy the Queue type from multiprocessing.queues. In that
case, remote processes use a proxy, but local processes can use the
queue directly.

> Perhaps the manager would be important if I was writing to a Queue and
> expecting all threads to see that message?

Only 1 thread will `get` the message.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the Number" script

2014-03-01 Thread Mark Lawrence

On 01/03/2014 06:05, Scott Dunning wrote:

In addition to the answers you've already had, I suggest that you learn 
to run code at the interactive prompt, it's a great way of seeing 
precisely what snippets of code actually do.  Also use the print 
statement in Python 2 or print function in Python 3, again a great way 
to observe what your code is doing.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread spir

On 03/01/2014 07:46 AM, Scott W Dunning wrote:

Hello, i am working on a project for learning python and I’m stuck.  The 
directions are confusing me.  Please keep in mind I’m very ne to this.  The 
directions are long so I’ll just add the paragraphs I’m confused about and my 
code if someone could help me out I’d greatly appreciate it!  Also, we haven’t 
learned loops yet so just conditional operators and for some reason we can’t 
use global variables.


from random import randrange
randrange(1, 101)

from random import seed
seed(129)

def print_description():
 print """Welcome to Guess the Number.
 I have seleted a secret number in the range 1 ... 100.
 You must guess the number within 10 tries.
 I will tell you if you ar high or low, and
 I will tell you if you are hot or cold.\n"""

def get_guess(guess_number):
 print "(",guess_number,")""Plese enter a guess:"
 current_guess = raw_input()
 return int(guess_number)

def main():
 print_description()
 secret = 50
 current_guess = 1
 get_guess(1)
 if current_guess != secret():
 print "Congratulations you win!!"

main()


Here are the instructions I’m having a hard time with and just not sure I’m 
doing it correctly.  I’m not sure the get_guess function is correct and I’m a 
little lost with the secret and current_guess variable.

 From within the body of the main function, immediately after the call to print 
description, create variable secret and assign it a random number between 1 and 
100, generated using the randrange function. You will need to pass two argument 
to randrange, what do you think they should be? You should be able to use the 
python help system or online python documentation to make sure you understand 
the arguments to randrange.

After the end of the body of the print description function, define a new 
global function named get guess that takes a single parameter. Name the 
parameter guess number, because it will hold the index (1, 2, 3, ..., 10) of 
current guess attempt. Make the function ask the user to enter guess using the 
raw input function. The function will return the number entered by the user, 
after it has been converted to an integer.

Return to the main function after the statement that assigned a value to the 
secret variable. In a new variable named current guess store the result of 
calling the get guess function with an argument of 1. Run your program to make 
sure it works correctly.

At the end of the main function, check if the current guess matches the secret. 
If it matches, print ‘Congratulations, you win!’. If it does not, print ‘Please 
play again!’


I find directions very confusing. Also, they completely control you while 
explaining about nothing, like a user manual saying "press this, turn that". 
This is inappropriate for programming (and anything else): you need to 
understand! You need the why's and the how's, not only the what's.


If not enough, they seem to teach you pretty weird practices: what is the point 
of the parameter guess_number? It is not a parameter, less so of this function, 
but a counter proper to the game control, possibly used at the end to write "You 
won in [counter] trials." But it is not and cannot be used as a parameter to 
get_guess. Also, what is the point of requiring you to write this game without a 
loop? You need a loop. If they want to teach you other notions first, they must 
find another sample program.


If the rest of the book is similar, I would encourage you to change. Maybe try 
one of those (or why not both in //):


* Alan Gauld's "Learning to Program": a very good point is this guide teaches to 
program, in general, *using* Python, mainly:

  http://www.alan-g.me.uk/l2p/index.htm

* Al sweigart's "invent with python": this one teaches python & programming, 
using games as learning material:

  http://inventwithpython.com/

The first example in the latter book is precisely "guess my number". So, you can 
find correct code for it there.


d

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Dave Angel
 Scott W Dunning  Wrote in message:

In addition to Ben's observation,  you don't use anything random
 when initializing secret. And you don't store the result of
 get_guess. 


-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor