[Tutor] QUESTION

2017-03-04 Thread Tasha Burman
Hello python tutors, 
I am having difficulty with a power function; what is another way I can do 4**9 
without using **?
Thanks, 
Tasha 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] QUESTION

2017-03-04 Thread Alan Gauld via Tutor
On 04/03/17 01:37, Tasha Burman wrote:
> I am having difficulty with a power function; 
> what is another way I can do 4**9 without using **?

You can use the pow() function.

answer = pow(4,9)

However, I'm not sure that really answers your question?
Do you mean that you want to write your own power()
function and want help with that? If so ask again with
a more specific description of your problem.

-- 
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] Calculate 4**9 without using **, was Re: QUESTION

2017-03-04 Thread Peter Otten
Tasha Burman wrote:

> Hello python tutors,
> I am having difficulty with a power function; what is another way I can do
> 4**9 without using **? Thanks,

Hello Tasha,

"what is another way I can do 4**9 without using **?"

sounds a lot like a homework question -- so you really have to think about 
it yourself a bit. A few hints:

How would you do the calculation with pen and paper?

Can you translate that into a Python loop? What kind of loop would you 
choose to repeat something 9 times?

If you are still having difficulties come back here and show us the code you 
have tried, even if it doesn't work yet.

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


Re: [Tutor] Calculate 4**9 without using **, was Re: QUESTION

2017-03-04 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
Much simpler is

4*4*4*4*4*4*4*4*4

regards,
Sarma.

On Sat, Mar 4, 2017 at 2:20 PM, Peter Otten <__pete...@web.de> wrote:

> Tasha Burman wrote:
>
> > Hello python tutors,
> > I am having difficulty with a power function; what is another way I can
> do
> > 4**9 without using **? Thanks,
>
> Hello Tasha,
>
> "what is another way I can do 4**9 without using **?"
>
> sounds a lot like a homework question -- so you really have to think about
> it yourself a bit. A few hints:
>
> How would you do the calculation with pen and paper?
>
> Can you translate that into a Python loop? What kind of loop would you
> choose to repeat something 9 times?
>
> If you are still having difficulties come back here and show us the code
> you
> have tried, even if it doesn't work yet.
>
> ___
> 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] Calculate 4**9 without using **, was Re: QUESTION

2017-03-04 Thread Peter Otten
D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
> On Sat, Mar 4, 2017 at 2:20 PM, Peter Otten <__pete...@web.de> wrote:

>> "what is another way I can do 4**9 without using **?"
>>
>> sounds a lot like a homework question -- so you really have to think
>> about it yourself a bit. A few hints:
>>
>> How would you do the calculation with pen and paper?
>>
>> Can you translate that into a Python loop? What kind of loop would you
>> choose to repeat something 9 times?

> Much simpler is
> 
> 4*4*4*4*4*4*4*4*4

The idea behind the approach I suggested is to lead towards some level of 
abstraction. The for-loop can be put into a function, the exponent be given 
by the user at runtime etc...

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


Re: [Tutor] Calculate 4**9 without using **

2017-03-04 Thread Sri Kavi
Hi,


I'm a beginner learning to program with Python. I'm trying to explain a
solution in plain English. Please correct me if I'm wrong.


Create a function that takes base and exponent as arguments.



In the body of the function:

set a result variable to the base.



User a for-loop with a range of 1 to the exponent.

With each iteration, set the result to the product of result times base.



After the loop, return the result.



Call the function.





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


Re: [Tutor] Problems with matplotlib

2017-03-04 Thread Pooja Bhalode
I had a similar issue when I tried to download matplotlib in my python
directory. I think what Peter suggested is correct, if you remove the new
file it would work for you. I had the same issue with copy.py file.

Hope that helps.



On Sat, Mar 4, 2017 at 2:30 AM, Peter Otten <__pete...@web.de> wrote:

> Jason Snyder wrote:
>
> > I installed the python module matplotlib on a computer and when I try to
> > run a program with the commands:
> >
> > import matplotlib.pyplot as plt I get the following errors:
> >
> > Traceback (most recent call last):
> >   File "new.py", line 1, in 
> > import matplotlib
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line
> > 151, in 
> > from matplotlib.rcsetup import (defaultParams,
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/rcsetup.py", line
> >   20,
> > in 
> > from matplotlib.colors import is_color_like
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/colors.py", line
> 54,
> > in 
> > import matplotlib.cbook as cbook
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/cbook.py", line
> 32,
> > in 
> > import new
> >   File "/home/www/html/auroratest/new.py", line 8, in 
> > plt.scatter(x,y)
> > NameError: name 'plt' is not defined
> >
> > when I try to use something like import matplotlib.image as image I get
> > the following errors:
> >
> > Traceback (most recent call last):
> >   File "new.py", line 1, in 
> > import matplotlib.image as image
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line
> > 151, in 
> > from matplotlib.rcsetup import (defaultParams,
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/rcsetup.py", line
> >   20,
> > in 
> > from matplotlib.colors import is_color_like
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/colors.py", line
> 54,
> > in 
> > import matplotlib.cbook as cbook
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/cbook.py", line
> 32,
> > in 
> > import new
>
> This looks like a name clash. There is a module called "new" in Python's
> standard library, and matplotlib is trying to install that. Instead your
> own
>
> >   File "/home/www/html/auroratest/new.py", line 1, in 
>
> is found. Once you rename your new.py to something else (and remove the
> corresponding new.pyc) things should start to work again.
>
> > import matplotlib.image as image
> >   File "/usr/lib64/python2.7/site-packages/matplotlib/image.py", line
> 13,
> > in 
> > from matplotlib import rcParams
> > ImportError: cannot import name rcParams
> >
> > What is causing these errors and what specific things do I need to do to
> > resolve this.  I need this explained clearly in a step by step way.
> >
> > Thanks,
> >
> > Jason
> >
>
>
> ___
> 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] Calculate 4**9 without using **

2017-03-04 Thread Alan Gauld via Tutor
On 04/03/17 16:17, Sri Kavi wrote:

> I'm a beginner learning to program with Python. I'm trying to explain a
> solution in plain English. Please correct me if I'm wrong.

See the thread earlier today with the subject QUESTION for
more on this topic.

> Create a function that takes base and exponent as arguments.
> 
> In the body of the function:
> 
> set a result variable to the base.
> Use a for-loop with a range of 1 to the exponent.
> With each iteration, set the result to the product of result times base.
> After the loop, return the result.

Is there anything there that you don't know how to do?
If not have a go and if it does not work come back to us
with your code and any error messages.


-- 
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] Calculate 4**9 without using **

2017-03-04 Thread Whom Isac
Hi there. So if you want to make a function for exponent (e^x)  rather than 
power such as x**n, then you need to use/import pythons math module such as 
Numpy. 

Use: 
import numpy as np
List = [1,2,3,4,5]
np.exp(list) 

This would give exponential value of each x in the list.

If you want to just power by a certain base then use:

def powerBase(base,n):
  return base**n

Example print(powerBase(2,3)) should give you 8.

That should also do that for you.

On Mar 5, 2017, 3:37 AM, at 3:37 AM, Sri Kavi  wrote:
>Hi,
>
>
>I'm a beginner learning to program with Python. I'm trying to explain a
>solution in plain English. Please correct me if I'm wrong.
>
>
>Create a function that takes base and exponent as arguments.
>
>
>
>In the body of the function:
>
>set a result variable to the base.
>
>
>
>User a for-loop with a range of 1 to the exponent.
>
>With each iteration, set the result to the product of result times
>base.
>
>
>
>After the loop, return the result.
>
>
>
>Call the function.
>
>
>
>
>
>Regards
>Sri
>___
>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] Calculate 4**9 without using **

2017-03-04 Thread Alex Kleider

On 2017-03-04 08:17, Sri Kavi wrote:


I'm a beginner learning to program with Python. I'm trying to explain a
solution in plain English. Please correct me if I'm wrong.



Create a function that takes base and exponent as arguments.


Is seems that you are facing the same problem as Tasha Burman.
Sounds like an assignment meant to exercise your use of iteration.
i.e. ** and various built in power functions that have been suggested 
are out of bounds.



In the body of the function:
set a result variable to the base.


def pwr(base, exponent):

res = base
...

User a for-loop with a range of 1 to the exponent.


for i in range(begin, end):  # The challenge is to pick begin and 
end.


end will be a function of exponent but not exponent itself.
I don't think 1 is a good choice for begin.
Picking the correct begin is related to dealing with the following:

What if any of the following are true, and what should be done in each 
case?

if exponent ==1: .
if exponent = 0: .
if exponent < 0: .
Each of the first two might deserve its own return statement.



With each iteration, set the result to the product of result times 
base.


res *= base  # same as res = res * base


It's a fun little exercise- a bit more complex than I initially thought 
it would be.


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


Re: [Tutor] Calculate 4**9 without using **

2017-03-04 Thread Steven D'Aprano
On Sat, Mar 04, 2017 at 06:07:23PM -0800, Alex Kleider wrote:
> On 2017-03-04 08:17, Sri Kavi wrote:
> 
> >I'm a beginner learning to program with Python. I'm trying to explain a
> >solution in plain English. Please correct me if I'm wrong.
> 
> >Create a function that takes base and exponent as arguments.
> 
> Is seems that you are facing the same problem as Tasha Burman.


I think you are misunderstanding Sri Kavi's answer. I think that Sri is 
trying to answer Tasha's question without providing actual working code. 
This is homework, and Tasha should write the code herself. But Sri has 
given a description of the algorithm to use.


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