________________________________________ From: tutor-bounces+nblack3=student.gsu....@python.org [tutor-bounces+nblack3=student.gsu....@python.org] on behalf of tutor-requ...@python.org [tutor-requ...@python.org] Sent: Saturday, August 21, 2010 1:25 PM To: tutor@python.org Subject: Tutor Digest, Vol 78, Issue 97
Send Tutor mailing list submissions to tutor@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-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. 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....@gmail.com> To: Roelof Wobben <rwob...@hotmail.com> Cc: tutor@python.org Subject: Re: [Tutor] prime test problem Message-ID: <6732a98e-e155-41b4-9330-ff78db90f...@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....@gmail.com > To: rwob...@hotmail.com > CC: tutor@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 <rwob...@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 <st...@pearwood.info> To: tutor@python.org Subject: Re: [Tutor] prime test problem Message-ID: <201008220249.27986.st...@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 <rwob...@hotmail.com> To: <tutor@python.org> Subject: Re: [Tutor] prime test problem Message-ID: <snt118-w65b83be62c37d10684c0d2ae...@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: st...@pearwood.info > To: tutor@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@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 <walle...@gmail.com> To: Alan Gauld <alan.ga...@btinternet.com> Cc: tutor@python.org Subject: Re: [Tutor] Windows Power Shell Message-ID: <aanlktimkg6uxyn=8uvbgh+qnyv3mfrgt4+bd9za8u...@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.ga...@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@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....@gmail.com> To: Roelof Wobben <rwob...@hotmail.com> Cc: tutor@python.org Subject: Re: [Tutor] prime test problem Message-ID: <89e5b3d1-3759-42e1-8e20-a3492545c...@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: st...@pearwood.info > > To: tutor@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@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 maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor End of Tutor Digest, Vol 78, Issue 97 ************************************* _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor