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

2014-03-02 Thread Dave Angel
 Scott W Dunning  Wrote in message:
> 
> 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)

That block of code is a huge step backwards from what you already
 had. So let's go back a step. 

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

First thing to do is decide what that function is 'supposed' to
 do. What do you suppose a caller might expect as a return value?
 Once you've decided a description,  write it down as a set of
 comments (or docstring,  but that's another lesson).

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

It will be called (up to) 9 times even after you learn about
 loops.  It's called get_guess, not get_guesses. 

>  I believe guess_number is the number of tries the user has used.
> So;
> (1) Please enter a guess: 
> (2) Please enter a guess:

If that's a specification, then add it to your comments above.  I
 would guess you're missing a print in the function.
 



-- 
DaveA

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


[Tutor] (no subject)

2014-03-02 Thread Emeraude kwilu
Read in a list of English words. Randomly select a long word and show it to the 
contestant. Challenge
the contestant to find shorter words using letters from the long word. They 
should type each one
and press Enter. After 30seconds,the game stops accepting entries. It evaluates 
the user’s submissions
and finds which ones were valid words. It prints the final tally, and shows the 
words the user guessed
correctly, and the invalid words the user submitted. Finally it shows all the 
valid words that
could be made. selectWord = [ "abjuring",] #this is the random word 
selectedvalidWordList = ['bar','bug'...] # this is all the words using letters 
from the long wordrandWord = random.choice(selectWord) time.time () = nowcount 
= 0while time() <= now +30:  print raw_input("enter a word in abjuring:")   
   count += 1#? I am stuck there my loop is not working and I don't know how to 
print the user word etherI have to print the number of the valid word the enter 
and print it also if they print invalid word I have to print it as wellat the 
end I prunt all the valid word. I know I have to use if and else statement but 
I'm not able to do so :( example:you enter 2 valid ['bar','jar']you enter 2 
invalid [' jirg', 'rig']the full list is: ['bar','bug',...] 
   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2014-03-02 Thread Alan Gauld

On 02/03/14 18:14, Emeraude kwilu wrote:


selectWord = [ "abjuring",] #this is the random word selected
validWordList = ['bar','bug'...]


Obviously this is not your real code since this is not
valid syntax. And since its clearly homework it will help
us if you post your actual code that is failing plus
any error messages(in  their entirety)



randWord = random.choice(selectWord)

time.time () = now
count = 0
while time() <= now +30:
   print raw_input("enter a word in abjuring:")


You need to store the word that the user entered. Here you
just print it then throw it away. You will need another
variable, and probably a list as well, to hold the
previous words entered.


   count += 1



I am stuck there my loop is not working


Define 'not working'
What is happening?
What did you expect to happen?

Being precise in your descriptions is very important.
Often describing the problem in detail is enough for you
to find the answer to it yourself!


and I don't know how to print the user word ether


You seem to be printing the word the user entered OK,
That is all you are doing with it in fact.
What you are not doing is comparing it to the valid
words list. That's where your if/else code should
come in.


I have to print the number of the valid word the enter and print it also
if they print invalid word I have to print it as well

at the end I prunt all the valid word. I know I have to use if and else
statement but I'm not able to do so :(


Show us your actual code plus any error messages.

It won't do any harm to tell us the python version too, it's obviously 
Python 2.X but what is X? 2.5, 2.6 or 2.7?


--
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] (no subject)

2014-03-02 Thread R. Alan Monroe

> I am stuck there my loop is not working
> ...
>  I know I have to use if and
> else statement but I'm not able to do so :(

Hint:
Set the assignment aside and write a couple smaller practice programs.
Like a very simple one that just asks for a word and prints that word.
Or a simple one that checks if 2 is greater than 1.
In other words, some baby steps before you tackle the real assignment.

Alan

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


[Tutor] What is the unladen airspeed velocity of a swallow in flight?

2014-03-02 Thread Mark Lawrence

On 02/03/2014 18:14, Emeraude kwilu wrote:

[snipped as it's been answered]

Or to put it another way, please use a sensible subject line, there may 
be some intelligent people on this list, but we're not mind readers :)


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


[Tutor] Equality Check.

2014-03-02 Thread Tyler Simko
Hi all! 

I'm embarrassingly new at Python, so please forgive my probably simple 
mistakes. 

So I called readlines() on a file, and I'm wondering how I can check the 
equality of a specific line with a raw_input set variable as a condition. For 
example,

file = open('filename.txt,' 'r')
file.readlines()
variable_name = raw_input()
if file[2] == variable_name:
 #whatever 

This approach hasn't worked so far, does anyone have any tips? Thanks so much!!

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


Re: [Tutor] Equality Check.

2014-03-02 Thread Mark Lawrence

On 02/03/2014 21:10, Tyler Simko wrote:

Hi all!

I'm embarrassingly new at Python, so please forgive my probably simple mistakes.

So I called readlines() on a file, and I'm wondering how I can check the 
equality of a specific line with a raw_input set variable as a condition. For 
example,

file = open('filename.txt,' 'r')
file.readlines()
variable_name = raw_input()
if file[2] == variable_name:
  #whatever

This approach hasn't worked so far, does anyone have any tips? Thanks so much!!

-Tyler


You haven't stripped the newline before doing the comparison.  You also 
don't have to read the whole file just to compare a specific line.  I'll 
leave you to find out how :)


--
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] Equality Check.

2014-03-02 Thread Joel Goldstick
On Mar 2, 2014 6:30 PM, "Mark Lawrence"  wrote:
>
> On 02/03/2014 21:10, Tyler Simko wrote:
>>
>> Hi all!
>>
>> I'm embarrassingly new at Python, so please forgive my probably simple
mistakes.
>>
>> So I called readlines() on a file, and I'm wondering how I can check the
equality of a specific line with a raw_input set variable as a condition.
For example,
>>readlines result must be put somewhere
>> file = open('filename.txt,' 'r')
>> file.readlines()
>> variable_name = raw_input()
>> if file[2] == variable_name:
>>   #whatever
>>
>> This approach hasn't worked so far, does anyone have any tips? Thanks so
much!!
>>
>> -Tyler
>
>
> You haven't stripped the newline before doing the comparison.  You also
don't have to read the whole file just to compare a specific line.  I'll
leave you to find out how :)
>
> --
> 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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Equality Check.

2014-03-02 Thread Danny Yoo
The call to readlines () has a return value that is currently being dropped
to the floor.  Look at its value.

Feel free to ask more questions.  Good luck!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Equality Check.

2014-03-02 Thread Alan Gauld

On 02/03/14 21:10, Tyler Simko wrote:


So I called readlines() on a file, and I'm wondering how

> I can check the equality of a specific line with a raw_input


file = open('filename.txt,' 'r')
file.readlines()


This opens the file and reads all the lines but it
doesn't store the result anywhere so you just throw
those lines away.

The recommended way to do this in Python nowadays is:

with open('filename.txt') as infile:
   for line in infile:
  # process line here


variable_name = raw_input()
if file[2] == variable_name:


file is a file object you cannot index into it using [2].

But even if you had used readlines and stored the result
checking line by line as shown above is probably a
better approach.


HTH
--
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] Equality Check.

2014-03-02 Thread Mark Lawrence

On 02/03/2014 23:38, Danny Yoo wrote:

The call to readlines () has a return value that is currently being
dropped to the floor.  Look at its value.

Feel free to ask more questions.  Good luck!



He'll need it after reading my response, I must stop replying when I'm 
knackered and not thinking straight :(


--
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] Equality Check.

2014-03-02 Thread Ben Finney
Tyler Simko  writes:

> I'm embarrassingly new at Python, so please forgive my probably simple
> mistakes.

Welcome, and congratulations on starting with Python!

No forgiveness needed for asking questions or making mistakes; the
important thing is to learn from both.

> So I called readlines() on a file, and I'm wondering how I can check
> the equality of a specific line with a raw_input set variable as a
> condition.

You don't need to use ‘file.readlines’ for this purpose; that method
consumes the entire file, which you don't need. You only need the
specific line. You could iterate over the file, discarding lines, until
you get to the one line you need, and bind a name to just that line.

> For example,
>
> file = open('filename.txt,' 'r')

Best not to clobber the built-in name “file”. Choose a more descriptive
name for the *purpose* of this value; e.g. “input_file”.

> file.readlines()

This consumes the entire file, and returns a new sequence containing
each line as an item of the sequence. You then throw this new object
away, because you haven't bound anything to it.

> variable_name = raw_input()
> if file[2] == variable_name:
>  #whatever 

Again, “variable_name” is utterly opaque as to the purpose. Choose names
that clearly indicate what the value *means* in the program.

> This approach hasn't worked so far, does anyone have any tips?

You're attempting to access an item of the file. But files don't have
items that can be indexed that way.

Files are, on the other hand, iterable. You get each line of a file by
iterating over the file object. (The ‘file.readlines’ method is specific
to file objects, and does the entire iteration behind the scenes. That
might be what is confusing you.)

This is the difference between iterables (objects which you can loop
over to get an object each iteration), versus sequences (objects with a
sequence of items all present and addressible by index).

All sequences are iterable, but not all iterables are sequences. A
Python file object is an iterable, but is not a sequence.

-- 
 \ “I wish there was a knob on the TV to turn up the intelligence. |
  `\  There's a knob called ‘brightness’ but it doesn't work.” |
_o__) —Eugene P. Gallagher |
Ben Finney

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