Re: [Tutor] How to plot amount of lines but the amount is a input

2015-12-30 Thread Joel Goldstick
On Wed, Dec 30, 2015 at 6:35 AM, Alan Gauld 
wrote:

> On 30/12/15 05:55, Tom Xu wrote:
> > Dear Pythoneers,
> >
> > I want to draw several curves in one graph, but the amount of curves is
> not
> > a fixed number.
>
> OK, But what exactly are you asking us to do?
>
> > My homework is below:
> > ---
> > import matplotlib.pyplot as plt
> > import math
> >
> > if __name__=='__main__':
> > try:
> > n=int(input('how many curves? '))
> > ulist=[]
> > thetalist=[]
> > for i in range(n):
> > ulist.append(float(input('Enter velocity: ')))
> > thetalist.append(float(input('Enter angle: ')))
> > except ValueError:
> > print('invalid input')
> > else:
> > generateFr(?)
>
> You need to put the call to generateFr inside a loop that
> iterates n times putting successive values from ulist and
> thetalist into the function.
>
> Also, put the function definitions above the place where you call them.
Normally, the if __name__ stuff should be below your function definitions

>
> > def generateFr(u, theta):
> > theta=math.radians(theta)
> > g=9.8
> >
> > tflight=2*u*math.sin(theta)/g
> > intervals=frange(0, tflight, 0.001)
> > x=[]
> > y=[]
> > for t in intervals:
> > x.append(u*math.cos(theta)*t)
> > y.append(u*math.sin(theta)*t - 0.5*g*t*t)
> > drawgraph(x, y)
> >
> > def frange(start, final, increment):
> > numbers=[]
> > while start > numbers.append(start)
> > start+=increment
> > return numbers
> >
> > def drawgraph(x, y):
> > plt.plot(x, y)
> > plt.xlabel('x-coordinate')
> > plt.ylabel('y-coordinate')
> > plt.title('Projectile motion')
>
>
>
> --
> 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
>



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


Re: [Tutor] How to plot amount of lines but the amount is a input

2015-12-30 Thread Alan Gauld
On 30/12/15 05:55, Tom Xu wrote:
> Dear Pythoneers,
> 
> I want to draw several curves in one graph, but the amount of curves is not
> a fixed number.

OK, But what exactly are you asking us to do?

> My homework is below:
> ---
> import matplotlib.pyplot as plt
> import math
> 
> if __name__=='__main__':
> try:
> n=int(input('how many curves? '))
> ulist=[]
> thetalist=[]
> for i in range(n):
> ulist.append(float(input('Enter velocity: ')))
> thetalist.append(float(input('Enter angle: ')))
> except ValueError:
> print('invalid input')
> else:
> generateFr(?)

You need to put the call to generateFr inside a loop that
iterates n times putting successive values from ulist and
thetalist into the function.


> def generateFr(u, theta):
> theta=math.radians(theta)
> g=9.8
> 
> tflight=2*u*math.sin(theta)/g
> intervals=frange(0, tflight, 0.001)
> x=[]
> y=[]
> for t in intervals:
> x.append(u*math.cos(theta)*t)
> y.append(u*math.sin(theta)*t - 0.5*g*t*t)
> drawgraph(x, y)
> 
> def frange(start, final, increment):
> numbers=[]
> while start numbers.append(start)
> start+=increment
> return numbers
> 
> def drawgraph(x, y):
> plt.plot(x, y)
> plt.xlabel('x-coordinate')
> plt.ylabel('y-coordinate')
> plt.title('Projectile motion')



-- 
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] trouble with beautiful soup

2015-12-30 Thread Alan Gauld
On 30/12/15 11:00, marcus lütolf wrote:
> Dear Pythonistas,
> o.K., thats what I get from the command line:
> 
> Microsoft Windows [Version 10.0.10586]
> (c) 2015 Microsoft Corporation. Alle Rechte vorbehalten.
> 
> C:\Users\marcus>c:\Python27\Scripts>dir pip*

OK, Thanks for the cut 'n paste that solves the mystery.

When you see

C:\some\path> somecommand

The bit up to the > is the OS prompt and you should NOT type that.
But it may tell you which folder you need to be in before you
do type it.

So, having seen the instruction above you would actually type

cd C:\some\path
somecommand

In your specific case you should type

cd C:\Python27\Scripts
dir pip*

Now try again and see if it works.

-- 
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] trouble with beautiful soup

2015-12-30 Thread marcus lütolf
Dear Pythonistas,
o.K., thats what I get from the command line:

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\marcus>c:\Python27\Scripts>dir pip*
Der Befehl "c:\Python27\Scripts" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

C:\Users\marcus>

As mentioned earlier, the error message is in german and says: The command 
"c:\Python27\Scripts" is either mistyped or could not be found.
With the cd command I get:

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\marcus>cd c:\Python27\Scripts> dir pip*
Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung 
ist falsch.

C:\Users\marcus>

The error message is also in german and says: The syntax for the filename, 
directory name or  drive name is wrong.
But if I use 2 steps I get:

C:\Users\marcus>cd c:\Python27\Scripts

c:\Python27\Scripts>dir pip*
 Datenträger in Laufwerk C: ist OS
 Volumeseriennummer: 4EE4-17CA

 Verzeichnis von c:\Python27\Scripts

25.12.2015  11:5798.124 pip.exe
25.12.2015  11:5798.124 pip2.7.exe
25.12.2015  11:5798.124 pip2.exe
   3 Datei(en),294.372 Bytes
   0 Verzeichnis(se), 411.226.550.272 Bytes frei

c:\Python27\Scripts>

How do I proceed from here ?
Thanks an regards, Marcus.

.
-Ursprüngliche Nachricht-
Von: Tutor [mailto:tutor-bounces+marcus.luetolf=bluewin...@python.org] Im 
Auftrag von Mark Lawrence
Gesendet: Montag, 28. Dezember 2015 20:23
An: tutor@python.org
Betreff: Re: [Tutor] trouble with beautiful soup

On 28/12/2015 17:24, marcus lütolf wrote:
> Dear Pythonistas
> Hi Danny,
>
> I am grateful for your precise instruchtions.
> Yes ideed, I tried all of the steps mentioned below which I shoudn't have 
> done fumling around with this task now  for hours and days.
> I even tried to do it on may laptop using W7 64bit and after deleting and 
> reinstalling Python27.
> The youtube video  I was referring to was : 
> https://www.youtube.com/watch?v=0snOcBQ3I0g.
>
> Now for pip: I found pip in C:\Python27\Lib\site-packages. But if I type in 
> pip or pip.exe I get (in german): The command "pip" is  either typed wrong or 
> could not be found (I can't cut and paste from the command window).
> As you might have noticed English is not my natural language and this can 
> lead sometimes to interpretation errors.
>
> Regards, Marcus.

c:\Python27\Scripts>dir pip*
  Volume in drive C has no label.
  Volume Serial Number is AE77-B408

  Directory of c:\Python27\Scripts

20/09/2015  20:2298,124 pip.exe
20/09/2015  20:2298,124 pip2.7.exe
20/09/2015  20:2298,124 pip2.exe
3 File(s)294,372 bytes
0 Dir(s)  869,655,580,672 bytes free

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


---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

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


Re: [Tutor] MemoryError

2015-12-30 Thread Alan Gauld
On 30/12/15 06:26, Satya Luzy wrote:
> Dear everyone, thank you for all of your support.
> To Alan :
> It is true that my code still need some improvement on the efficiency part,
> and thanks for pointing out which part that needs to be improved. 

My suggestions won't really do much for efficiency. They will
improve readability though. And that in turn makes it easier
to test/debug your code.

> By the way, did a little bit of searching, does my 64-bit Operating System
> has less performance because it is used for a 32-bit activity?

It may affect the amount of memory available.
Why not use 64 bit Python?

-- 
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] How to plot amount of lines but the amount is a input

2015-12-30 Thread Tom Xu
Dear Pythoneers,

sorry for bothering. I want to draw several curves in one graph, but the
amount of curves is not a fixed number.
My homework is below:
---
import matplotlib.pyplot as plt
import math

if __name__=='__main__':
try:
n=int(input('how many curves? '))
ulist=[]
thetalist=[]
for i in range(n):
ulist.append(float(input('Enter velocity: ')))
thetalist.append(float(input('Enter angle: ')))
except ValueError:
print('invalid input')
else:
*generateFr(?) # here I want to draw several curves with
ulist[0], thetalist[0], ulist[1], thetalist[1]... ... ulist[n-1],
thetalist[n-1]*

def generateFr(u, theta):
theta=math.radians(theta)
g=9.8

tflight=2*u*math.sin(theta)/g
intervals=frange(0, tflight, 0.001)

x=[]
y=[]
for t in intervals:
x.append(u*math.cos(theta)*t)
y.append(u*math.sin(theta)*t - 0.5*g*t*t)
drawgraph(x, y)

def frange(start, final, increment):
numbers=[]
while starthttps://mail.python.org/mailman/listinfo/tutor


[Tutor] How to plot amount of lines but the amount is a input

2015-12-30 Thread Tom Xu
Dear Pythoneers,

I want to draw several curves in one graph, but the amount of curves is not
a fixed number.
My homework is below:
---
import matplotlib.pyplot as plt
import math

if __name__=='__main__':
try:
n=int(input('how many curves? '))
ulist=[]
thetalist=[]
for i in range(n):
ulist.append(float(input('Enter velocity: ')))
thetalist.append(float(input('Enter angle: ')))
except ValueError:
print('invalid input')
else:
generateFr(?)

def generateFr(u, theta):
theta=math.radians(theta)
g=9.8

tflight=2*u*math.sin(theta)/g
intervals=frange(0, tflight, 0.001)

x=[]
y=[]
for t in intervals:
x.append(u*math.cos(theta)*t)
y.append(u*math.sin(theta)*t - 0.5*g*t*t)
drawgraph(x, y)

def frange(start, final, increment):
numbers=[]
while starthttps://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MemoryError

2015-12-30 Thread Satya Luzy
Thanks for testing out more of the program.
Yes, as you can see, I'm using the continued fraction method on n, which in
your case is 459.
During the continued fraction process (referring to function
cfract(n,boundary)), I set the boundary to store only 50 value of the first
iteration. The result of that function can be in a short pattern, just like
what you have seen:
[21, 2, 2, 1, 4, 21, 4, 1, 2, 2, 42,
  2, 2, 1, 4, 21, 4, 1, 2, 2, 42,
  2, 2, 1, 4, 21, 4, 1, 2, 2, 42,
  2, 2, 1, 4, 21, 4, 1, 2, 2, 42,
  2, 2, 1, 4, 21, 4, 1, 2, 2, 42]
In this case, the algorithm may get nothing or fail in this step because of
q (not Q) value. Thus, variable j is introduced.
When it comes to this, my code will move to faktorisasi function.
Fulfilling a mathematical rule where 459 = k.459 (mod n). The k is
multiplication, which is represented by j. Thus my program when it failed
on the first try, it will increase both the boundary and k or j until it
found the match. In faktorisasi_default function, it is creating one table
that consists of q,P,Q,A. The j variable is for the next table generation.

I will try more cases on my unfinished program.
Meanwhile, please bear with my amateurishness.
Thanks

On Wed, Dec 30, 2015 at 1:36 PM, Steven D'Aprano 
wrote:

> On Wed, Dec 30, 2015 at 12:00:02AM +0700, Satya Luzy wrote:
> > Hello,
> > I am currently working on a program to find the prime factor of n, in
> which
> > n is a big integer. Using the Continued Fraction factorization method (I
> > will provide the source code below, please don't mind the variables).
> [...]
>
> I have had a bit more time available to look at this, and I don't think
> your code is correct. I changed the value of n from 94152743499601547 to
> 18. Factorising 18 should give [2, 3, 3], but your code prints:
>
> 1
> 1
> 18
> 2
>
>
> before ending. I tried it again with n = 459, which should factorise
> to [3, 3, 3, 17], but your code prints:
>
> 1
> 1
> 1
> 1
> 1
> 1
> 1
> 1
> 1
> 1
> 18
> 18
> 459
> 9
>
> Then I added an extra line to the faktorisasi_default function, at the
> very end:
>
> print 'q =', q, 'p =', p, 'Q =', Q, 'A =', A
>
> and ran it again with n = 459 and got these results:
>
> q = [21, 2, 2, 1, 4, 21, 4, 1, 2, 2, 42,
>  2, 2, 1, 4, 21, 4, 1, 2, 2, 42,
>  2, 2, 1, 4, 21, 4, 1, 2, 2, 42,
>  2, 2, 1, 4, 21, 4, 1, 2, 2, 42,
>  2, 2, 1, 4, 21, 4, 1, 2, 2, 42]
> p = [0, 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21,
> 21, 15, 11, 15, 21]
> Q = [1, 18, 13, 26, 9, 2, 9, 26, 13, 18, 1,
> 18, 13, 26, 9, 2, 9, 26, 13, 18, 1,
> 18, 13, 26, 9, 2, 9, 26, 13, 18, 1,
> 18, 13, 26, 9, 2, 9, 26, 13, 18, 1,
> 18, 13, 26, 9, 2, 9, 26, 13, 18, 1]
> A = [0, 1, 21, 43, 107, 150, 248, 309, 107, 416, 21, 458,
> 438, 416, 352, 309, 211, 150, 352, 43, 438,
> 1, 21, 43, 107, 150, 248, 309, 107, 416, 21, 458,
> 438, 416, 352, 309, 211, 150, 352, 43, 438,
> 1, 21, 43, 107, 150, 248, 309, 107, 416, 21, 458]
>
> (reformatted to make them easier to read). So you can see the problem:
> to factorise a 3 digit number, you have recorded over 200 numbers.
> And the numbers have repeating patterns, as you can see above.
>
> I don't know if this is expected by the algorithm, or if you have made a
> programming error, but this looks very suspicious to me. At the very
> least, if you know that these repeating patterns are expected, there is
> no need to keep growing the lists and making them bigger and bigger, you
> can just build the pattern once.
>
>
>
> --
> Steve
> ___
> 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] MemoryError

2015-12-30 Thread Satya Luzy
Dear everyone, thank you for all of your support.
To Alan :
It is true that my code still need some improvement on the efficiency part,
and thanks for pointing out which part that needs to be improved. Speaking
of the nested loops, with my ability, I don't think I could simplify it, as
the nested loops is meant to look for a same value that occured twice or
more in the table (that's how the algorithm works, in my learning).
Really appreciate it :)

To Steven :
Well, I used a Laptop with i5 processor and 6GB of RAM in Windows 8 64-bit.
Wouldn't that be enough?
Either way, it is true that my method is not the best factorization method
nowadays. It was best used in the 70's. And I'm here to just do a research.
So it's not really surprising that it will not be that fast to have the
process done. I'm just having a problem because the process is interrupted
with MemoryError.

To Danny :
I'm sorry for the unfavored topic. Yeah I have understood the method and I
was just trying to convert it into code. By the way, I'm using the
references of (Mollin, Public Key Cryptography).

To Martin :
It is also true that I forgot to mention that the tested 10-digit numbers
are the non-prime numbers (Yeah, seems like I will have to add a primality
test before running the factorization). I was just too desperate to use the
global variable (lol). Yeah, I will try my best to avoid using it in the
future time. In my codes, the output of having 4 or more lines are to be
expected, for the first two lines are value of Q that is being compared due
to the same value and take the value associated with Q, which is A. Q is
printed and A is not. Then the last 2 lines are the actual factor. Thank
you for improving my code.


By the way, did a little bit of searching, does my 64-bit Operating System
has less performance because it is used for a 32-bit activity?

Really glad to have this community.
Have a good day!


On Wed, Dec 30, 2015 at 9:29 AM, Martin A. Brown 
wrote:

>
> Hello there Satya,
>
> >I am currently working on a program to find the prime factor of n, in
> which
> >n is a big integer. Using the Continued Fraction factorization method (I
> >will provide the source code below, please don't mind the variables).
>
> I do not know the Continued Fraction factorization method.  (I admit
> to not looking it up and simply examining your code.)
>
> >It works perfectly when factorizing below 10 digits numbers.
>
> Are you certain?  All 10 digit numbers?  Or just the 10 digit
> numbers you tried?  I ask because  Well, please see my second
> point below.
>
> >In my code below you will see on how I tried to factorize
> >94152743499601547, but get this message instead :
>
> Alan, Steven and Danny have other useful comments.  I will not
> repeat those.
>
> You may find it a bit easier to diagnose which data structure is
> exploding in size by logging/printing the contents of the lists p, Q
> and A, which you maintain in the function faktorisasi_default().
>
> I made a few small modifications to your code (see below) so that I
> could run it on smaller numbers.  Here are some comments:
>
>   * I adjusted the variables accepted in faktorisasi_default so that
> there is no need for using a 'global' variable.  I don't like
> using globals if it is possible to avoid.  In pure mathematical
> functions, it is usually possible to avoid using a global.  If
> you need an intermediate work product from the function (in
> addition to the result), then simply return the intermediate
> work product along with the result.
>
>   * See below my (slight) modifications to your code.  Now, you can
> see how I'm running the program to perform some more diagnosis.
> I think you have some sort of recursion termination problem in
> your functions which are implementing your factoring.  In
> short, determining I don't think that faktorisasi_default knows
> when to stop.  Here's how I drew this conclusion:
>
>   python wuzzyluzy.py 18  # -- stops with four lines of output
>   python wuzzyluzy.py 12275   # -- stops with four lines of output
>   python wuzzyluzy.py 262144  # -- stops with many lines of output
>   python wuzzyluzy.py 17  # -- never stops
>   python wuzzyluzy.py 19  # -- never stops
>
> Good luck in your hunt for the wily factors,
>
> -Martin
>
>
>
> import fractions
> import math
>
> # CFRAC
> def cfract(n, boundary):
>coeff = 1
>floor_part = floor_ = math.floor(math.sqrt(n))
>denom = n - floor_part ** 2
>result = []
>result.append(int(floor_))
>
>if float(denom)!=0:
>   for i in range(boundary-1):
>  try:
> floor_ = math.floor((math.sqrt(n) + floor_part) / float(denom))
>  except ZeroDivisionError: # perfect square
> return result
>
>  if denom != 1:
> result.append(int(floor_))
>  floor_part = denom * floor_ - floor_part
>  coeff = denom
>  denom = n - floor_part