Re: [Tutor] HELP PLEASE

2019-08-13 Thread Alan Gauld via Tutor
On 13/08/2019 12:09, Sithembewena L. Dube wrote:
> Hi Marissa,
> 
> I really think that you could consider doing an introductory Python
> tutorial and then venture back into solving this problem.

>>> This is the output of my updated code:
>>> Traceback (most recent call last):
>>>  File "/Applications/Python 3.7/exercises .py", line 37, in 
>>>main()

Based on the file name I suspect she is already doing some kind of
tutorial. However, you are right about needing to review some of the
basic concepts.

As a plug I'll just mention my own tutorial linked in my .sig below :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
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 PLEASE

2019-08-13 Thread Sithembewena L. Dube
Hi Marissa,

I really think that you could consider doing an introductory Python
tutorial and then venture back into solving this problem.

Understanding concepts like data types, function syntax and loops makes all
the difference in approaching programming challenges.

Here is a decent and free online Python tutorial to get you going:
https://www.learnpython.org/


Kind regards,
Sithembewena Dube


*Sent with Shift
*

On Tue, Aug 13, 2019 at 12:47 PM Cameron Simpson  wrote:

> On 12Aug2019 15:11, Marissa Russo  wrote:
> >This is my code:
>
> Thank you.
>
> >This is the output of my updated code:
> >Traceback (most recent call last):
> >  File "/Applications/Python 3.7/exercises .py", line 37, in 
> >main()
> >  File "/Applications/Python 3.7/exercises .py", line 33, in main
> >m = mean(data[0])
> >  File "/Applications/Python 3.7/exercises .py", line 29, in mean
> >return(sum(nums)/len(nums))
> >TypeError: unsupported operand type(s) for +: 'int' and 'str'
>
> Thank you for this as well, it makes things much clearer.
>
> So, to your code:
>
> >import math
>
> Just a remark: you're not using anything from this module. I presume you
> intend to later.
>
> >def get_numbers():
> >print("This program will compute the mean and standard deviation")
> >file1 = input("Please enter the first filename: ")
> >file2 = input("Please enter the second filename: ")
> >x = open(file1, "r")
> >y = open(file2, "r")
> >nums = x.readlines()
> >nums2 = y.readlines()
>
> As has been mentioned in another reply, readlines() returns a list of
> strings, one for each line of text in the file.
>
> In order to treat these as numbers you need to convert them.
>
> >return nums, nums2
> >
> >def to_ints(strings):
> >num_copy = []
> >for num in nums:
> >num_copy.append(float(num))
> >return num_copy
>
> This returns a list of floats. You might want to rename this function to
> "to_floats". Just for clarity.
>
> >return to_ints(nums), to_ints(nums2)
>
> This isn't reached. I _think_ you need to put this line at the bottom of
> the get_numbers function in order to return two lists of numbers. But it
> is down here, not up there.
>
> >def mean(nums):
> >_sum = 0
> >return(sum(nums)/len(nums))
>
> This is the line raising your exception. The reference to "+" is because
> sum() does addition. It starts with 0 and adds the values you give it,
> but you're handing it "nums".
>
> Presently "nums" is a list of strings, thus the addition of the initial
> 0 to a str in the exception message.
>
> If you move your misplaced "return to_ints(nums), to_ints(nums2)"
> statement up into the get_numbers function you should be better off,
> because then it will return a list of numbers, not strings.
>
> Cheers,
> Cameron Simpson 
> ___
> 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] HELP PLEASE

2019-08-13 Thread Cameron Simpson

On 12Aug2019 15:11, Marissa Russo  wrote:

This is my code:


Thank you.


This is the output of my updated code:
Traceback (most recent call last):
 File "/Applications/Python 3.7/exercises .py", line 37, in 
   main()
 File "/Applications/Python 3.7/exercises .py", line 33, in main
   m = mean(data[0])
 File "/Applications/Python 3.7/exercises .py", line 29, in mean
   return(sum(nums)/len(nums))
TypeError: unsupported operand type(s) for +: 'int' and 'str'


Thank you for this as well, it makes things much clearer.

So, to your code:


import math


Just a remark: you're not using anything from this module. I presume you 
intend to later.



def get_numbers():
   print("This program will compute the mean and standard deviation")
   file1 = input("Please enter the first filename: ")
   file2 = input("Please enter the second filename: ")
   x = open(file1, "r")
   y = open(file2, "r")
   nums = x.readlines()
   nums2 = y.readlines()


As has been mentioned in another reply, readlines() returns a list of 
strings, one for each line of text in the file.


In order to treat these as numbers you need to convert them.


   return nums, nums2

def to_ints(strings):
   num_copy = []
   for num in nums:
   num_copy.append(float(num))
   return num_copy


This returns a list of floats. You might want to rename this function to 
"to_floats". Just for clarity.



   return to_ints(nums), to_ints(nums2)


This isn't reached. I _think_ you need to put this line at the bottom of 
the get_numbers function in order to return two lists of numbers. But it 
is down here, not up there.



def mean(nums):
   _sum = 0
   return(sum(nums)/len(nums))


This is the line raising your exception. The reference to "+" is because 
sum() does addition. It starts with 0 and adds the values you give it, 
but you're handing it "nums".


Presently "nums" is a list of strings, thus the addition of the initial 
0 to a str in the exception message.


If you move your misplaced "return to_ints(nums), to_ints(nums2)" 
statement up into the get_numbers function you should be better off, 
because then it will return a list of numbers, not strings.


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


Re: [Tutor] HELP PLEASE

2019-08-13 Thread David L Neil

On 13/08/19 7:11 AM, Marissa Russo wrote:

This is my code:

import math

def get_numbers():
 print("This program will compute the mean and standard deviation")
 file1 = input("Please enter the first filename: ")
 file2 = input("Please enter the second filename: ")
 x = open(file1, "r")
 y = open(file2, "r")
 nums = x.readlines()
 nums2 = y.readlines()

 return nums, nums2



Do you understand the concept of a "loop" - Code which is repeated as 
many times as necessary?


How many files must be opened, read, and then averaged?



def to_ints(strings):
 num_copy = []
 for num in nums:
 num_copy.append(float(num))
 return num_copy

 return to_ints(nums), to_ints(nums2)


What is the purpose of this line, given that the previous line has 
returned to the calling code?


Have I missed something? When is to_ints() used?



def mean(nums):
 _sum = 0
 return(sum(nums)/len(nums))

def main():
 data = get_numbers()
 m = mean(data[0])


Do you know what data[ 0 ] (or [ 1 ]) contains?
Might this knowledge be helpful?



 m2 = mean(data[1])
 print("The mean of the first file is: ", m)
 print("The mean of the second file is: ", m2)
main()


This is the output of my updated code:

Traceback (most recent call last):
   File "/Applications/Python 3.7/exercises .py", line 37, in 
 main()
   File "/Applications/Python 3.7/exercises .py", line 33, in main
 m = mean(data[0])
   File "/Applications/Python 3.7/exercises .py", line 29, in mean
 return(sum(nums)/len(nums))
TypeError: unsupported operand type(s) for +: 'int' and 'str'


What do you think "TypeError" means? Do you know the difference between 
an "int" and a "str[ing]"?


Given that both sum() and len() return numbers, what do you think is the 
"str"? Might this refer back to the earlier suggestion that you need to 
'see' the data being read?


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


Re: [Tutor] HELP PLEASE

2019-08-12 Thread Marissa Russo
This is my code:

import math

def get_numbers():
print("This program will compute the mean and standard deviation")
file1 = input("Please enter the first filename: ")
file2 = input("Please enter the second filename: ")
x = open(file1, "r")
y = open(file2, "r")
nums = x.readlines()
nums2 = y.readlines()

return nums, nums2

def to_ints(strings):
num_copy = []
for num in nums:
num_copy.append(float(num))
return num_copy

return to_ints(nums), to_ints(nums2)

def mean(nums):
_sum = 0
return(sum(nums)/len(nums))

def main():
data = get_numbers()
m = mean(data[0])
m2 = mean(data[1])
print("The mean of the first file is: ", m)
print("The mean of the second file is: ", m2)
main()


This is the output of my updated code:

Traceback (most recent call last):
  File "/Applications/Python 3.7/exercises .py", line 37, in 
main()
  File "/Applications/Python 3.7/exercises .py", line 33, in main
m = mean(data[0])
  File "/Applications/Python 3.7/exercises .py", line 29, in mean
return(sum(nums)/len(nums))
TypeError: unsupported operand type(s) for +: 'int' and 'str'
> On Aug 12, 2019, at 12:54 PM, Marissa Russo  wrote:
> 
> Hello,
> 
> I am trying to figure out what is going on and why my output is saying 
> “” instead of giving me a number. Please let me know if 
> you see the error in my code!!
> 
> import math
> 
> def get_numbers():
>print("This program will compute the mean and standard deviation")
>file1 = input("Please enter the first filename: ")
>file2 = input("Please enter the second filename: ")
>x = open(file1, "r")
>y = open(file2, "r")
>nums = x.readlines()
>nums2 = y.readlines()
> 
>return nums, nums2
> 
> def mean(nums):
>for num in nums:
>_sum += num
>return _sum / len(nums)
> 
> def mean2(nums2):
>for num in nums2:
>_sum += nums2
>return _sum / len(nums2)
> 
> def main():
>data = get_numbers()
> 
>print("The mean of the first file is: ", mean)
>print("The mean of the second file is: ", mean2)
> main()
> 

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


Re: [Tutor] HELP PLEASE

2019-08-12 Thread Mats Wichmann
On 8/12/19 10:54 AM, Marissa Russo wrote:
> Hello,
> 
> I am trying to figure out what is going on and why my output is saying 
> “” instead of giving me a number. Please let me know if 
> you see the error in my code!!

to quickly illustrate the specific question you asked - you got comments
on other stuff already:


>>> def foo():
... return "string from foo()"
...
>>> print(foo)

>>> print(foo())
string from foo()
>>>


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


Re: [Tutor] HELP PLEASE

2019-08-12 Thread Alan Gauld via Tutor
On 12/08/2019 17:54, Marissa Russo wrote:

> def mean(nums):
> for num in nums:
> _sum += num
> return _sum / len(nums)
> 
> def mean2(nums2):
> for num in nums2:
> _sum += nums2
> return _sum / len(nums2)
> 
> def main():
> data = get_numbers()
> 
> print("The mean of the first file is: ", mean)
> print("The mean of the second file is: ", mean2)

Notice that in the print statement you use the names
of the functions.
Python therefore evaluates those names and discovers
that they are functions, so that's what it tells you.

To get the values you need to call the functions,
which you do by adding parens to the name:

 print("The mean of the first file is: ", mean(data[0]) )
 print("The mean of the second file is: ", mean2(data[1]) )

That will then execute the functions

Which leads us to the next problem.
In both functions you have a line like:

_sum += num

But that expands to

_sum = _sum + num

Which means you are trying to get a value from _sum
before assigning any value. You need to initialize
_sum before using it like that.

_sum = 0

But better still would be to use the builtin sum method:

sum(nums)

So your mean function turns into:

def mean(nums):
   return( sum(nums)/len(nums))

But that leads to the next problem which is that your data
is still in string format, which is what you read from the
file with getlines().
You can convert it to integers using a list comprehension
inside your get_numbers function:

nums = [int(s) for s in nums]

which assumes the file is a list of numbers each on one line?

If you are not familiar with the list comprehension shortcut
you can do it longhand like this:

num_copy = []
for num in nums:
num_copy.append(int(num))
nums = num_copy

Incidentally, the two mean functions look identical
to me. What do you think is different other than
the names?

Finally, you could just use the mean() function defined in
the statistics library of the standard library.

import statistics as stats
...
 print("The mean of the first file is: ", stats.mean(data[0]) )
 ...

That should be enough to be getting on with.

Once you get those things done you could post again and
we might suggest some ways to tidy the code up a little.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
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 PLEASE

2019-08-12 Thread Sithembewena L. Dube
In your calls to the `*print*` function, you  are not calling the `*mean*`
and `*mean2*` functions that you declared to calculate averages. So Python
sees you trying to concatenate two function objects to strings and is not
happy. That's one thing.

Secondly, your code could be refactored to define one `*mean*` function as
your functions do virtually the same thing. Then, you could just call it as
needed.

Thirdly, you could use the `*with*` keyword. See "7.2. Reading and Writing
Files" at https://docs.python.org/3/tutorial/inputoutput.html


Kind regards,
Sithembewena Dube


*Sent with Shift
*

On Mon, Aug 12, 2019 at 7:24 PM Marissa Russo 
wrote:

> Hello,
>
> I am trying to figure out what is going on and why my output is saying
> “” instead of giving me a number. Please let me know
> if you see the error in my code!!
>
> import math
>
> def get_numbers():
> print("This program will compute the mean and standard deviation")
> file1 = input("Please enter the first filename: ")
> file2 = input("Please enter the second filename: ")
> x = open(file1, "r")
> y = open(file2, "r")
> nums = x.readlines()
> nums2 = y.readlines()
>
> return nums, nums2
>
> def mean(nums):
> for num in nums:
> _sum += num
> return _sum / len(nums)
>
> def mean2(nums2):
> for num in nums2:
> _sum += nums2
> return _sum / len(nums2)
>
> def main():
> data = get_numbers()
>
> print("The mean of the first file is: ", mean)
> print("The mean of the second file is: ", mean2)
> main()
>
> ___
> 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] HELP PLEASE

2019-08-12 Thread Joel Goldstick
On Mon, Aug 12, 2019 at 1:22 PM Marissa Russo  wrote:
>
> Hello,
>
> I am trying to figure out what is going on and why my output is saying 
> “” instead of giving me a number. Please let me know if 
> you see the error in my code!!
>

Marissa, you have lots of problems here.  First, you should copy and
paste the complete traceback instead of the snippet you showed.
> import math
>
> def get_numbers():
> print("This program will compute the mean and standard deviation")
> file1 = input("Please enter the first filename: ")
> file2 = input("Please enter the second filename: ")
> x = open(file1, "r")
> y = open(file2, "r")
> nums = x.readlines()
> nums2 = y.readlines()
>
> return nums, nums2
>

Above. You are returning a string of all the data in your files.. is
that what you want?

> def mean(nums):
> for num in nums:
> _sum += num
> return _sum / len(nums)
>
Your traceback probably is complaining about _sum +=.  You can't add
to a variable that doesn't exists.  Maybe try _sum = 0 above your for
loop


> def mean2(nums2):
> for num in nums2:
> _sum += nums2
> return _sum / len(nums2)
>
> def main():
> data = get_numbers()

Ok, so you call a function which will return a tuple with two values
into data.  But you don't do anything with data

You might put this here:

m = mean(data[0])
m2 = mean2(data[1])

then print m and m2
>
> print("The mean of the first file is: ", mean)
> print("The mean of the second file is: ", mean2)
> main()
>

So, first, show the complete error message here.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] HELP PLEASE

2019-08-12 Thread Marissa Russo
Hello,

I am trying to figure out what is going on and why my output is saying 
“” instead of giving me a number. Please let me know if 
you see the error in my code!!

import math

def get_numbers():
print("This program will compute the mean and standard deviation")
file1 = input("Please enter the first filename: ")
file2 = input("Please enter the second filename: ")
x = open(file1, "r")
y = open(file2, "r")
nums = x.readlines()
nums2 = y.readlines()

return nums, nums2

def mean(nums):
for num in nums:
_sum += num
return _sum / len(nums)

def mean2(nums2):
for num in nums2:
_sum += nums2
return _sum / len(nums2)

def main():
data = get_numbers()

print("The mean of the first file is: ", mean)
print("The mean of the second file is: ", mean2)
main()

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


Re: [Tutor] Help Please

2019-02-21 Thread DL Neil

Mario,

On 21/02/19 3:30 AM, Mario Ontiveros wrote:

Hello,
 I am new to python and have been stuck on this for a while. What I am 
trying to do is to remove rows with void, disconnected, and error on lines. The 
code I have does that, the only problem is that it removes my header because 
void is in header. I need to keep header.
with open("PSS.csv","r+") as f:
 new_f = f.readlines()
 f.seek(0)
 for line in new_f:
 if "Void" not in line:
 if "Disconnected" not in line:
 if "Error" not in line:
  f.write(line)
 f.truncate()



Would it be 'safer' to create a separate output file?

Rather than reading the entire file (easily managed if short, but 
unwieldy and RAM-hungry if thousands of records!), consider that a file 
object is an iterable and process it one line/record at a time.


with open( ... ) as f:
header = f.readline()
# deal with the header record
for record in f:
function_keep_or_discard( record )
#etc


In case it helps you to follow the above, and possibly to learn other 
applications of this thinking, herewith:-


An iterable matches a for-each-loop very neatly (by design). It consists 
of two aspects: next() ie give me the next value (thus for each value in 
turn), and the StopIteration exception (when next() asks for another 
value after they have all been processed). The for 'swallows' the 
exception because it is expected. Hence, you don't need to try...except!


Something a lot of pythonistas don't stop to consider, is that once code 
starts iterating an object, the iteration does not 'reset' until 
"exhausted" (unlike your use of f.seek(0) against the output file). 
Accordingly, we can use a 'bare' next() to pick-out the first (header) 
record and then pass the rest of the job (all the other next()s) to a 
for-each-loop:


with open( ... ) as f:
header = next( f )  # grab the first record
# deal with the header record
for record in f:# iterate through the remaining records
#etc

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


Re: [Tutor] Help Please

2019-02-20 Thread Alex Kleider

On 2019-02-20 06:30, Mario Ontiveros wrote:

Hello,
I am new to python and have been stuck on this for a while. What I
am trying to do is to remove rows with void, disconnected, and error
on lines. The code I have does that, the only problem is that it
removes my header because void is in header. I need to keep header.

Any help will be greatly appreciated.

with open("PSS.csv","r+") as f:
new_f = f.readlines()
f.seek(0)
for line in new_f:
if "Void" not in line:
if "Disconnected" not in line:
if "Error" not in line:
 f.write(line)
f.truncate()



Mario Ontiveros


Since your file seems to be a csv file, can we assume your 'header' line 
is really a comma separated list of column names?


If so, then using the csv module and specifically csv.DictReader (+/- 
DictWriter) might make things easier for you.

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


Re: [Tutor] Help Please

2019-02-20 Thread Alan Gauld via Tutor
On 20/02/2019 14:30, Mario Ontiveros wrote:
> Hello,
> I am new to python and have been stuck on this for a while. What I am 
> trying to do is to remove rows with void, disconnected, and error on lines. 
> The code I have does that, the only problem is that it removes my header 
> because void is in header. I need to keep header.
> 
> Any help will be greatly appreciated.
> 
> with open("PSS.csv","r+") as f:
> new_f = f.readlines()
> f.seek(0)
> for line in new_f:

I don't know how long your header is but assuming it is
only 1 line you can simply use slicing to remove the first
line:

  for line in new_f[1:]:

If the header is multi line simply change to the first line you need to
process, for example to remove 3 lines use new_f[3:]

> if "Void" not in line:
> if "Disconnected" not in line:
> if "Error" not in line:
>f.write(line)

This only writes the line if all three terms are present. Assuming thats
what you want it might be more obviously written as

if ("Void" in line and
   "Disconnected in line and
   "Error" in line):
  f.write(line)

You could also use a regex to search for all three and if its
a long file that will probably be faster since it only traverses
the list once. The snag is the regex gets complex if you need
all three in any order. But if you know the order in which
the terms arise it's probably the best option.

> f.truncate()

While overwriting the original file works, it's slightly dangerous
in that you lose the original data if anything goes wrong.
The more usual way to do things is to create a new file for writing
then rename it to the original if, and only if, everything works.
You might even rename the original to .bak first to be really safe.

The other advantage of this approach is that you don't need the
readlines)() call but can just process the file line by line
directly which should also be faster.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
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 Please

2019-02-20 Thread Mark Lawrence

On 20/02/2019 14:30, Mario Ontiveros wrote:

Hello,
 I am new to python and have been stuck on this for a while. What I am 
trying to do is to remove rows with void, disconnected, and error on lines. The 
code I have does that, the only problem is that it removes my header because 
void is in header. I need to keep header.

Any help will be greatly appreciated.

with open("PSS.csv","r+") as f:
 new_f = f.readlines()
 f.seek(0)
 for line in new_f:
 if "Void" not in line:
 if "Disconnected" not in line:
 if "Error" not in line:
  f.write(line)
 f.truncate()



Mario Ontiveros



Something like (completely from memory so untested) :-

with open("PSS.csv","r") as inf:
   lines = inf.readlines()

with open("PSS.csv","w") as outf:
   fiter = iter(lines)
   line = next(fiter)
   outf.write(line)
   for line in fiter:
  if "Void" not in line and "Disconnected" not in line and "Error" 
not in line: # probably a simpler way of writing this but I'm knackered :-)

   outf.write(line)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


[Tutor] Help Please

2019-02-20 Thread Mario Ontiveros
Hello,
I am new to python and have been stuck on this for a while. What I am 
trying to do is to remove rows with void, disconnected, and error on lines. The 
code I have does that, the only problem is that it removes my header because 
void is in header. I need to keep header.

Any help will be greatly appreciated.

with open("PSS.csv","r+") as f:
new_f = f.readlines()
f.seek(0)
for line in new_f:
if "Void" not in line:
if "Disconnected" not in line:
if "Error" not in line:
 f.write(line)
f.truncate()



Mario Ontiveros


---
Confidentiality Warning: This message and any attachments are intended only for 
the 
use of the intended recipient(s), are confidential, and may be privileged. If 
you are 
not the intended recipient, you are hereby notified that any review, 
retransmission, 
conversion to hard copy, copying, circulation or other use of all or any 
portion of 
this message and any attachments is strictly prohibited. If you are not the 
intended 
recipient, please notify the sender immediately by return e-mail, and delete 
this 
message and any attachments from your system.
---
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help please

2018-10-12 Thread Alan Gauld via Tutor
On 12/10/18 04:31, Adam Eyring wrote:

> Also, it looks better to use " + " instead of a comma:
> print("Combining these foods will you," + new_food)

It may "look better" but be aware that they don't do
the same thing and the plus sign is a lot less efficient
computationally since it creates a new string for
each addition.

For a simple case like this it won't matter but if
you had a lot of short strings being added together
in a loop it could slow things down quite a bit.

The other problem with the plus sign is that it
requires all arguments to be strings whereas the
comma separated list gets automatically converted
to a string by Python (by calling str(x) ) so is
in general more reliable.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
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 please

2018-10-12 Thread Mark Lawrence

On 12/10/18 04:31, Adam Eyring wrote:

The program works as is in Python3. For Python2, change input to raw_input
and see if that makes it work (I know it worked for me when I had Python2).
Also, it looks better to use " + " instead of a comma:
print("Combining these foods will you," + new_food)

Also, colons and spaces are good practices when using input boxes, such as
food_1=raw_input("Sushi: ")



Please don't top post as it makes reading long threads really irritating.

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

Mark Lawrence

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


Re: [Tutor] Help please

2018-10-12 Thread Adam Eyring
The program works as is in Python3. For Python2, change input to raw_input
and see if that makes it work (I know it worked for me when I had Python2).
Also, it looks better to use " + " instead of a comma:
print("Combining these foods will you," + new_food)

Also, colons and spaces are good practices when using input boxes, such as
food_1=raw_input("Sushi: ")


On Thu, Oct 11, 2018 at 1:23 PM Carlton Banks  wrote:

> https://www.w3schools.com/python/ref_func_input.asp
>
> tor. 11. okt. 2018 18.51 skrev Carlton Banks :
>
> > What are you trying to do?
> >
> > tor. 11. okt. 2018 18.33 skrev Holly Jo :
> >
> >>
> >> I have no clue what I’m doing wrong, I’m a new student
> >>
> >> food_1=input("Sushi")
> >> food_2=input("Quesdilla")
> >> new_food=food_1+food_2
> >> print("Combining these foods will you,",new_food)
> >> input("Press enter to continue")
> >>
> >>
> >> Sent from Mail for Windows 10
> >>
> >> ___
> >> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help please

2018-10-11 Thread Carlton Banks
https://www.w3schools.com/python/ref_func_input.asp

tor. 11. okt. 2018 18.51 skrev Carlton Banks :

> What are you trying to do?
>
> tor. 11. okt. 2018 18.33 skrev Holly Jo :
>
>>
>> I have no clue what I’m doing wrong, I’m a new student
>>
>> food_1=input("Sushi")
>> food_2=input("Quesdilla")
>> new_food=food_1+food_2
>> print("Combining these foods will you,",new_food)
>> input("Press enter to continue")
>>
>>
>> Sent from Mail for Windows 10
>>
>> ___
>> 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] Help please

2018-10-11 Thread Carlton Banks
What are you trying to do?

tor. 11. okt. 2018 18.33 skrev Holly Jo :

>
> I have no clue what I’m doing wrong, I’m a new student
>
> food_1=input("Sushi")
> food_2=input("Quesdilla")
> new_food=food_1+food_2
> print("Combining these foods will you,",new_food)
> input("Press enter to continue")
>
>
> Sent from Mail for Windows 10
>
> ___
> 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] Help please

2018-10-11 Thread Alan Gauld via Tutor
On 11/10/18 04:19, Holly Jo wrote:
> 
> I have no clue what I’m doing wrong, I’m a new student 
> 
> food_1=input("Sushi")
> food_2=input("Quesdilla")
> new_food=food_1+food_2
> print("Combining these foods will you,",new_food)
> input("Press enter to continue")


Please always tell us what has gone wrong. What you
expected and what you got. If there is an error message
send the full error text.

It also helps if you tell us which Python version
and OS you are using.

Based on the above I'm guessing you may be running
this Python v3 code using Python v2. One of the changes
between 3 and 2 is how input() works.

If that's not the case then you need to provide
more details, as requested above.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Help please

2018-10-11 Thread Holly Jo

I have no clue what I’m doing wrong, I’m a new student 

food_1=input("Sushi")
food_2=input("Quesdilla")
new_food=food_1+food_2
print("Combining these foods will you,",new_food)
input("Press enter to continue")


Sent from Mail for Windows 10

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


Re: [Tutor] help please

2018-10-10 Thread Mirage Web Studio
You are using the same variable name twice.
You may use "rivers" for the dict and "river" for values.
Also use descriptive names for variables. For eg if you correct the above
mistake, the next one will be this line

for rivers in rivers.values():
print (rivers)


and sorry for top positing.


On Wed 10 Oct, 2018, 12:38 Michael Schmitt, 
wrote:

> To whom it may concern:
>
>
> I am trying to teach myself Python and ran into a problem. This is my code
>
>
> # name of rivers and country
>
> rivers = {'nile' : 'egypt', 'ohio' : 'US', 'rhine' : 'germany' }
>
> # prints river name
> for rivers in rivers.keys():
> print (rivers)
>
> #prints country
> for rivers in rivers.values():
> print (rivers)
>
> # prints statement " The (river) is in the country of (country)
> for rivers in rivers:
> print ("The " + rivers.keys() + "is in the country of " +
> rivers.vaules())
>
> I am getting the following error
>  for rivers in rivers.values():
> AttributeError: 'str' object has no attribute 'values'
>
> Thanks for the help.
>
> Sincerely,
>
> Michael S. Schmitt
>
>
> [
> https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif
> ]<
> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail_term=icon>
>   Virus-free. www.avast.com<
> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail_term=link
> >
> ___
> 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] help please

2018-10-10 Thread Deepak Dixit
On Wed, Oct 10, 2018, 12:37 PM Michael Schmitt 
wrote:

> To whom it may concern:
>
>
> I am trying to teach myself Python and ran into a problem. This is my code
>
>
> # name of rivers and country
>
> rivers = {'nile' : 'egypt', 'ohio' : 'US', 'rhine' : 'germany' }
>
> # prints river name
> for rivers in rivers.keys():
> print (rivers)
>
> #prints country
> for rivers in rivers.values():
> print (rivers)
>
> # prints statement " The (river) is in the country of (country)
>

  Why are you using "for rivers in rivers".
  Replace this for loop with :-

  for river in rivers:
 print ("The " + river + "is in the country of " + rivers.get(river))

for rivers in rivers:
> print ("The " + rivers.keys() + "is in the country of " +
> rivers.vaules())
>
> I am getting the following error
>  for rivers in rivers.values():
> AttributeError: 'str' object has no attribute 'values'
>
> Thanks for the help.
>
> Sincerely,
>
> Michael S. Schmitt
>
>
> [
> https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif
> ]<
> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail_term=icon>
>   Virus-free. www.avast.com<
> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail_term=link
> >
> ___
> 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] help please

2018-10-10 Thread Abdur-Rahmaan Janhangeer
i think it should have been

for river in rivers instead of
for rivers in rivers

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ
Mauritius
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help please

2018-10-10 Thread Peter Otten
Michael Schmitt wrote:

> To whom it may concern:
> 
> 
> I am trying to teach myself Python and ran into a problem. This is my code

> I am getting the following error
>  for rivers in rivers.values():
> AttributeError: 'str' object has no attribute 'values'

> # prints river name
> for rivers in rivers.keys():
> print (rivers)

Look closely at the loop above. What is the value of the "rivers" variable 
after the first iteration?

To resolve the problem simply use a different name as the loop variable.

Pro tip: When you loop over a dict you get the keys by default. So:

for river in rivers:
print(river)

> # prints statement " The (river) is in the country of (country)
> for rivers in rivers:
> print ("The " + rivers.keys() + "is in the country of " + 
rivers.vaules())
> 

Here's a logic (and a spelling) error: rivers.keys() comprises all rivers 
and rivers.values() all countries in the dict. You want to loop over 
rivers.items() which gives you (river, country) pairs.

Tip: print() automatically inserts spaces between its arguments. So:

for river, country in rivers.items():
print("River", river, "is in", country)

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


[Tutor] help please

2018-10-10 Thread Michael Schmitt
To whom it may concern:


I am trying to teach myself Python and ran into a problem. This is my code


# name of rivers and country

rivers = {'nile' : 'egypt', 'ohio' : 'US', 'rhine' : 'germany' }

# prints river name
for rivers in rivers.keys():
print (rivers)

#prints country
for rivers in rivers.values():
print (rivers)

# prints statement " The (river) is in the country of (country)
for rivers in rivers:
print ("The " + rivers.keys() + "is in the country of " + rivers.vaules())

I am getting the following error
 for rivers in rivers.values():
AttributeError: 'str' object has no attribute 'values'

Thanks for the help.

Sincerely,

Michael S. Schmitt


[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
Virus-free. 
www.avast.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Please on python

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 02:12, Laura Garcia wrote:
> I need to create a python code that  should simulate throwing darts by
> random landing between (a random x and a random y)0 and 1.  and the program
> should print out number of darts that land within a rectangle.

Look in the random module. There are a bunch of different
random number generating functions in thee, just choose
the one that looks best suited to your task.

For the rest its just a case of some basic math. Write
some code and if you get stuck come back with a specific
question and we can try to answer it.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Help Please on python

2017-02-07 Thread Laura Garcia
I need to create a python code that  should simulate throwing darts by
random landing between (a random x and a random y)0 and 1.  and the program
should print out number of darts that land within a rectangle.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help please

2016-10-20 Thread Alan Gauld via Tutor
On 20/10/16 21:25, Karen Palladino wrote:

> I am new to python and programming for that matter. Basically, I don't know
> much at all. I have python on my p/c which was put there by a former
> co-worker who wrote a program that extracts bites of information to generate
> a report. The format of the text file used to extract the information has
> changed and therefore, the information is not be extracted and distributed
> properly. 
> 
>  
> 
> We are looking for someone to help fine tune the program, can anyone help
> us?

This list can help you learn how to modify the program yourself,
but it is not a job board. So if you are trying to find a
programmer who can modify the program for you, you need to
look somewhere else. (There are several; sites that specialize
in Python jobs)

If you do want to learn how to program in Python then there are
many tutorials available for complete beginners (including mine,
see below)

There is a list here:

https://wiki.python.org/moin/BeginnersGuide/NonProgrammers

If you go down that route feel free to post any questions
you may have here and we will try to answer them.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Help please

2016-10-20 Thread Karen Palladino
HI,

 

I am new to python and programming for that matter. Basically, I don't know
much at all. I have python on my p/c which was put there by a former
co-worker who wrote a program that extracts bites of information to generate
a report. The format of the text file used to extract the information has
changed and therefore, the information is not be extracted and distributed
properly. 

 

We are looking for someone to help fine tune the program, can anyone help
us?

 

Thank you,

 

Karen Palladino

The Windham Group, Inc.

363 West 22 Street

New York, NY   10011

212-624-1132

 

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


[Tutor] Help please

2013-10-17 Thread Pinedo, Ruben A
I was given this code and I need to modify it so that it will:

#1. Error handling for the files to ensure reading only .txt file
#2. Print a range of top words... ex: print top 10-20 words
#3. Print only the words with  3 characters
#4. Modify the printing function to print top 1 or 2 or 3 
#5. How many unique words are there in the book of length 1, 2, 3 etc

I am fairly new to python and am completely lost, i looked in my book as to how 
to do number one but i cannot figure out what to modify and/or delete to add 
the print selection. This is the code:


import string

def process_file(filename):
hist = dict()
fp = open(filename)
for line in fp:
process_line(line, hist)
return hist

def process_line(line, hist):
line = line.replace('-', ' ')

for word in line.split():
word = word.strip(string.punctuation + string.whitespace)
word = word.lower()

hist[word] = hist.get(word, 0) + 1

def common_words(hist):
t = []
for key, value in hist.items():
t.append((value, key))

t.sort(reverse=True)
return t

def most_common_words(hist, num=100):
t = common_words(hist)
print 'The most common words are:'
for freq, word in t[:num]:
print freq, '\t', word

hist = process_file('emma.txt')
print 'Total num of Words:', sum(hist.values())
print 'Total num of Unique Words:', len(hist)
most_common_words(hist, 50)

Any help would be greatly appreciated because i am struggling in this class. 
Thank you in advance

Respectfully,

Ruben Pinedo
Computer Information Systems
College of Business Administration
University of Texas at El Paso
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help please

2013-10-17 Thread Todd Matsumoto

Hello Ruben,

You might already know this, but the Python documentation will get you 
pretty far: http://www.python.org/doc/


Here are some things to lookup that may help you solve the problems.

On 10/16/2013 08:49 PM, Pinedo, Ruben A wrote:

I was given this code and I need to modify it so that it will:

#1. Error handling for the files to ensure reading only .txt file

Look up exceptions.
Find out what the string method endswith() does.

#2. Print a range of top words... ex: print top 10-20 words
#3. Print only the words with  3 characters

Look up how the built-in len() works.

#4. Modify the printing function to print top 1 or 2 or 3 
#5. How many unique words are there in the book of length 1, 2, 3 etc
Read up on different datatypes and choose the one, or combination types 
that would solve this for you.


T

P.S. Tutors I hope this is posted to the list and the top. I always get 
that wrong!

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


Re: [Tutor] Help please

2013-10-17 Thread Alan Gauld

On 16/10/13 19:49, Pinedo, Ruben A wrote:

I was given this code and I need to modify it so that it will:

#1. Error handling for the files to ensure reading only .txt file


I'm not sure what is meant here since your code only ever opens 
'emma.txt', so it is presumably a text file... Or are you

supposed to make the filename a user provided value maybe
(using raw_input maybe?)


#2. Print a range of top words... ex: print top 10-20 words


I assume 'top' here means the most common? Whoever is writing the 
specification for this problem needs to be a bit more specific

in their definitions.

If so you need to fix the bugs in process_line() and
process_file(). I don;t know if these are deliberate bugs
or somebody is just sloppy. But neither work as expected
right now. (Hint: Consider the return values of each)

Once you've done that you can figure out how to extract
the required number of words from your (unsorted) dictionary.
and put that in a reporting function and print the output.
You might be able to use the two common words functions,
although watch out because they don't do exactly what
you want and one of them is basically broken...


#3. Print only the words with  3 characters


Modify the above to discard words of 3 letters or less.


#4. Modify the printing function to print top 1 or 2 or 3 


I assume this means take a parameter that speciffies the
number of words to print. Or it could be the length of
word to ignore. Again the specification is woolly
In either case its a small modification to your
reporting function.


#5. How many unique words are there in the book of length 1, 2, 3 etc


This is slicing the data slightly differently but
again not that different to the earlier requirement.


I am fairly new to python and am completely lost, i looked in my book as
to how to do number one but i cannot figure out what to modify and/or
delete to add the print selection. This is the code:


You need to modify the two brokemn functions and add a
new reporting function. (Despite the reference to a
printing function I'd suggest keeping the data extraction
and printing seperate.


import string

def process_file(filename):
 hist = dict()
 fp = open(filename)
 for line in fp:
 process_line(line, hist)
 return hist

def process_line(line, hist):
 line = line.replace('-', ' ')
 for word in line.split():
 word = word.strip(string.punctuation + string.whitespace)
 word = word.lower()
 hist[word] = hist.get(word, 0) + 1

def common_words(hist):
 t = []
 for key, value in hist.items():
 t.append((value, key))
 t.sort(reverse=True)
 return t

def most_common_words(hist, num=100):
 t = common_words(hist)
 print 'The most common words are:'
 for freq, word in t[:num]:
 print freq, '\t', word
hist = process_file('emma.txt')
print 'Total num of Words:', sum(hist.values())
print 'Total num of Unique Words:', len(hist)
most_common_words(hist, 50)

Any help would be greatly appreciated because i am struggling in this
class. Thank you in advance


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] Help please

2013-10-17 Thread Peter Otten
Alan Gauld wrote:

[Ruben Pinedo]

 def process_file(filename):
 hist = dict()
 fp = open(filename)
 for line in fp:
 process_line(line, hist)
 return hist
 
 def process_line(line, hist):
 line = line.replace('-', ' ')
 
 for word in line.split():
 word = word.strip(string.punctuation + string.whitespace)
 word = word.lower()
 
 hist[word] = hist.get(word, 0) + 1

[Alan Gauld]

 If so you need to fix the bugs in process_line() and
 process_file(). I don;t know if these are deliberate bugs
 or somebody is just sloppy. But neither work as expected
 right now. (Hint: Consider the return values of each)
 
I fail to see the bug. 

process_line() mutates its `hist` argument, so there's no need to return 
something. Or did you mean something else that escapes me?

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


Re: [Tutor] Help please

2013-10-17 Thread Dominik George
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Todd Matsumoto c.t.matsum...@gmail.com schrieb:
 #1. Error handling for the files to ensure reading only .txt file
Look up exceptions.
Find out what the string method endswith() does.

One should note that the OP probably meant files of the type text/plain rather 
than .txt files. File name extensions are a convenience to identify a file on 
first glance, but they tell absolutely nothing about the contents.

So, look up MIME types as well ;)!

- -nik
-BEGIN PGP SIGNATURE-
Version: APG v1.0.8-fdroid

iQFNBAEBCgA3BQJSX/F3MBxEb21pbmlrIEdlb3JnZSAobW9iaWxlIGtleSkgPG5p
a0BuYXR1cmFsbmV0LmRlPgAKCRAvLbGk0zMOJZxHB/9TGh6F1vRzgZmSMHt48arc
jruTRfvOK9TZ5MWm6L2ZpxqKr3zBP7KSf1ZWSeXIovat9LetETkEwZ9bzHBuN8Ve
m8YsOVX3zR6VWqGkRYYer3MbWo9DCONlJUKGMs/qjB180yxxhQ12Iw9WAHqam1Ti
n0CCWsf4l5B3WBe+t2aTOlQNmo//6RuBK1LfCrnYX0XV2Catv1075am0KaTvbxfB
rfHHnR4tdIYmZ8P/SkO3t+9JzJU9e+H2W90++K9EkMTBJxUhsa4AuZIEr8WqEfSe
EheQMUp23tlMgKRp6UHiRJBljEsQJ0XFuYa+zj6hXCXoru/9ReHTRWcvJEpfXxEC
=hJ0m
-END PGP SIGNATURE-

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


Re: [Tutor] Help please

2013-10-17 Thread Kengesbayev, Askar
Ruben,

#1 you can try something like this
  try:
with open('my_file.txt') as file:
pass
except IOError as e:
print Unable to open file  #Does not exist or you do not have read 
permission

#2. I would try to use regular expression push words to array and then you can 
manipulate array. Not sure if it is efficient way but it should work.
#3 . easy way would be to use regular expression. Re module.
#4. Once you will have array in #2 you can sort it and print whatever top words 
you need.
#5.  I am not sure the best way on this but you can play with array from #2.

Thanks,
Askar

From: Pinedo, Ruben A [mailto:rapin...@miners.utep.edu]
Sent: Wednesday, October 16, 2013 2:49 PM
To: tutor@python.org
Subject: [Tutor] Help please

I was given this code and I need to modify it so that it will:

#1. Error handling for the files to ensure reading only .txt file
#2. Print a range of top words... ex: print top 10-20 words
#3. Print only the words with  3 characters
#4. Modify the printing function to print top 1 or 2 or 3 
#5. How many unique words are there in the book of length 1, 2, 3 etc

I am fairly new to python and am completely lost, i looked in my book as to how 
to do number one but i cannot figure out what to modify and/or delete to add 
the print selection. This is the code:


import string

def process_file(filename):
hist = dict()
fp = open(filename)
for line in fp:
process_line(line, hist)
return hist

def process_line(line, hist):
line = line.replace('-', ' ')

for word in line.split():
word = word.strip(string.punctuation + string.whitespace)
word = word.lower()

hist[word] = hist.get(word, 0) + 1

def common_words(hist):
t = []
for key, value in hist.items():
t.append((value, key))

t.sort(reverse=True)
return t

def most_common_words(hist, num=100):
t = common_words(hist)
print 'The most common words are:'
for freq, word in t[:num]:
print freq, '\t', word

hist = process_file('emma.txt')
print 'Total num of Words:', sum(hist.values())
print 'Total num of Unique Words:', len(hist)
most_common_words(hist, 50)

Any help would be greatly appreciated because i am struggling in this class. 
Thank you in advance

Respectfully,

Ruben Pinedo
Computer Information Systems
College of Business Administration
University of Texas at El Paso
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help please

2013-10-17 Thread Alan Gauld

On 17/10/13 14:37, Peter Otten wrote:

Alan Gauld wrote:

[Ruben Pinedo]


def process_file(filename):
 hist = dict()
 fp = open(filename)
 for line in fp:
 process_line(line, hist)
 return hist



or somebody is just sloppy. But neither work as expected
right now. (Hint: Consider the return values of each)


I fail to see the bug.

process_line() mutates its `hist` argument, so there's no need to return
something. Or did you mean something else that escapes me?


Oops, no, you are right, I forgot it's mutable. I don't
like that style but that is not a bug...

I was expecting to see a hist = process_line(...)
and a return hist in there...

My bad.


--
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 Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-26 Thread Steven D'Aprano
On Thu, Sep 26, 2013 at 12:24:41AM +0200, Dino Bektešević wrote:
  Message: 1

and later:

 Message: 4

I don't suppose you are replying to a message digest, are you?

If so, thank you for changing the subject line to something more useful 
than just Re Digest, and thank you even more for trimming the content 
of your reply. But by replying to digests, you lose useful threading 
information.

In my opinion, digests are not terribly useful. If they have any use at 
all, it is only for those who want to read emails in the mailing list, 
then either keep them all, or delete them all. If you want to select 
which threads or messages to keep, digests are useless, and if you 
intend to carry on a conversation or discussion, they're even more 
useless.

Of course, I may be misinterpreting the Message numbers above, in 
which case, sorry for the noise.


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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-26 Thread David Robinow
On Wed, Sep 25, 2013 at 9:34 PM, Dave Angel da...@davea.name wrote:

 Clearly gmail isn't showing you all the headers.  I looked for Alan's
 message in one of these threads with the same subject, and see about 60
 lines of header information.  Does gmail have a View-Source menu item?

In gmail the menu item is Show Original
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-25 Thread Dino Bektešević
Hello,

I wrote a response on the subject in the title about creating a graph
in Python using the Graphics module presented in the standard python
tutorial on 23rd detailing full explanations but I still saw repeated
responses asking more of the same question (lines causing the error,
which graphics module are you referring to etc...) which is ok because
I don't mind multiple answers to the question, not everything usually
gets covered in only one and it's a check up if I answered something
wrong.

But it still kind of bothered me that so many of same questions got
repeated so I googled to see the archives and it seems my response was
not placed in the same archive thread as it should have been, and
doesn't appear in the response list of the question.

original question: http://code.activestate.com/lists/python-tutor/96889/
my response: http://code.activestate.com/lists/python-tutor/96897/

For someone browsing through Tutor in archive form I can see how this
is a tad confusing, is it fixable? I'm guessing that my mail wasn't
put in the response list because of different titles?

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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-25 Thread eryksun
On Tue, Sep 24, 2013 at 9:15 PM, Dino Bektešević ljet...@gmail.com wrote:

 original question: http://code.activestate.com/lists/python-tutor/96889/
 my response: http://code.activestate.com/lists/python-tutor/96897/

 For someone browsing through Tutor in archive form I can see how this
 is a tad confusing, is it fixable? I'm guessing that my mail wasn't
 put in the response list because of different titles?

Alan's reply, for example, has an In-Reply-To field:

In-Reply-To: 1379734001.35687.yahoomail...@web184701.mail.ne1.yahoo.com

Your message's header doesn't have this field:

From ljetibo at gmail.com  Mon Sep 23 23:17:00 2013
From: ljetibo at gmail.com (=?ISO-8859-2?Q?Dino_Bekte=B9evi=E6?=)
Date: Mon, 23 Sep 2013 23:17:00 +0200
Subject: [Tutor] HELP Please!!!How Do I Make a Graph Chart Generate
 in Python Based on my Code (znx...@yahoo.com)
Message-ID:
CAMGeA2Wt3zm=wu9r_7epm4hor7pji2b7rppntvgxa6m1cz8...@mail.gmail.com

Source:

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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-25 Thread Dave Angel
On 24/9/2013 21:15, Dino Bektešević wrote:

 Hello,

 I wrote a response on the subject in the title about creating a graph
 in Python using the Graphics module presented in the standard python
 tutorial on 23rd detailing full explanations but I still saw repeated
 responses asking more of the same question (lines causing the error,
 which graphics module are you referring to etc...) which is ok because
 I don't mind multiple answers to the question, not everything usually
 gets covered in only one and it's a check up if I answered something
 wrong.

 But it still kind of bothered me that so many of same questions got
 repeated so I googled to see the archives and it seems my response was
 not placed in the same archive thread as it should have been, and
 doesn't appear in the response list of the question.

 original question: http://code.activestate.com/lists/python-tutor/96889/
 my response: http://code.activestate.com/lists/python-tutor/96897/

 For someone browsing through Tutor in archive form I can see how this
 is a tad confusing, is it fixable? I'm guessing that my mail wasn't
 put in the response list because of different titles?


I can't answer for some third-party archive of the list.  But your
message on the current mailing list doesn't seem to be a reply to any
existing one.  I'm viewing the list through the news.gmane.org feed, and
it is happy to thread messages and their responses nicely, regardless of
subject line.

How did you respond to the earlier message?  Did you just compose a new
one and address it to the mailing list?


-- 
DaveA


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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-25 Thread znxm0i

Thanks Brian for replying but I already figured out what I was not doing 
correctlyalso the link you supplied was not what I needed.I had to make 
the user input statements appear as graphical input boxes and not just text and 
I figured out how to do it, so it now works like a charm

--
On Tue, Sep 24, 2013 8:14 PM CDT brian arb wrote:

http://mcsp.wartburg.edu/zelle/python/ppics1/code/chapter05/futval_graph2.py


On Tue, Sep 24, 2013 at 4:36 PM, School northri...@s.dcsdk12.org wrote:

 What is the error you received? What lines does it say are causing the
 error?

 Also, this smells like classwork.

 On Sep 20, 2013, at 21:26, znx...@yahoo.com wrote:

 Can anyone please help me figure out what I am NOT doing to make this
 program work properly.PLEASE !!

 I need to be able to take the user input that is entered in the two
 graphical boxes of the first window and evaluate it to generate a graph
 chart which is suppose to display in the second window.  I am totally at a
 loss for what I am NOT doing, and I know it is something so simple that I
 am overlooking because I am making this harder that what it most likely
 really is.

 But I just cannot get it to work properly.  Please HELP !!!  Help me
 understand what I am doing wrong and how to fix it.  I believe I am on the
 right path but I'm becoming frustrated and discouraged.

 I have attached a copy of the code I've compiled so far.

 futval_graph2.py

 ___
 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



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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-25 Thread Dino Bektešević
 Message: 1
 Date: Wed, 25 Sep 2013 06:29:30 -0400
 From: eryksun eryk...@gmail.com
 To: Dino Bekte?evi? ljet...@gmail.com
 Cc: tutor@python.org
 Subject: Re: [Tutor] HELP Please!!!How Do I Make a Graph Chart
 Generate in Python Based on my Code
 Message-ID:
 cacl+1avhzs0byopf1urnygywyafsy8hpfpbkk4kgxsyddtu...@mail.gmail.com
 Content-Type: text/plain; charset=UTF-8

 On Tue, Sep 24, 2013 at 9:15 PM, Dino Bekte?evi? ljet...@gmail.com wrote:

 original question: http://code.activestate.com/lists/python-tutor/96889/
 my response: http://code.activestate.com/lists/python-tutor/96897/

 For someone browsing through Tutor in archive form I can see how this
 is a tad confusing, is it fixable? I'm guessing that my mail wasn't
 put in the response list because of different titles?

 Alan's reply, for example, has an In-Reply-To field:

 In-Reply-To: 1379734001.35687.yahoomail...@web184701.mail.ne1.yahoo.com

 Your message's header doesn't have this field:

 From ljetibo at gmail.com  Mon Sep 23 23:17:00 2013
 From: ljetibo at gmail.com (=?ISO-8859-2?Q?Dino_Bekte=B9evi=E6?=)
 Date: Mon, 23 Sep 2013 23:17:00 +0200
 Subject: [Tutor] HELP Please!!!How Do I Make a Graph Chart Generate
  in Python Based on my Code (znx...@yahoo.com)
 Message-ID:
 CAMGeA2Wt3zm=wu9r_7epm4hor7pji2b7rppntvgxa6m1cz8...@mail.gmail.com

 Source:

 http://mail.python.org/pipermail/tutor


Where did you find that In-Reply-To: field? In example Alan's response
header, including the quoted section is shown to me as:

Message: 4
Date: Mon, 23 Sep 2013 18:21:03 +0100
From: Alan Gauld alan.ga...@btinternet.com
To: tutor@python.org
Subject: Re: [Tutor] HELP Please!!!How Do I Make a Graph Chart
Generate in Python Based on my Code
Message-ID: l1pt9n$tiq$1...@ger.gmane.org
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 21/09/13 04:26, znx...@yahoo.com wrote:
 Can anyone please help me figure out what I am NOT doing to make this
 program work properly.PLEASE !!

Which is the same for any response header I see. It doesn't seem to be
something I edit at all.

 Message: 2
 Date: Wed, 25 Sep 2013 10:45:57 + (UTC)
 From: Dave Angel da...@davea.name
 To: tutor@python.org
 Subject: Re: [Tutor] HELP Please!!!How Do I Make a Graph Chart
 Generatein Python Based on my Code
 Message-ID: l1uet3$atm$1...@ger.gmane.org
 Content-Type: text/plain; charset=ISO-8859-2

 On 24/9/2013 21:15, Dino Bekte?evi? wrote:

 I can't answer for some third-party archive of the list.  But your
 message on the current mailing list doesn't seem to be a reply to any
 existing one.  I'm viewing the list through the news.gmane.org feed, and
 it is happy to thread messages and their responses nicely, regardless of
 subject line.

 How did you respond to the earlier message?  Did you just compose a new
 one and address it to the mailing list?


 --
 DaveA

I use gmail and just use the funny looking arrow at the top that
says reply and I can see that in the news.gmane.org feed my mail is
sorted nicely in the response section but it isn't on either
code.activestate or on mail.python.org as eryksun stated as well.
I just want to be able to make my responses easily visible in most of
the online archives since otherwise they don't make sense for anyone
not subscribed to the daily mailing list.

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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-25 Thread Dave Angel
On 25/9/2013 18:24, Dino Bektešević wrote:


 Where did you find that In-Reply-To: field? In example Alan's response
 header, including the quoted section is shown to me as:

 Message: 4
 Date: Mon, 23 Sep 2013 18:21:03 +0100
 From: Alan Gauld alan.ga...@btinternet.com
 To: tutor@python.org
 Subject: Re: [Tutor] HELP Please!!!How Do I Make a Graph Chart
 Generate in Python Based on my Code
 Message-ID: l1pt9n$tiq$1...@ger.gmane.org
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed


Clearly gmail isn't showing you all the headers.  I looked for Alan's
message in one of these threads with the same subject, and see about 60
lines of header information.  Does gmail have a View-Source menu item?

Here's a small excerpt:

User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:17.0) Gecko/20130804 Thunderbird/17.0.8
In-Reply-To: 1379734001.35687.yahoomail...@web184701.mail.ne1.yahoo.com
X-BeenThere: tutor@python.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Discussion for learning programming with Python tutor.python.org
List-Unsubscribe: https://mail.python.org/mailman/options/tutor,


-- 
DaveA


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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-25 Thread eryksun
On Wed, Sep 25, 2013 at 6:24 PM, Dino Bektešević ljet...@gmail.com wrote:

 Where did you find that In-Reply-To: field? In example Alan's response
 header

Gmail has a Show original link in the message drop-down menu. But in
this case I just searched the September text archive:

https://mail.python.org/pipermail/tutor/2013-September.txt

I replied to you using Gmail's Reply to all in the webmail
interface, which added In-Reply-To and References to the header.

RFC 2822:
http://www.ietf.org/rfc/rfc2822.txt

   The In-Reply-To: and References: fields are used when creating a
   reply to a message.  They hold the message identifier of the original
   message and the message identifiers of other messages (for example,
   in the case of a reply to a message which was itself a reply).  The
   In-Reply-To: field may be used to identify the message (or
   messages) to which the new message is a reply, while the
   References: field may be used to identify a thread of
   conversation.

   When creating a reply to a message, the In-Reply-To: and
   References: fields of the resultant message are constructed as
   follows:

   The In-Reply-To: field will contain the contents of the Message-
   ID: field of the message to which this one is a reply (the parent
   message).  If there is more than one parent message, then the In-
   Reply-To: field will contain the contents of all of the parents'
   Message-ID: fields.  If there is no Message-ID: field in any of
   the parent messages, then the new message will have no In-Reply-To:
   field.

   The References: field will contain the contents of the parent's
   References: field (if any) followed by the contents of the parent's
   Message-ID: field (if any).  If the parent message does not contain
   a References: field but does have an In-Reply-To: field
   containing a single message identifier, then the References: field
   will contain the contents of the parent's In-Reply-To: field
   followed by the contents of the parent's Message-ID: field (if
   any).  If the parent has none of the References:, In-Reply-To:,
   or Message-ID: fields, then the new message will have no
   References: field.

   Note: Some implementations parse the References: field to display
   the thread of the discussion.  These implementations assume that
   each new message is a reply to a single parent and hence that they
   can walk backwards through the References: field to find the parent
   of each message listed there.  Therefore, trying to form a
   References: field for a reply that has multiple parents is
   discouraged and how to do so is not defined in this document.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-24 Thread bob gailer

In addition to Alan's comment:
Saying it work properly is totally uninformative. Tell us what is 
happening that you want different.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-24 Thread School
What is the error you received? What lines does it say are causing the error?

Also, this smells like classwork.

On Sep 20, 2013, at 21:26, znx...@yahoo.com wrote:

 Can anyone please help me figure out what I am NOT doing to make this program 
 work properly.PLEASE !!
 
 I need to be able to take the user input that is entered in the two graphical 
 boxes of the first window and evaluate it to generate a graph chart which is 
 suppose to display in the second window.  I am totally at a loss for what I 
 am NOT doing, and I know it is something so simple that I am overlooking 
 because I am making this harder that what it most likely really is.
 
 But I just cannot get it to work properly.  Please HELP !!!  Help me 
 understand what I am doing wrong and how to fix it.  I believe I am on the 
 right path but I'm becoming frustrated and discouraged.  
 
 I have attached a copy of the code I've compiled so far.
 futval_graph2.py
 ___
 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] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-24 Thread brian arb
http://mcsp.wartburg.edu/zelle/python/ppics1/code/chapter05/futval_graph2.py


On Tue, Sep 24, 2013 at 4:36 PM, School northri...@s.dcsdk12.org wrote:

 What is the error you received? What lines does it say are causing the
 error?

 Also, this smells like classwork.

 On Sep 20, 2013, at 21:26, znx...@yahoo.com wrote:

 Can anyone please help me figure out what I am NOT doing to make this
 program work properly.PLEASE !!

 I need to be able to take the user input that is entered in the two
 graphical boxes of the first window and evaluate it to generate a graph
 chart which is suppose to display in the second window.  I am totally at a
 loss for what I am NOT doing, and I know it is something so simple that I
 am overlooking because I am making this harder that what it most likely
 really is.

 But I just cannot get it to work properly.  Please HELP !!!  Help me
 understand what I am doing wrong and how to fix it.  I believe I am on the
 right path but I'm becoming frustrated and discouraged.

 I have attached a copy of the code I've compiled so far.

 futval_graph2.py

 ___
 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


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


[Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-23 Thread znxm0i
Can anyone please help me figure out what I am NOT doing to make this program 
work properly.PLEASE !!


I need to be able to take the user input that is entered in the two graphical 
boxes of the first window and evaluate it to generate a graph chart which is 
suppose to display in the second window.  I am totally at a loss for what I am 
NOT doing, and I know it is something so simple that I am overlooking because I 
am making this harder that what it most likely really is.

But I just cannot get it to work properly.  Please HELP !!!   Help me 
understand what I am doing wrong and how to fix it.  I believe I am on the 
right path but I'm becoming frustrated and discouraged.  

I have attached a copy of the code I've compiled so far.
# futval_graph2.py

from graphics import *

def main():
# Introduction
print(This program plots the growth of a 10-year investment.)

win = GraphWin(Growth of 10-Year Investment, 400, 300)
win.setCoords(0.0, 0.0, 3.0, 4.0)

# Draw the interface
Text(Point(1,3),Enter principal:).draw(win)
input = Entry(Point(2,3), 5)
input.setText(0.00)
input.draw(win)
principal = eval(input.getText())

Text(Point(1.10,2.5),Input APR:).draw(win)
input2 = Entry(Point(2,2.5), 5)
input2.setText(0.0)
input2.draw(win)
apr = eval(input2.getText())

output = Text(Point(0,0),)
output.draw(win)
button = Text(Point(1.5 ,1.65),Graph It)
button.draw(win)
Rectangle(Point(.5,2), Point(2.5,1.25)).draw(win)

# wait for a mouse click
win.getMouse()

win = GraphWin(Investment Growth Chart, 320, 240)
win.setBackground(white)
win.setCoords(-1.75,-200, 11.5, 10400)

# Create a graphics window with labels on left edge
Text(Point(-1, 0), ' 0.0K').draw(win)
Text(Point(-1, 2000), ' 2.5K').draw(win)
Text(Point(-1, 5000), ' 5.0K').draw(win)
Text(Point(-1, 7500), ' 7.5k').draw(win)
Text(Point(-1, 1), '10.0K').draw(win)

# Draw bar for initial principal
bar = Rectangle(Point(0, 0), Point(1, principal + apr))
bar.setFill(green)
bar.setWidth(2)
bar.draw(win)

# Draw a bar for each subsequent year
for year in range(1, 11):
bar = Rectangle(Point(year, 0), Point(year+1, principal))
bar.setFill(green)
bar.setWidth(2)
bar.draw(win)

win.getMouse()
win.close()

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


Re: [Tutor] HELP Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code

2013-09-23 Thread Alan Gauld

On 21/09/13 04:26, znx...@yahoo.com wrote:

Can anyone please help me figure out what I am NOT doing to make this
program work properly.PLEASE !!


First you need to tell us what graphics module you are
using since there is no standard library module by that
name.

Second, you should probably ask for help on their forum
since this list is really for those learning Python and
its standard library.

However, if we know the library we might be able to help
or someone may have some experience.


--
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 Please!!!....How Do I Make a Graph Chart Generate in Python Based on my Code (znx...@yahoo.com)

2013-09-23 Thread Dino Bektešević
Hello,

 I have attached a copy of the code I've compiled so far.

Next time just post the code in here, I think that's the general
consensus around here. You should only attach it or use a pastebin if
it's really really long. Considering that usually the only valid
entries here are snippets of code you've isolated that do not work
(functions/methods...), code that gets posted here is usually not too
long.
Anyhow the graphics.py module is unbeknownst to me, but I presume
you're reffering to this one:
http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/graphics.html

What you're doing wrong is your input:
principal = eval(input.getText())
apr = eval(input2.getText())
Those commands are in order, however their position in programing is
not. Let's examine:
1. you draw your input screen and define standard inputs for boxes
2. during the drawing session you read in values for which you have
provided input boxes
3. you plot the values in a bar graph.
When this runs it goes like this:
1. you draw your input screen, set values in input boxes to 0.0 and 0.0
2. apr and principal get set to 0.0 and 0.0
3. plot graph and values

and of course every single bar gets ploted to 0, because those are the
values of your inputs. If there is no principal to add apr to there is
no net result. You should make it so that apr and principal get set
AFTER the initial screen drawing session but BEFORE plotting,
therefore after the mouse-click.
You're also making a mistake of not actually changing any values as
the year progresses:
bar = Rectangle(Point(year, 0), Point(year+1, principal))
every bar will have the same height, that of the inputed principal value.

I don't know if it's encouraged here or not, to give straight away
answers, but here it goes anyway because I think znx is missing couple
of other things as well:
To sort out the wrong inputing move the eval() lines after the
win.getMouse() statement, preferably right before the for loop
statement. Your principal grows each year by the value of apr, so if
you have a 1000$ in the bank and the bank awards you with 500$ each
year (good luck with that) then by the end of the first year you
should have 1500$, by the end of the 2nd year 2000$ because the 1st
year becomes the principal for the 2nd year, by 3rd year it's 2500$
and so on
To introduce the changing values you have to have a new variable to
store the increased original value, let's call that variable
newvalue. Then you have to increase the value of the new variable
every complete step of the for loop. Each full circle of for loop
should see at least 1 newvalue = newvalue +apr (or newvalue+=apr in
short).

This solution removes the need for the # Draw bar for initial
principal set of orders so delete it:
# read values in input boxes AFTER the button click
principal = eval(input.getText())
apr = eval(input2.getText())

#create new value that you'll increase every year by apr
newvalue = principal+apr #this is the net money by the end of 1st year

# Draw a bar for each subsequent year
for year in range(0, 11): #by going from 0 you don't have to
specifically plot 1st year
bar = Rectangle(Point(year, 0), Point(year+1, newvalue))
newvalue = newvalue+apr
bar.setFill(green)
bar.setWidth(2) #I don't know if this serves any purpose
because the width of your bar is defined with year to year+1 values.
Maybe it's the line width?
bar.draw(win)

and that should do it. For a test run use print statement to check
that the for loop does what you want it too and use simple numbers as
principal=1000 and apr=500, you should get 1500, 2000, 2500..
(This looked a lot like a fixed interest rate assignment so I guess
that's the purpose, note that because of the set scale of the graph
you should always use larger numbers because smaller ones will not be
visible).

You can make your y axis change by the value of input if you:
1. read input after button click but before setting the scale
2. set scale from 0 to maximal achievable value + some aditional
height that you can see the entire graph (p.s. maximal achievable
value is principal+final_year*apr, so in your case,
principal+11*apr+500 [for spacing])
3. plot the rest

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


Re: [Tutor] Help Please

2013-07-10 Thread Dave Angel

On 07/05/2013 05:10 PM, Ashley Fowler wrote:


HOMEWORK

This is what I have so far. Can anyone make suggestions or tell me what I need 
to correct?
*
*



First thing to correct is the notion that you're due an instant answer. 
 You get frustrated after 3 minutes, and post a new message in a new 
thread, with slightly different (but still useless) subject line, and 
the new message is slightly different than the first.


People here are volunteers, and you should wait a minimum of 12 hours 
before reposting.  And then it should be a bump, on the same thread, not 
a new message.  And the new message may have corrections to the first, 
but do them as corrections, not a whole new text to read.


So next time:

Post a single message, send it as TEXT, not html, pick a subject line 
that has something to do with the content (90% of the threads here are 
asking for help, so the word help contributes nothing).  Specify your 
python version, specify what happened when you ran it:

1) I expected this...
2) Instead the program did this...

or

I ran it with these arguments, and got this exception, including 
traceback.


Thanks.

--
DaveA

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


[Tutor] Help please!

2012-12-14 Thread Jack Little
Hi Tutor,
I'm getting this error

Traceback (most recent call last): File C:\Users\Jack\Desktop\python\g.py, 
line 45, in module path_1pt1()
NameError: name 'path_1pt1' is not defined

With the attached file

Please get back to me
Thank you

g.py
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help please!

2012-12-14 Thread Kwpolska
On Sun, Dec 2, 2012 at 2:37 AM, Jack Little jacklittl...@yahoo.com wrote:
 Hi Tutor,
 I'm getting this error

 Traceback (most recent call last): File C:\Users\Jack\Desktop\python\g.py,
 line 45, in module path_1pt1() NameError: name 'path_1pt1' is not defined

 With the attached file

 Please get back to me
 Thank you

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


You need to define path_1pt1 *before* simpstart.  Also, about not “free source”:
(a) did you mean: open source?
(b) why did you publish it here?

-- 
Kwpolska http://kwpolska.tk
stop html mail  | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help please!

2012-12-14 Thread Steven D'Aprano

On 02/12/12 12:37, Jack Little wrote:

Hi Tutor,
I'm getting this error

Traceback (most recent call last): File C:\Users\Jack\Desktop\python\g.py,
line 45, inmodule  path_1pt1()
NameError: name 'path_1pt1' is not defined



Names need to be defined before they are used. Code needs to be indented to
be inside a function, if it is not indented then it is considered to be part
of the top level code that runs immediately.

So you begin a new function, simpstart:



def simpstart():
   global ammo
   global health
   global tech_parts
   global radio_parts


By the way, you can consolidate those four lines to one:

global ammo, health, tech_parts, radio_parts


But here you lose the indentation, so Python considers the following to
be top level code and executes it immediately:


print You awake in a haze. A crate,a door and a radio.
g1 = raw_input(Which do you choose  )


Questions in English should end with a question mark, or people will
consider you ignorant and illiterate. Unless you are a famous poet
or artist, in which case they will fawn over how transgressive you are.



if g1 == CRATE or g1 == Crate or g1 == crate:


What if they type cRAtE or crATE?

Much simpler to do this:

if g1.lower() == create:

By the way, you will find programming much, much simpler if you always
use meaningful variable names. g1? What does that mean? A better name
would be something like user_response, or even just response.

So, skipping ahead, we come to this bit:


elif g2 == NORTH or g2 == North or g2 == north:
 path_1pt1()


Again, this is better written as if g2.lower() == 'north':.

At this point, Python then tries to call the path_1pt function, but it
hasn't been defined yet. So it gives you a NameError.

How do you fix this? Simple: this entire block of code needs to be
indented level with the global declarations at the start of simstart.

(Fixing this error may very well reveal further errors. Good luck!)

Another comment:



#A Towel Production
# APOC
#---
global ammo1
global ammo2
global ammo3
global health
global tech_parts
global exp
global radio_parts


These seven global lines don't do anything. They are literally pointless. One
of the mysteries to me is why Python allows global declarations outside of
functions, but these lines literally do nothing at all except fool the reader
(you!) into thinking that they do something. Get rid of them.



ammo1=10
ammo2=0
ammo3=0


I note that you have three variables, ammo1 through ammo3, but in the
simpstart function, you declare a global ammo.




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


[Tutor] Hello Python Tutor - help please!

2012-08-23 Thread Ron Painter
Hi, Cecilia:

I came across your posts when catching up with my tutor-request digest
emails. I did not see the Udacity site mentioned--if it was, my apologies
for the repetition.

Udacity.com, a free online education service, offers a number of
high-quality courses. They include interactive quizzes using code
sandboxes. The courses are 7 weeks long with online office hours and
forums. If you do not want to wait for the next start date, you can take
the courses online without getting instructor responses to students' posts.

Free Interactive Computer Courses (interaction via online quizzes using
code sandboxes):
http://www.udacity.com/

Intro to Computer Science
Python -- Beginner -- Project create functional search engine
http://www.udacity.com/view#Course/cs101/CourseRev/apr2012/Unit/671001/Nugget/675002

Programming Languages
Python, JavaScript -- Intermediate -- Project: Build a Functional Web
Browser
http://www.udacity.com/view#Course/cs262/CourseRev/apr2012/Unit/3001/Nugget/5001

Web Application Engineering
Python -- Intermediate -- Project: Build a Functional Blog
http://www.udacity.com/view#Course/cs253/CourseRev/apr2012/Unit/4001/Nugget/5002

Other courses available.

Best regards,
Ron Painter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Cecilia Chavana-Bryant
Dear all,

I am just returning to my doctoral studies after a 7-month medical leave and 
desperately trying to catch up for lost time. I am COMPLETELY new to 
programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little 
success) but had to stop and then spent 2 years in the Amazon climbing trees 
(lots more enjoyable than learning to programme!) and collecting loads of field 
data that I now need to post-process and analyse. By the way, the 3 weeks I 
spent trying to learn C really ended up being spent trying to get to grips with 
using a terminal for the first time in my life.

Since getting back to work, I was advised to try learning Python instead of C 
as it is a much easier first language to learn. I have been trying, but again, 
to not great success. I started following A Primer on Scientific programming 
with Python but I kept getting lost and stuck, specially on the exercises. I 
have also been advised that I should not try to learn programming by following 
guides but by trying to write the programmes I need to analyse my data. 
Although I can understand the logic behind this last bit of advise (it gives 
context and direction to the learning process) I have also gotten stuck trying 
this approach as I do not know how to programme!. Thus, I was hoping that 
some of you can remember how you got started and point me towards any really 
good interactive learning guides/materials and/or have a good learning strategy 
for a complete beginner. I have searched the web and was overwhelmed by choice 
of tutorials and guides. I have skimmed through a couple of tutorials but then 
fail to see how all that relates to my own work and I get stuck with what seems 
like basic important concepts so I don't progress. I then think I should try to 
make some progress with my own data analysing and go back to trying to learn to 
write a programme for my specific needs and get stuck again because this 
requires more advanced skills then the basic programming concepts I have been 
reading about on the learning guides. So, I am now feeling VERY frustrated and 
have no idea what on Earth I am doing! Can anyone please offer guidance in my 
learning process? I don't know how and what I should be spending my time 
learning first and/or if I should focus my learning towards the skill areas I 
will require to write my specific programmes, although I have no idea what 
these are. I would like advise on finding some really good interactive(let you 
know if your solution to an exercise is correct or not) and or video tutorials 
that give you feedback on the solutions you write to exercises.

Many thanks in advance for all your help, it will be much appreciated!



Cecilia Chavana-Bryant
DPhil Candidate - Remote sensing and tropical phenology
Environmental Change Institute
School of Geography and the Environment
University of Oxford
South Parks Road, Oxford, OX1 3QY
Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php
Tel Direct: +44 (0)1865 275861
Fax: +44 (0)1865 275885
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Mario Cacciatore
Hello,

My highest recommendation for you is to start with a simple hello world
program. Study that program, each line. Think about how and most
importantly, why it works.

Then, extend on it. Make it write to a file instead of a terminal. Then
make it read from a file and print to the terminal. Then make it print one
letter to each file, then read them back in and reconstruct the sentence.

Just take it slow, and one step at a time. So many times people simply go
for complex solutions and get lost in the complexity.

Sorry for top posting. My phone client doesn't support inline replies.

-Mario
--
From: Cecilia Chavana-Bryant
Sent: 8/22/2012 6:35 AM
To: tutor@python.org
Subject: [Tutor] Hello Python Tutor - help please!

   Dear all,

 I am just returning to my doctoral studies after a 7-month medical leave
and desperately trying to catch up for lost time. I am COMPLETELY new to
programming, well, I did try learning C for 3 weeks 3 yrs ago (with very
little success) but had to stop and then spent 2 years in the Amazon
climbing trees (lots more enjoyable than learning to programme!) and
collecting loads of field data that I now need to post-process and analyse.
By the way, the 3 weeks I spent trying to learn C really ended up being
spent trying to get to grips with using a terminal for the first time in my
life.

 Since getting back to work, I was advised to try learning Python instead
of C as it is a much easier first language to learn. I have been trying,
but again, to not great success. I started following A Primer on
Scientific programming with Python but I kept getting lost and stuck,
specially on the exercises. I have also been advised that I should not try
to learn programming by following guides but by trying to write the
programmes I need to analyse my data. Although I can understand the logic
behind this last bit of advise (it gives context and direction to the
learning process) I have also gotten stuck trying this approach as I do
not know how to programme!. Thus, I was hoping that some of you can
remember how you got started and point me towards any really good
interactive learning guides/materials and/or have a good learning strategy
for a complete beginner. I have searched the web and was overwhelmed by
choice of tutorials and guides. I have skimmed through a couple of
tutorials but then fail to see how all that relates to my own work and I
get stuck with what seems like basic important concepts so I don't
progress. I then think I should try to make some progress with my own data
analysing and go back to trying to learn to write a programme for my
specific needs and get stuck again because this requires more advanced
skills then the basic programming concepts I have been reading about on the
learning guides. So, I am now feeling VERY frustrated and have no idea what
on Earth I am doing! Can anyone please offer guidance in my learning
process? I don't know how and what I should be spending my time learning
first and/or if I should focus my learning towards the skill areas I will
require to write my specific programmes, although I have no idea what these
are. I would like advise on finding some really good interactive(let you
know if your solution to an exercise is correct or not) and or video
tutorials that give you feedback on the solutions you write to exercises.

 Many thanks in advance for all your help, it will be much appreciated!



Cecilia Chavana-Bryant
DPhil Candidate - Remote sensing and tropical phenology
Environmental Change Institute
School of Geography and the Environment
University of Oxford
South Parks Road, Oxford, OX1 3QY
Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php
Tel Direct: +44 (0)1865 275861
Fax: +44 (0)1865 275885
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread leon zaat

If you don't have any prior programmers skills, i would advice first to learn 
the basics. You will need a good foundation, before it is possible to create 
complex functions.
Starting with complex functions is only frustrating if you don't understand the 
basics. 

From: cecilia.chavana-bry...@ouce.ox.ac.uk
To: tutor@python.org
Date: Wed, 22 Aug 2012 10:10:46 +
Subject: [Tutor] Hello Python Tutor - help please!







Dear all,



I am just returning to my doctoral studies after a 7-month medical leave and 
desperately trying to catch up for lost time. I am COMPLETELY new to 
programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little 
success) but had to stop and
 then spent 2 years in the Amazon climbing trees (lots more enjoyable than 
learning to programme!) and collecting loads of field data that I now need to 
post-process and analyse. By the way, the 3 weeks I spent trying to learn C 
really ended up being spent
 trying to get to grips with using a terminal for the first time in my life. 



Since getting back to work, I was advised to try learning Python instead of C 
as it is a much easier first language to learn. I have been trying, but again, 
to not great success. I started following A Primer on Scientific programming 
with Python but
 I kept getting lost and stuck, specially on the exercises. I have also been 
advised that I should not try to learn programming by following guides but by 
trying to write the programmes I need to analyse my data. Although I can 
understand the logic behind this
 last bit of advise (it gives context and direction to the learning process) I 
have also gotten stuck trying this approach as I do not know how to 
programme!. Thus, I was hoping that some of you can remember how you got 
started and point me towards any really
 good interactive learning guides/materials and/or have a good learning 
strategy for a complete beginner. I have searched the web and was overwhelmed 
by choice of tutorials and guides. I have skimmed through a couple of tutorials 
but then fail to see how all
 that relates to my own work and I get stuck with what seems like basic 
important concepts so I don't progress. I then think I should try to make some 
progress with my own data analysing and go back to trying to learn to write a 
programme for my specific needs
 and get stuck again because this requires more advanced skills then the basic 
programming concepts I have been reading about on the learning guides. So, I am 
now feeling VERY frustrated and have no idea what on Earth I am doing! Can 
anyone please offer guidance
 in my learning process? I don't know how and what I should be spending my time 
learning first and/or if I should focus my learning towards the skill areas I 
will require to write my specific programmes, although I have no idea what 
these are. I would like
 advise on finding some really good interactive(let you know if your solution 
to an exercise is correct or not) and or video tutorials that give you feedback 
on the solutions you write to exercises.   




Many thanks in advance for all your help, it will be much appreciated!








Cecilia Chavana-Bryant

DPhil Candidate - Remote sensing and tropical phenology

Environmental Change Institute

School of Geography and the Environment

University of Oxford

South Parks Road, Oxford, OX1 3QY

Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php

Tel Direct: +44 (0)1865 275861

Fax: +44 (0)1865 275885









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


Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Steven D'Aprano

Hello Cecilia,

My replies are below, interleaved with your comments, which are
prefixed with  marks.


On 22/08/12 20:10, Cecilia Chavana-Bryant wrote:


By the way, the 3 weeks I spent trying to learn C really ended up
being spent trying to get to grips with using a terminal for the
first time in my life.


Unfortunately, there will be a certain amount of that, or at least
something quite similar to a terminal. Fortunately, using Python in
the terminal is usually MUCH easier than C, and in my experience
using Python's interactive interpreter is one of the best ways to
learn the language.

What sort of computer are you using? Windows, Linux, Macintosh, or
something different? I think that most of the people here use Linux
or Windows, but we can probably help you one way or the other.



Since getting back to work, I was advised to try learning Python
instead of C as it is a much easier first language to learn.


Yes, definitely, but it is still programming. Don't overestimate
the difficulty, if it was hard programmers couldn't learn to do it
*wink*, but on the other hand it's not trivial either.



I have been trying, but again, to not great success. I started
following A Primer on Scientific programming with Python but I
kept getting lost and stuck, specially on the exercises.


If you are willing to make a good, honest effort on the exercises
first, we're happy to help you with them. We do like to see your
attempt first, so that we can suggest fixes rather than solve the
problem for you.



I have also been advised that I should not try to learn
programming by following guides but by trying to write the
programmes I need to analyse my data. Although I can understand
the logic behind this last bit of advise (it gives context and
direction to the learning process) I have also gotten stuck
trying this approach as I do not know how to programme!.


I'm entirely with you there. Having direction in your learning is
a good thing. But until you understand the basic skills you need,
it will be nothing but frustration and pain!

I recommend that, if nothing else, you work through some basic
tutorials so that you at least have some idea of basic language
constructs like:

- strings
- lists
- functions
- ints
- floats
- basic arithmetic
- importing modules
etc.

You could start with the official Python tutorial:

http://docs.python.org/tutorial/index.html

although I find that it is sometimes a bit wordy. (I should
talk...)

If you get stuck, don't hesitate to come back and ask
questions, that's why we're here.



Thus, I was hoping that some of you can remember how you got
started


I learned from the book Learning Python by Mark Lutz and
David Ascher, and then by writing oodles and oodles of really
bad code which I have long since thrown away :)


[...]

So, I am now feeling VERY frustrated and have no idea what on
Earth I am doing! Can anyone please offer guidance in my
learning process?


I feel your pain! That's how I feel every time I try to understand
monads in Haskell (don't ask!).

How about if you start off with a simple question you would like
to solve using Python? Something relevant to your work. You may
need to explain some of the concepts to us, since we're not
ecologists. (At least, I'm not, I can't speak for others.)

We can then try to guide you to a solution and introduce concepts
as we go.




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


Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Cecilia Chavana-Bryant
Hola Bill,

Many thanks for your reply to my post, you seem to understand the predicament I 
am in very well. Unfortunately, I am currently working from home and do not 
have someone close by to help and this is why I came to this space. This is 
also why I asked for advise about interactive tutorials or video tutorials. I 
have found that I keep getting lost with the more traditional tutorials where 
you just read and then do exercises. Following the guide I mentioned on my 
initial post I got through the first 2 chapters but I found them quite hard 
going. I don't know if this makes me not a complete beginner but I certainly do 
not feel like I learned much from reading them. Maybe it is the trying to learn 
the computer ecosystem of terminal commands at the same time that is making 
this learning process so tough.

With respect to my field data, during my 2 yrs of fieldwork I collected a large 
amount of data which is currently stored in excel files. My research involves 
remote sensing (data from Earth-observation satellites) and I work with data 
from the MODIS NASA satellite which monitors the health of forest canopies 
using reflectance data. My research is based in the Amazon. I have collected 
field data to monitor the leaf dynamics of canopy leaves during the dry season. 
Dry season is the time of year when many tropical trees change their old leaves 
for new ones. New leaves are more photosynthetically active (absorb more carbon 
from and release more oxygen into the atmosphere) so the leaf exchange of such 
a large forest region as the Amazon can have huge effects on regional and 
global carbon and water cycles and thus on global climate (apologies if I'm 
giving you loads more information than you need or requested?!). My data 
involves a large amount of data on leaf demography (we demographically surveyed 
more than 120,000 leaves), and thousands of morphological and reflectance 
measurements. I will have to reorganise this data and create a few easily 
manipulable datasets so I can sort data according to leaf age, canopy position, 
date, etc. Then I will have to do statistical analyses on the data. I will also 
have to model some of the data.

Many thanks for taking the time to respond to my post so comprehensively and 
for your good wishes.


Cecilia Chavana-Bryant
DPhil Candidate - Remote sensing and tropical phenology
Environmental Change Institute
School of Geography and the Environment
University of Oxford
South Parks Road, Oxford, OX1 3QY
Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php
Tel Direct: +44 (0)1865 275861
Fax: +44 (0)1865 275885

From: William R. Wing (Bill Wing) [w...@mac.com]
Sent: 22 August 2012 15:17
To: Cecilia Chavana-Bryant
Cc: William R. Wing (Bill Wing)
Subject: Re: [Tutor] Hello Python Tutor - help please!

On Aug 22, 2012, at 6:10 AM, Cecilia Chavana-Bryant 
cecilia.chavana-bry...@ouce.ox.ac.ukmailto:cecilia.chavana-bry...@ouce.ox.ac.uk
 wrote:

Dear all,

I am just returning to my doctoral studies after a 7-month medical leave and 
desperately trying to catch up for lost time. I am COMPLETELY new to 
programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little 
success) but had to stop and then spent 2 years in the Amazon climbing trees 
(lots more enjoyable than learning to programme!) and collecting loads of field 
data that I now need to post-process and analyse. By the way, the 3 weeks I 
spent trying to learn C really ended up being spent trying to get to grips with 
using a terminal for the first time in my life.


Could you say a few words about what the field data is, and how you hope to 
analyze it.  That is, are you headed in the direction of plotting species 
density on maps, or the time evolution of something, or doing statistics?

Since getting back to work, I was advised to try learning Python instead of C 
as it is a much easier first language to learn. I have been trying, but again, 
to not great success. I started following A Primer on Scientific programming 
with Python but I kept getting lost and stuck, specially on the exercises. I 
have also been advised that I should not try to learn programming by following 
guides but by trying to write the programmes I need to analyse my data. 
Although I can understand the logic behind this last bit of advise (it gives 
context and direction to the learning process) I have also gotten stuck trying 
this approach as I do not know how to programme!. Thus, I was hoping that 
some of you can remember how you got started and point me towards any really 
good interactive learning guides/materials and/or have a good learning strategy 
for a complete beginner. I have searched the web and was overwhelmed by choice 
of tutorials and guides. I have skimmed through a couple of tutorials but then 
fail to see how all that relates to my own work and I get stuck with what seems 
like basic important concepts so I don't progress. I then think I

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Joel Goldstick
On Wed, Aug 22, 2012 at 11:33 AM, Cecilia Chavana-Bryant
cecilia.chavana-bry...@ouce.ox.ac.uk wrote:
 Hola Bill,

 Many thanks for your reply to my post, you seem to understand the
 predicament I am in very well. Unfortunately, I am currently working from
 home and do not have someone close by to help and this is why I came to this
 space. This is also why I asked for advise about interactive tutorials or
 video tutorials. I have found that I keep getting lost with the more
 traditional tutorials where you just read and then do exercises. Following
 the guide I mentioned on my initial post I got through the first 2 chapters
 but I found them quite hard going. I don't know if this makes me not a
 complete beginner but I certainly do not feel like I learned much from
 reading them. Maybe it is the trying to learn the computer ecosystem of
 terminal commands at the same time that is making this learning process so
 tough.

 With respect to my field data, during my 2 yrs of fieldwork I collected a
 large amount of data which is currently stored in excel files. My research
 involves remote sensing (data from Earth-observation satellites) and I work
 with data from the MODIS NASA satellite which monitors the health of forest
 canopies using reflectance data. My research is based in the Amazon. I have
 collected field data to monitor the leaf dynamics of canopy leaves during
 the dry season. Dry season is the time of year when many tropical trees
 change their old leaves for new ones. New leaves are more photosynthetically
 active (absorb more carbon from and release more oxygen into the atmosphere)
 so the leaf exchange of such a large forest region as the Amazon can have
 huge effects on regional and global carbon and water cycles and thus on
 global climate (apologies if I'm giving you loads more information than you
 need or requested?!). My data involves a large amount of data on leaf
 demography (we demographically surveyed more than 120,000 leaves), and
 thousands of morphological and reflectance measurements. I will have to
 reorganise this data and create a few easily manipulable datasets so I can
 sort data according to leaf age, canopy position, date, etc. Then I will
 have to do statistical analyses on the data. I will also have to model some
 of the data.

 Many thanks for taking the time to respond to my post so comprehensively and
 for your good wishes.


 Cecilia Chavana-Bryant
 DPhil Candidate - Remote sensing and tropical phenology
 Environmental Change Institute
 School of Geography and the Environment
 University of Oxford
 South Parks Road, Oxford, OX1 3QY
 Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php
 Tel Direct: +44 (0)1865 275861
 Fax: +44 (0)1865 275885
 
 From: William R. Wing (Bill Wing) [w...@mac.com]
 Sent: 22 August 2012 15:17
 To: Cecilia Chavana-Bryant
 Cc: William R. Wing (Bill Wing)
 Subject: Re: [Tutor] Hello Python Tutor - help please!

 On Aug 22, 2012, at 6:10 AM, Cecilia Chavana-Bryant
 cecilia.chavana-bry...@ouce.ox.ac.uk wrote:

 Dear all,

 I am just returning to my doctoral studies after a 7-month medical leave and
 desperately trying to catch up for lost time. I am COMPLETELY new to
 programming, well, I did try learning C for 3 weeks 3 yrs ago (with very
 little success) but had to stop and then spent 2 years in the Amazon
 climbing trees (lots more enjoyable than learning to programme!) and
 collecting loads of field data that I now need to post-process and analyse.
 By the way, the 3 weeks I spent trying to learn C really ended up being
 spent trying to get to grips with using a terminal for the first time in my
 life.


 Could you say a few words about what the field data is, and how you hope to
 analyze it.  That is, are you headed in the direction of plotting species
 density on maps, or the time evolution of something, or doing statistics?

 Since getting back to work, I was advised to try learning Python instead of
 C as it is a much easier first language to learn. I have been trying, but
 again, to not great success. I started following A Primer on Scientific
 programming with Python but I kept getting lost and stuck, specially on the
 exercises. I have also been advised that I should not try to learn
 programming by following guides but by trying to write the programmes I need
 to analyse my data. Although I can understand the logic behind this last bit
 of advise (it gives context and direction to the learning process) I have
 also gotten stuck trying this approach as I do not know how to programme!.
 Thus, I was hoping that some of you can remember how you got started and
 point me towards any really good interactive learning guides/materials
 and/or have a good learning strategy for a complete beginner. I have
 searched the web and was overwhelmed by choice of tutorials and guides. I
 have skimmed through a couple of tutorials but then fail to see how all that
 relates to my own work and I get

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Alan Gauld

On 22/08/12 11:10, Cecilia Chavana-Bryant wrote:


I do not know how to programme!. Thus, I was hoping that some of you
can remember how you got started and point me towards any really good
interactive learning guides/materials and/or have a good learning
strategy for a complete beginner.


At the risk of self promotion you could try the early stages of my 
tutorial (see .sig).


It starts from level zero and explains the concepts of programming 
before getting started writing code. I personally found that to be 
fundamental to my learning when I started (and why I included it!).


It then goes through the basic programming structures using very
simple examples - a multiplication table and address book mainly.
(It includes VBScript and Javascript examples too but feel free to 
ignore them if you find they confuse more than help! The intent is to 
show the common structures present in all programming languages :-)


Whether you progress beyond the first two sections depends on what you 
want to do next. Those would be enough to start writing programs related 
to your work and switching to another tutor at that point

might be effective.

But the concepts topics at the start of my tutor are I think
relatively unique, and if diving straight into writing code isn't 
working maybe a view of the bigger picture will help.


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

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


Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Walter Prins
Hi Cecilia,

You've had a lot of good replies already, but I'd like to add the
following points if I may:

1) You probably should figure out as much as that's possible up front
exactly you're trying to do in terms of data processing first (e.g.
some idea of the stats, graphs, summaries, operations etc), and then
figure out whether Python is in fact the quickest/best way to get
there for you.  Python is very capable, it has many data analysis
libraries and so on and is used by many scientists (NumPy, SciPy,
Pandas comes to mind offhand), but then there are also many other
languages and system also appropriate in this sphere.  (R comes to
mind.)  Your goal (from my point of view) is not to become a
programmer, but to get your research done.  Python may be the way to
achieve that, but from where I'm sitting it may also not be.

2) It may be useful to take some suitable courses from some of the
very good free online courses now available from various sources such
as Coursera.  Some examples that seem relevant:

Computing for Data Analysis:
https://www.coursera.org/course/compdata

Mathematics Biostatistics Boot camp:
https://www.coursera.org/course/biostats

Data Analysis
https://www.coursera.org/course/dataanalysis

There are also courses covering basic programming, including Python,
for example: https://www.coursera.org/course/programming1

HTH,

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


Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Ray Jones

I highly recommend the Google Python class that is found on YouTube.
The first video is found at http://www.youtube.com/watch?v=tKTZoB2Vjuk
The supporting class materials and assignments are found at
http://code.google.com/edu/languages/google-python-class/ . This series
of videos begins at a pretty basic level, but subsequent videos increase
the difficulty level pretty rapidly.

Don't despair - the concept of how to properly manipulate strings,
lists, tuples, and other objects is rather daunting, but if you're
working on your doctoral studies, you already know that complex concepts
aren't simply soaked up like water to a sponge ;).


Ray

On 08/22/2012 03:10 AM, Cecilia Chavana-Bryant wrote:
 Dear all,

 I am just returning to my doctoral studies after a 7-month medical
 leave and desperately trying to catch up for lost time. I am
 COMPLETELY new to programming, well, I did try learning C for 3 weeks
 3 yrs ago (with very little success) but had to stop and then spent 2
 years in the Amazon climbing trees (lots more enjoyable than learning
 to programme!) and collecting loads of field data that I now need to
 post-process and analyse. By the way, the 3 weeks I spent trying to
 learn C really ended up being spent trying to get to grips with using
 a terminal for the first time in my life. 

 Since getting back to work, I was advised to try learning Python
 instead of C as it is a much easier first language to learn. I have
 been trying, but again, to not great success. I started following A
 Primer on Scientific programming with Python but I kept getting lost
 and stuck, specially on the exercises. I have also been advised that I
 should not try to learn programming by following guides but by trying
 to write the programmes I need to analyse my data. Although I can
 understand the logic behind this last bit of advise (it gives context
 and direction to the learning process) I have also gotten stuck trying
 this approach as I do not know how to programme!. Thus, I was hoping
 that some of you can remember how you got started and point me towards
 any really good interactive learning guides/materials and/or have a
 good learning strategy for a complete beginner. I have searched the
 web and was overwhelmed by choice of tutorials and guides. I have
 skimmed through a couple of tutorials but then fail to see how all
 that relates to my own work and I get stuck with what seems like basic
 important concepts so I don't progress. I then think I should try to
 make some progress with my own data analysing and go back to trying to
 learn to write a programme for my specific needs and get stuck again
 because this requires more advanced skills then the basic programming
 concepts I have been reading about on the learning guides. So, I am
 now feeling VERY frustrated and have no idea what on Earth I am doing!
 Can anyone please offer guidance in my learning process? I don't know
 how and what I should be spending my time learning first and/or if I
 should focus my learning towards the skill areas I will require to
 write my specific programmes, although I have no idea what these are.
 I would like advise on finding some really good interactive(let you
 know if your solution to an exercise is correct or not) and or video
 tutorials that give you feedback on the solutions you write to
 exercises.   

 Many thanks in advance for all your help, it will be much appreciated!
 


 Cecilia Chavana-Bryant
 DPhil Candidate - Remote sensing and tropical phenology
 Environmental Change Institute
 School of Geography and the Environment
 University of Oxford
 South Parks Road, Oxford, OX1 3QY
 Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php
 Tel Direct: +44 (0)1865 275861
 Fax: +44 (0)1865 275885


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

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


[Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Cecilia Chavana-Bryant
Steven, (now from my new account without all the long-winded signature) can
files be attached to posts in this forum?

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


Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Alan Gauld

On 22/08/12 22:51, Cecilia Chavana-Bryant wrote:

Steven, (now from my new account without all the long-winded signature)
can files be attached to posts in this forum?


Yes they can, but we prefer if you just include them in the body if they 
are fairly short (100 lines?) or put them on a pastebin with a link.


Some mail tools/servers/smartphones don't like mail attachments.


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

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


Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Alan Gauld

On 22/08/12 21:51, Cecilia Chavana-Bryant wrote:


def main(fname, sheet_name):
 wb = xlrd.open_workbook(fname)
 sh = wb.sheet_by_name(sheet_name)
 data1 = sh.col_values(0)
 data2 = sh.col_values(1)

 return data1, data2

fname = Cal_File_P17.xlsx
sheet_name = RefPanelData
(data1, data2) = main(fname)

print data1, data2

... I do not know where the data is being saved to.



That's because it isn't being saved anywhere, it gets
thrown away after printing it.

If you want to save it you need to augment/replace the print
statement with a file write statement(s)

You could also write it out using the OS redirection facility.
On Unix (ie Your MacOS Terminal) thats done by running the
program like:

$ python myprog.py  myOutputFile.txt

Where you substitute your own desired program name and
output filename of course!

But that will just create a text file that looks like the output 
displayed on the Terminal, which is not, I think, what you are after.

You probably want to do some extra work to save as a csv file.

However, before you do that you could look at using the spreadsheet's 
SaveAs feature to export as a CSV directly, but it depends on how many 
spreadsheets you need to convert!


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

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


Re: [Tutor] Help please!

2012-07-31 Thread ttmticdi .
  print Mum is in a %s mood % (mum_mood)
  print Dad is in a %s mood % (dad_mood)




Hi Victoria!

Since you have only one format character in the strings above there is
no need to surround the variables mum_mood and dad_mood with
parenthesis.
You only do that when you have multiple formats in your string that
print multiple variables.

Ex:

print Hi %s! You like %s and %s (user_name, x, y)




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


Re: [Tutor] Help please!

2012-07-31 Thread Joel Goldstick
On Tue, Jul 31, 2012 at 5:52 AM, ttmticdi . ttmti...@gmail.com wrote:
  print Mum is in a %s mood % (mum_mood)
  print Dad is in a %s mood % (dad_mood)




 Hi Victoria!

 Since you have only one format character in the strings above there is
 no need to surround the variables mum_mood and dad_mood with
 parenthesis.
 You only do that when you have multiple formats in your string that
 print multiple variables.

 Ex:

No!
 print Hi %s! You like %s and %s (user_name, x, y)

Yes!
  print Hi %s! You like %s and %s % (user_name, x, y)



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



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


Re: [Tutor] Help please!

2012-07-31 Thread ttmticdi .
 Ex:

 No!
 print Hi %s! You like %s and %s (user_name, x, y)

 Yes!
   print Hi %s! You like %s and %s % (user_name, x, y)




Forgot the interpolation operator(%). Thank you very much Joel for
correcting me.

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


[Tutor] Help please!

2012-07-30 Thread Victoria Homsy
Hi! I am a new Python user, and would really appreciate some help. My code is 
as follows:

from sys import argvs
script, mum_mood, dad_mood = argvs

# my own function
def dad_and_mum_mood(mum_mood, dad_mood):
print If both mum and dad are in a good mood, all is good.
print If one is and one isn't, all is good.
print If both are in a bad mood, not so good.
print Mum is in a %s mood % (mum_mood)
print Dad is in a %s mood % (dad_mood)
print Where does that leave us?

 
dad_and_mum_mood(mum_mood, dad_mood)


I am just trying to get get the information mum_mood and dad_mood from the 
argvs (written into the command line), but I get the error ImportError: cannot 
import name argvs.

Do you have any idea why this wouldn't be working? Thank you so much for 
helping me. 

Kind regards, 

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


Re: [Tutor] Help please!

2012-07-30 Thread Puneeth Chaganti
On Mon, Jul 30, 2012 at 9:35 PM, Victoria Homsy victoriaho...@yahoo.com wrote:
 Hi! I am a new Python user, and would really appreciate some help. My code
 is as follows:

 from sys import argvs
 script, mum_mood, dad_mood = argvs

 # my own function
 def dad_and_mum_mood(mum_mood, dad_mood):
 print If both mum and dad are in a good mood, all is good.
 print If one is and one isn't, all is good.
 print If both are in a bad mood, not so good.
 print Mum is in a %s mood % (mum_mood)
 print Dad is in a %s mood % (dad_mood)
 print Where does that leave us?


 dad_and_mum_mood(mum_mood, dad_mood)


 I am just trying to get get the information mum_mood and dad_mood from the
 argvs (written into the command line), but I get the error ImportError:
 cannot import name argvs.

The problem is exactly what the error message says.  argvs should
really be argv.

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


[Tutor] Help please!

2012-07-30 Thread Victoria Homsy
Hello all! I have a very simple question but I'm very new to python. Could you 
describe to me what the following piece of Python code says in English please? 

def print_a_line(line_count, f):
print line_count, f.readline()

I understand that line_count counts the number of lines in the Python prog, and 
that we are creating a function, and that 'f' stands for file etc, but I can't 
get my head around what the function does.

Many thanks in advance!

Best, 

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


Re: [Tutor] Help please!

2012-07-30 Thread Emile van Sebille

On 7/30/2012 12:52 PM Victoria Homsy said...

Hello all! I have a very simple question but I'm very new to python.
Could you describe to me what the following piece of Python code says in
English please?

def print_a_line(line_count, f):
print line_count, f.readline()



This function accepts two passed parameters, then prints the first, and 
reads and prints one line from the second.  Obviously, to work the first 
must be printable, and the second must provide a readline method.


*IF* you believe that the names selected accurately represent the intent 
of the function, you may come to the type of conclusions you reach below.


Emile





I understand that line_count counts the number of lines in the Python
prog, and that we are creating a function, and that 'f' stands for file
etc, but I can't get my head around what the function does.

Many thanks in advance!

Best,

Victoria



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


Re: [Tutor] Help please!

2012-07-30 Thread Prasad, Ramit
 Hello all! I have a very simple question but I'm very new to python. Could you
 describe to me what the following piece of Python code says in English
 please?

Welcome to the list and Python! When posting code in the future I recommend
posting in plain text and not rich text or HTML. If you are using
Yahoo! via web interface you can do this by the following link.
http://www.emailquestions.com/yahoo-mail/4446-switch-yahoo-mail-between-rich-text-plain-text.html


 
 def print_a_line(line_count, f):
   print line_count, f.readline()
 
 I understand that line_count counts the number of lines in the Python prog,
 and that we are creating a function, and that 'f' stands for file etc, but I
 can't get my head around what the function does.

line_count in this function can be anything. It is not actually
doing any counting or any work. All this function does is print whatever
information is in line_count (I assume it would be the current line number), 
then it retrieves exactly one line from the file f and then prints that
line.

Let us assume that the following multi-line string is what is contained in
file f. Some examples of what this function would print are shown below.

'''This is the first line. 
And this is the second line.
'''

 print_a_line(1, f )
1 This is the first line.
 print_a_line('line 2:', f )
line 2: And this is the second line.


Ramit

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help Please

2007-01-28 Thread Python Freak

Hi,

This may be too elementary for most of you, but could you please help me
with the following question? I would like to use comprehensive lists and
lists of lists. Where do I start?

Question:

Consider a digraph with 10 vertices, labeled 1 through 10. You are given the
following adjacency list representation, where we first list the vertices
adjacent to vertex 1, and so on.

1*; *2; 2*; *3; 3*; *4; 4*; *5; 5*; *6; 6*; *7; 7*; *8; 8*; *9; 9*; *10; 10.


a) Write code to turn the adjacency list into an incidence list and an an
adjacency matrix.

b) Write code to turn the incidence list into an adjacency matrix.

Hint: You may find it useful to note that one incidence list representation
is (1*; *1), (2*; *2), (3*; *3), (4*; *4), (5*; *5),(6*; *6), (7*; *7), (8*;
*8), (9*; *9), (10*; *10), (1*; *2), (2*; *3), (3*; *4), (4*; *5), (5*; *6),
(6*; *7), (7*; *8), (8*; *9), (9*; *10).
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Please

2007-01-28 Thread Danny Yoo


 This may be too elementary for most of you, but could you please help me
 with the following question?

This is almost certainly a homework problem.  We are very restricted in 
what we can do to help.  See:

 http://www.catb.org/~esr/faqs/smart-questions.html#homework


 I would like to use comprehensive lists and lists of lists. Where do I 
 start?


These are basic list manipulation concepts.  See any Python tutorial that 
talk about lists.  For example:

 http://www.ibiblio.org/obp/thinkCSpy/chap08.html


Other than refering you to tutorials, I don't think I can do much else 
here.  Good luck.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Please

2007-01-28 Thread Alan Gauld

Python Freak [EMAIL PROTECTED] wrote

 This may be too elementary for most of you, but could you please 
 help me
 with the following question? I would like to use comprehensive lists 
 and
 lists of lists. Where do I start?

Assuming you mean list comprehensions and lists of
lists then most web tutorials (including mine) should
include those topics

What exactly don you not understand? The more specific the question
the more specific will be the answer.


 Question:

 Consider a digraph with 10 vertices, labeled 1 through 10. You are 
 given the
 following adjacency list representation, where we first list the 
 vertices
 adjacent to vertex 1, and so on.

 1*; *2; 2*; *3; 3*; *4; 4*; *5; 5*; *6; 6*; *7; 7*; *8; 8*; *9; 9*; 
 *10; 10.

Thats pretty specific but looks like a homework.
We won't do your homework for you but we will help you with
specific bits if you get stuck. But you need to show us that
you are  making a fair attempt yourself.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help Please

2007-01-28 Thread Python Freak

Hi,

This may be too elementary for most of you, but could you please help me
with the following question? I would like to use comprehensive lists and
lists of lists. Where do I start?

Question:

Consider a digraph with 10 vertices, labeled 1 through 10. You are given the
following adjacency list representation, where we first list the vertices
adjacent to vertex 1, and so on.

1*; *2; 2*; *3; 3*; *4; 4*; *5; 5*; *6; 6*; *7; 7*; *8; 8*; *9; 9*; *10; 10.


a) Write code to turn the adjacency list into an incidence list and an an
adjacency matrix.

b) Write code to turn the incidence list into an adjacency matrix.

Hint: You may find it useful to note that one incidence list representation
is (1*; *1), (2*; *2), (3*; *3), (4*; *4), (5*; *5),(6*; *6), (7*; *7), (8*;
*8), (9*; *9), (10*; *10), (1*; *2), (2*; *3), (3*; *4), (4*; *5), (5*; *6),
(6*; *7), (7*; *8), (8*; *9), (9*; *10).
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help [Please use better subject lines than help!]

2005-03-13 Thread Danny Yoo


On Sun, 13 Mar 2005, R. Alan Monroe wrote:

  ok i have learned that on the python shell or new window you can
  type in..print hello world...and the output is ..'hello
  world'.. or you can put in anything realy and it say it back to
  you.is this a program or what

 Yep, that's a program. Just an ultra, ultra-simple one.

  how to write better programs

 Have you learnt the if statement yet? If not, that's the next thing
 you want to learn. Tell us if you get stuck.

[meta: mailing list admin stuff]

Hi Jeff,

And when you tell us, please make the subject line a little bit more
descriptive.  Your last two messages had subject lines like help! or
help me!.  We wouldn't be here if we didn't want to help.  *grin*

There's actually a very pratical reason why you should be more
descriptive: Your messages are actually not getting through directly to
the list because the mailing list software sees the naked word help! and
thinks that it's an administrative request!

Such messages get put on to a moderation queue that must be manually
curated by some poor, brain-dead mailing list administrator.  I would
laugh at that person, except that I am that brain-dead mailing list admin.
And I have to manually release messages that are caught in the moderation
queue from time to time, which sometime explains why it looks like it
takes a while for you messages to get to the list.

So if you can, please make my life easier: try to make your subject
headers more descriptive, like:

Is this a program?

A descriptive subject line should avoid manual moderation from the mailing
list software.


We're also trying to encourage good mailing list habits because all the
messages on the list are archived:

http://mail.python.org/pipermail/tutor/

and it is much easier for people to learn and find information from the
archives if messages have useful titles.


Best of wishes to you!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor