[Tutor] Tutor Digest, Vol 78, Issue 97

Nick nblack3 at student.gsu.edu
Sun Aug 22 01:06:52 CEST 2010


________________________________________
From: tutor-bounces+nblack3=student.gsu.edu at python.org [tutor-bounces+nblack3=student.gsu.edu at python.org] on behalf of tutor-request at python.org [tutor-request at python.org]
Sent: Saturday, August 21, 2010 1:25 PM
To: tutor at python.org
Subject: Tutor Digest, Vol 78, Issue 97

Send Tutor mailing list submissions to
        tutor at python.org

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

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

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


Today's Topics:

   1. Re: prime test problem (Evert Rol)
   2. Re: prime test problem (Steven D'Aprano)
   3. Re: prime test problem (Roelof Wobben)
   4. Re: Windows Power Shell (Bill Allen)
   5. Re: prime test problem (Evert Rol)


----------------------------------------------------------------------

Message: 1
Date: Sat, 21 Aug 2010 17:11:53 +0200
From: Evert Rol <evert.rol at gmail.com>
To: Roelof Wobben <rwobben at hotmail.com>
Cc: tutor at python.org
Subject: Re: [Tutor] prime test problem
Message-ID: <6732A98E-E155-41B4-9330-FF78DB90F900 at gmail.com>
Content-Type: text/plain; charset=us-ascii

> Hello,
>
> I know.
> I have read them all I believe but I can't see how I can convert the algebra to a working programm.

And if you just search Google for "Python prime number algorithm"? Perhaps it's cheating, so you'll have to try and fully understand the code first before you run it (be sure to read comments if there are any, eg the activatestate recipes; can have tons of useful extra info & links).
Generally, try to start with a program yourself, and then see where you get stuck. You could then post your stuck algorithm to the list and ask for advice; your current question is a bit too general, and thus harder to answer.

  Evert


>
> Roelof
>
>
> Date: Sat, 21 Aug 2010 19:15:03 +0530
> Subject: Re: [Tutor] prime test problem
> From: nitin.162 at gmail.com
> To: rwobben at hotmail.com
> CC: tutor at python.org
>
> For this problem u will get lots of solutions on the net.
> e.g wilson's theorem , sieve of eranthoses etc.
>
> --nitin
>
> On Sat, Aug 21, 2010 at 7:05 PM, Roelof Wobben <rwobben at hotmail.com> wrote:
> Hello,
>
> I have to make a programm which can test if a number is a prime.
> I know a prime is a number which can only be diveded by 1 and itself.
>
> One way is was thinking about is to make a loop which try if % has output 0.
> But that don't work.
>
> Can someone give me a hint what's the best approach is.
>
> Roelof
>


------------------------------

Message: 2
Date: Sun, 22 Aug 2010 02:49:26 +1000
From: Steven D'Aprano <steve at pearwood.info>
To: tutor at python.org
Subject: Re: [Tutor] prime test problem
Message-ID: <201008220249.27986.steve at pearwood.info>
Content-Type: text/plain;  charset="utf-8"

On Sun, 22 Aug 2010 12:41:03 am Roelof Wobben wrote:
> Hello,
>
> I know.
> I have read them all I believe

You've read all 64 million pages that Google finds? Wow, you must be a
fast reader! Well done!

> but I can't see how I can convert the
> algebra to a working programm.

Have you *tried*?

Perhaps you should try something a little bit less ambitious. Write a
program to test whether a number is divisible by 3. Then write a
program to test whether a number is divisible by 3 or 5. Then write a
third program to test whether a number is divisible by 3, 5 or 7.

Then generalise that third program.

Off you go. Come back when you have some code. Even if it isn't working
code, at least try something.



--
Steven D'Aprano

--------
My reply:  I may be formatting this wrong.  This is my first time posting to this list as I'm a relatively new subscriber.  I think I read the directions right in that it said don't top post, post under what you're responding to.  I'm sorry to anyone I offend if I got this wrong.

I was interested in this specific topic as I've been working some problems on project euler.  I've been stuck on a prime one more or less because I don't understand all the scripts I've been viewing (trying to learn how to approach it).  I get stuck in various areas specific to each one.  While that is general here is my real question.  

"Perhaps you should try something a little bit less ambitious. Write a
program to test whether a number is divisible by 3. Then write a
program to test whether a number is divisible by 3 or 5. Then write a
third program to test whether a number is divisible by 3, 5 or 7."

The very first problem for projecteuler.net makes you write a program that finds all factors of 3 and 5 for n < 1000.  Were they trying to lead me down the path you're alluding to?  I'm not seeing the connection between that particular problem and finding primes.  I would appreciate more insight.  Thanks everyone!  


------------------------------

Message: 3
Date: Sat, 21 Aug 2010 17:14:05 +0000
From: Roelof Wobben <rwobben at hotmail.com>
To: <tutor at python.org>
Subject: Re: [Tutor] prime test problem
Message-ID: <SNT118-W65B83BE62C37D10684C0D2AE800 at phx.gbl>
Content-Type: text/plain; charset="iso-8859-1"


Hello,



I tried it with this simple programm



def is_prime(n):
    x=2
    while x <= int(n**0.5)+1:
        if n % x == 0:
                return False

    x=x+1;
    return True

x=is_prime(7)
if x==True:
    print 7, "is een prime getal"
else :
    print 7, "is geen prime getal"





But this one gets in a indefinitive loop.



Roelof



> From: steve at pearwood.info
> To: tutor at python.org
> Date: Sun, 22 Aug 2010 02:49:26 +1000
> Subject: Re: [Tutor] prime test problem
>
> On Sun, 22 Aug 2010 12:41:03 am Roelof Wobben wrote:
> > Hello,
> >
> > I know.
> > I have read them all I believe
>
> You've read all 64 million pages that Google finds? Wow, you must be a
> fast reader! Well done!
>
> > but I can't see how I can convert the
> > algebra to a working programm.
>
> Have you *tried*?
>
> Perhaps you should try something a little bit less ambitious. Write a
> program to test whether a number is divisible by 3. Then write a
> program to test whether a number is divisible by 3 or 5. Then write a
> third program to test whether a number is divisible by 3, 5 or 7.
>
> Then generalise that third program.
>
> Off you go. Come back when you have some code. Even if it isn't working
> code, at least try something.
>
>
>
> --
> Steven D'Aprano
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100821/334000b2/attachment-0001.html>

------------------------------

Message: 4
Date: Sat, 21 Aug 2010 12:21:10 -0500
From: Bill Allen <wallenpb at gmail.com>
To: Alan Gauld <alan.gauld at btinternet.com>
Cc: tutor at python.org
Subject: Re: [Tutor] Windows Power Shell
Message-ID:
        <AANLkTimkg6UxYN=8Uvbgh+qNYV3mFrgt4+bd9zA8UYdE at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Alan,

I have used WPS 1.0 for some time at work to script software installs, etc.
It is very powerful and gives full .NET visibility to "DOS" level scripts.
In fact, it is a plausible replacement for VB for most administrative
scripting work in the Windows environment.

Some good resources:
The Hey Scripting Guy <http://blogs.technet.com/b/heyscriptingguy/>! Technet
blog is an execellent place to start as he focuses heavily on WPS.
PowerShell.com <http://powershell.com/cs/> WPS community (you can also sign
up for really good daily WPS tips sent straight to you email here, I
recommend these tips!)
TechNet Learning to Script
Center<http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx>,
focuses on WPS.


Bill




On Sat, Aug 21, 2010 at 3:20 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> A recent windows update delivered the Windows Power Shell to my desktop.
>
> I'd heard of this but never used it till now. I've only started playing
> with it but
> it is essentially DOS on steroids. It brings Windows users a shell that
> seems
> to be very close to Unix shells like Bash in power and flexibility (and
> scripting
> language). It's very early days yet, but I wondered if any other tutor
> members
> had started using WPS?
>
> Some examples of the extra features include regex,  objects, process
> control,
> remote invocation, better loop structures etc...
>
> Regards,
>
> Alan G.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100821/1172d8db/attachment-0001.html>

------------------------------

Message: 5
Date: Sat, 21 Aug 2010 19:24:51 +0200
From: Evert Rol <evert.rol at gmail.com>
To: Roelof Wobben <rwobben at hotmail.com>
Cc: tutor at python.org
Subject: Re: [Tutor] prime test problem
Message-ID: <89E5B3D1-3759-42E1-8E20-A3492545CA39 at gmail.com>
Content-Type: text/plain; charset=us-ascii

> Hello,
>
> I tried it with this simple programm
>
> def is_prime(n):
>     x=2
>     while x <= int(n**0.5)+1:
>         if n % x == 0:
>                 return False

If your while condition is True, you get into the loop.
Inside the loop, however, you never change anything that could change the condition (ie, neither x nor n get changed).
So the while condition stays the same, ie, True, and you loop indefinitely.


>     x=x+1;

Ah, but here you actually change something so that the while condition could become False. Sadly, this statement is outside the loop (hint hint).


>
>     return True
>
> x=is_prime(7)
> if x==True:
>     print 7, "is een prime getal"
> else :
>     print 7, "is geen prime getal"
>
>
> But this one gets in a indefinitive loop.

Try to mentally follow the logic of the loop.
Or use print statements and some small, easily checkable, numbers (prime and non-prime) to see what happens.
Print statements (functions, if you're on Python >= 3) are a simple, but at times extremely quick and useful way to debug scripts.

Ah yes, and either use "is een priemgetal" or "is a prime number", not a mix of both (sorry, couldn't help myself ;-).


  Evert



>
> Roelof
>
>
> > From: steve at pearwood.info
> > To: tutor at python.org
> > Date: Sun, 22 Aug 2010 02:49:26 +1000
> > Subject: Re: [Tutor] prime test problem
> >
> > On Sun, 22 Aug 2010 12:41:03 am Roelof Wobben wrote:
> > > Hello,
> > >
> > > I know.
> > > I have read them all I believe
> >
> > You've read all 64 million pages that Google finds? Wow, you must be a
> > fast reader! Well done!
> >
> > > but I can't see how I can convert the
> > > algebra to a working programm.
> >
> > Have you *tried*?
> >
> > Perhaps you should try something a little bit less ambitious. Write a
> > program to test whether a number is divisible by 3. Then write a
> > program to test whether a number is divisible by 3 or 5. Then write a
> > third program to test whether a number is divisible by 3, 5 or 7.
> >
> > Then generalise that third program.
> >
> > Off you go. Come back when you have some code. Even if it isn't working
> > code, at least try something.
> >
> >
> >
> > --
> > Steven D'Aprano
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



------------------------------

_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


End of Tutor Digest, Vol 78, Issue 97
*************************************


More information about the Tutor mailing list