[Tutor] Require help for a script

2017-09-19 Thread Clara Chua
Hi Python tutor, I require help for a script that asks user for number of
rows, r and number of columns c, and generates a r x c matrix with the
following values:

- The value of each element in the first row is the number of the column
- The value of each element in the first column is the number of the row
- The rest of the elements each has a value equal to the sum of the element
above it and the element to the left.

Example of such matrix if a user inputs r=4 and c=5

12 3 4 5
24 711   16
3714   25   41
4   1125   50   91

We were told to use the for loops as well as numpy for this.
Thank you in advance!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Require help for a script

2017-09-19 Thread Alan Gauld via Tutor
On 19/09/17 08:48, Clara Chua wrote:
> Hi Python tutor, I require help for a script that asks user for number of
> rows, r and number of columns c, and generates a r x c matrix with the
> following values:

What help do you need?
Which part of the above do you not know how to do?

Can you ask the user for two numbers and store them
in two variables?

It says generate a matrix, I'm guessing that's
where the numpy stuff comes in although a standard
Python list would be just as effective in this case.
In either case can you define a new two dimensional
data structure using the sizes read previously?

> - The value of each element in the first row is the number of the column

Do you know how to populate the first row?

> - The value of each element in the first column is the number of the row

Do you know how to populate the first column (or first
element of each row)?

> - The rest of the elements each has a value equal to the sum of the element
> above it and the element to the left.

Do you know how to iterate over each cell in your matrix,
starting with the second row?

For a given cell do you know how to read the value above?
For a given cell do you know how to read the value left?

Do you know how to sum two values and store the result
in the current cell?

> Example of such matrix if a user inputs r=4 and c=5
> 
> 12 3 4 5
> 24 711   16
...

Tell us which part of the problem you are stuck with.
Show us the code you have tried and any error
messages (in full). Then we can give you more focused
help.

-- 
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] Require help for a script

2017-09-19 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
First fill the first row and first column of the matrix with seperate loops.
Then the rest of the elements of the matrix can be filled with nested loops.
regards,
Sarma.


On Tue, Sep 19, 2017 at 1:18 PM, Clara Chua  wrote:
> Hi Python tutor, I require help for a script that asks user for number of
> rows, r and number of columns c, and generates a r x c matrix with the
> following values:
>
> - The value of each element in the first row is the number of the column
> - The value of each element in the first column is the number of the row
> - The rest of the elements each has a value equal to the sum of the element
> above it and the element to the left.
>
> Example of such matrix if a user inputs r=4 and c=5
>
> 12 3 4 5
> 24 711   16
> 3714   25   41
> 4   1125   50   91
>
> We were told to use the for loops as well as numpy for this.
> Thank you in advance!
> ___
> 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] (no subject)

2017-09-19 Thread C
Hi Python tutor, I require help for a script that asks user for number of
rows, r and number of columns c, and generates a r x c matrix with the
following values:

- The value of each element in the first row is the number of the column
- The value of each element in the first column is the number of the row
- The rest of the elements each has a value equal to the sum of the element
above it and the element to the left.

Example of such matrix if a user inputs r=4 and c=5

12 3 4 5
24 711   16
3714   25   41
4   1125   50   91

For now I only filled up the first row and first columns.

We were told to use the for loops as well as numpy for this. However, I
cannot quite figure out how I can use loops to do this. Please help!

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


Re: [Tutor] Tutor Digest, Vol 163, Issue 28

2017-09-19 Thread Saahndong Ransom
What are the uses of python?
What are easy way to learn python?

On Sep 19, 2017 15:07,  wrote:

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
https://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@python.org

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

Today's Topics:

   1. pip install of subprocess module (Derek Smith)
   2. Re: pip install of subprocess module (Alan Gauld)
   3. Require help for a script (Clara Chua)
   4. Re: Require help for a script (Alan Gauld)
   5. Re: Require help for a script (D.V.N.Sarma ??.??.???.)


-- Forwarded message --
From: Derek Smith 
To: "tutor@python.org" 
Cc:
Bcc:
Date: Mon, 18 Sep 2017 17:59:39 +
Subject: [Tutor] pip install of subprocess module
Hi All,

Thank for the recent replies.  I want to use the subprocess.run module b/c
per the docs os.system is antiquated and cannot use  more than 1 arg in 3.6.
Why am I doing wrong below?  Also couldn't I just copy and paste the
subprocess code from github and create a file, but then how do I tell
python this is a new module called os.system since this py file requires
os.system and os.spawn*
I am on AIX 7.1, python 3.6.2, pip 9.0.1

Thx agn!

# pip install git+https://github.com/python/cpython/blob/3.6/Lib/
subprocess.py -vvv
Collecting git+https://github.com/python/cpython/blob/3.6/Lib/subprocess.py
  Cloning https://github.com/python/cpython/blob/3.6/Lib/subprocess.py to
/tmp/pip-bw8rryo9-build
  Running command git clone -q https://github.com/python/
cpython/blob/3.6/Lib/subprocess.py /tmp/pip-bw8rryo9-build
remote: Not Found
fatal: repository 'https://github.com/python/cpython/blob/3.6/Lib/
subprocess.py/' not found
Cleaning up...
Command "git clone -q https://github.com/python/cpython/blob/3.6/Lib/
subprocess.py /tmp/pip-bw8rryo9-build" failed with error code 128 in None
Exception information:
Traceback (most recent call last):
  File "/opt/freeware/lib/python3.6/site-packages/pip/basecommand.py", line
215, in main
status = self.run(options, args)
  File "/opt/freeware/lib/python3.6/site-packages/pip/commands/install.py",
line 335, in run
wb.build(autobuilding=True)
  File "/opt/freeware/lib/python3.6/site-packages/pip/wheel.py", line 749,
in build
self.requirement_set.prepare_files(self.finder)
  File "/opt/freeware/lib/python3.6/site-packages/pip/req/req_set.py", line
380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
  File "/opt/freeware/lib/python3.6/site-packages/pip/req/req_set.py", line
620, in _prepare_file
session=self.session, hashes=hashes)
  File "/opt/freeware/lib/python3.6/site-packages/pip/download.py", line
805, in unpack_url
unpack_vcs_link(link, location)
  File "/opt/freeware/lib/python3.6/site-packages/pip/download.py", line
479, in unpack_vcs_link
vcs_backend.unpack(location)
  File "/opt/freeware/lib/python3.6/site-packages/pip/vcs/__init__.py",
line 286, in unpack
self.obtain(location)
  File "/opt/freeware/lib/python3.6/site-packages/pip/vcs/git.py", line
142, in obtain
self.run_command(['clone', '-q', url, dest])
  File "/opt/freeware/lib/python3.6/site-packages/pip/vcs/__init__.py",
line 325, in run_command
spinner)
  File "/opt/freeware/lib/python3.6/site-packages/pip/utils/__init__.py",
line 707, in call_subprocess
% (command_desc, proc.returncode, cwd))
pip.exceptions.InstallationError: Command "git clone -q
https://github.com/python/cpython/blob/3.6/Lib/subprocess.py
/tmp/pip-bw8rryo9-build" failed with error code 128 in None



Derek Smith  |  Unix/TSM Administrator  | Racksquared Data Centers
::  dereksm...@racksquared.com  *: www.racksquared.com |  www.racksquared.jobs

[cid:image003.png@01D2E9AA.1B9CF8F0]




-- Forwarded message --
From: Alan Gauld 
To: tutor@python.org
Cc:
Bcc:
Date: Mon, 18 Sep 2017 23:24:31 +0100
Subject: Re: [Tutor] pip install of subprocess module
On 18/09/17 18:59, Derek Smith wrote:

> I want to use the subprocess.run module b/c per the> docs os.system is
antiquated

Its not so much antiquated but it is deprecated because
it is severely limited, all you get back is an error code.

> Why am I doing wrong below?

You are trying to install it, but subprocess is part
of the standard library, it should already be installoed.

Just use the >>> prompt and try

>>> import subprocess

If you don't get an error then its already there.

> python this is a new module called os.system

subprocess is its own moduile it is not part of os.

import os
import subprocess

> since this py file requires os.system and os.spawn*

Both of those can be replaced by calls within
subprocess but  they will not be called by
those names. Read the subprocess modu

Re: [Tutor] (no subject)

2017-09-19 Thread Alan Gauld via Tutor
On 19/09/17 15:11, C wrote:
> Hi Python tutor, I require help for a script that asks user for number of
> rows, r and number of columns c, and generates a r x c matrix with the
> following values:

You already posted this in another thread, please do not multi-post it
just clutters up the archive and splits the discussion. you already have
replies on the original post.

-- 
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] Tutor Digest, Vol 163, Issue 28

2017-09-19 Thread Alan Gauld via Tutor
On 19/09/17 15:45, Saahndong Ransom wrote:
> What are the uses of python?
> What are easy way to learn python?

Python is a general purpose programming language
that can be used to build many kinds of software
applications from computer administration to web
servers to desktop GUI applications.

The Python wiki is the bet place to start, it
provides many different tutorials depending on
your level of existing knowledge about programming.

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

If you are a complete beginner you might like my
tutorial, linked 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


[Tutor] Need Help with install of Python!

2017-09-19 Thread Larry Staley
Hello I am very new to Python just having installed Python Version 2.7 onto
my windows 8.1 laptop.  I thought the install was successful and was
entering information for my first assignment when I received an unexpected
error.

 

I executed a Sheets command using an earlier generated getSheetNames
function that successfully was entered by me.

However, when I ran the Sheets command I received the following:

 

Import Error:  No modules name Pandas

 

If Pandas were not included in the original install, would it not have been
caught when I input the getSheetNames function:

 

def getSheetNames(excelfile):

from pandas import ExcelFile

return (ExcelFile(excelfile)).sheet_names

Here again was my command:

 

>>> excelfile=r:"C:\Users\Larry

>>> sheets=getSheetNames

(excelfile);sheets

Traceback (most recent call last):

  File "", line 1, in 

  File "", line 2, in 

getSheetNames

ImportError: No module named pandas

>>> 

 

I have in addition included the actual Python I executed and received the
message.  It is attached in the file.

I would appreciate any help in getting this issue resolved.

If I need to install Pandas, please indicate clearly how I do using my
current ver 2.7 python install.

 

Thanks again for your help.

 

Larry  Staley

 

650.274.6794 (c)

larrystale...@comcast.net

 

 

 

>>> def getSheetNames(excelfile):
... from pandas import ExcelFile
... return (ExcelFile(excelfile)).sheet_names
...
>>> excelfile=r"D:\Assignment_1_Data_and_Template.xlsx";
>>> sheets=getSheetNames(excelfile);sheets
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in getSheetNames
ImportError: No module named pandas
>>> excelfile="D:\Assignment_1_Data_and_Template.xlsx";
>>> sheets=getSheetNames(excelfile);sheets
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in getSheetNames
ImportError: No module named pandas
>>> excelfile=r"D:\Assignment_1_Data_and_Template.xlsx";
>>> excelfile=r:"C:\Users\Larry\Assignment_1_Data_and_Template.xlsx"
  File "", line 1
excelfile=r:"C:\Users\Larry\Assignment_1_Data_and_Template.xlsx"
   ^
SyntaxError: invalid syntax
>>> excelfile=r"C:\Users\Larry\Assignment_1_Data_and_Template.xlsx";
>>> sheets=getSheetNames(excelfile);sheets
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in getSheetNames
ImportError: No module named pandas
>>>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need Help with install of Python!

2017-09-19 Thread Alan Gauld via Tutor
On 19/09/17 21:13, Larry Staley wrote:
> Hello I am very new to Python just having installed Python Version 2.7 onto
> my windows 8.1 laptop.  I thought the install was successful and was
> entering information for my first assignment when I received an unexpected
> error.

Where did you get your vesion of Python?
If it was the standard distribution from python.org or
activestate.com then it does not include any of the SciPy
packages(*) and you need to install them separately.

If you expect to be using mamny of these types of package
you are best fetching a distribution  that includes them
all, for example, Anaconda or Enthought

(*)Pandas is part of the SciPy suite of third party add-ons.

> I executed a Sheets command using an earlier generated getSheetNames
> function that successfully was entered by me.

When you define a function the code inside is not
executed merely compiled into a function object
ready for execution.

> However, when I ran the Sheets command I received the following:

Its only when you call the function that the code inside
gets executed.

> def getSheetNames(excelfile):
> from pandas import ExcelFile

Its normal in Python to put all imports at the top of
the file rather than inside any functions. In this
case you try to import pandas everytime you call
the function and while its not a big overhead it
mounts up if you were calling this inside a
repeating loop.

And if the import was outside the function you would
pick up the import error earlier.

 excelfile=r:"C:\Users\Larry
 sheets=getSheetNames
> (excelfile);sheets

I'm not sure what you are doing with that
final ;sheets. I assuyme trying to evaluate the result of the function?

It would be normal to just print it:

>>> print getSheetNames(excelFile)

or, if you need to store the result:

>>> sheets=getSheetNames(excelfile)
>>> sheets

Combining commands on a single line doesn't save
much typing and makes debugging harder.

> I have in addition included the actual Python I executed and received the
> message.  It is attached in the file.

attachments often get rejected by the mailer,
if its not a huge file(>100 lines) just paste
it into the email.

Always include the full error trace too.

> If I need to install Pandas, please indicate clearly how I do using my
> current ver 2.7 python install.

The easiest way is just to grab one of the
all-inclusive Python distros mentioned 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