![]() |
|
Re: ** Python Support Thread **
This woud seem more elegant. I had to use a while loop rather than a for loop, because I kept getting errors that the number was too big when I called isfact with the proper argument.
Spoiler:
Still taking forever to brute force that number. 30 mins and counting..... |
Re: ** Python Support Thread **
Uh oh - 6.5 hours later and my code is still running. The last time the code found a prime factor was probably over 4 hours ago, and while it's up into 10 digit numbers now I'd be surprised if it was legitimately taking this long to compute. I'm starting to suspect I may have hit an infinite loop. Could anybody tell from looking at the code in my previous post (or the one before it which prints every prime factor it encounters) where I am likely to have run into problems?
|
Re: ** Python Support Thread **
edit: disregard what this post used to say. I think your code is correct, but it will take a long time. Definitely you should start your prime-finding mission from the bottom instead of the top.
Spoiler:
|
Re: ** Python Support Thread **
I just came back to post that I think my code sucks balls. I got really exasperated after 7hrs and checked Wolfram for the answer. It turns out I got the correct answer a few seconds into my search, but then for some reason it kept on iterating and generating larger numbers which turned out not to be primes. Back to the drawing board for me, after I read up a little on prime sieves. My math let me down pretty hard here!
Roundtower, re: your spoiler I had 2 algos running - one that started from 1, and one that started from the end. The second never produced anything, the first got the answer but then kept on going (code is in post 250)! |
Re: ** Python Support Thread **
ok. a good way to check if you have got the answer would be to multiply all of the primes found already, and see if you have the answer.
|
Re: ** Python Support Thread **
Wow, thanks. I had no idea you could check that way. I really should have paid more attention in Math class.....
|
Re: ** Python Support Thread **
This code gets the answers immediately, which is what I started my 2nd attempt off with, but then it keeps on running, and running, so I scrapped it thinking it was faulty. It works (in that it instantly returns the prime factors), I just don't understand why it doesn't stop.
Code:
I think I've found out what I was doing wrong - I just don't quite understand why yet. The problem was in the way I set up the while loop in isfact(). As sooon as I re-write that function the way I've set out below, the program runs and completes in < 1 sec: Code:
def isfact(arg): |
Re: ** Python Support Thread **
Quote:
The only change I would make is to get rid of the loop counter: Code:
def isfact(arg): |
Re: ** Python Support Thread **
Quote:
Instead of : Code:
if my_test(x) == True:Code:
if my_test(x):Code:
def isfact(arg): |
Re: ** Python Support Thread **
Hmm. Cool thanks for the true/false tip. Why is that bad form? (I'm only an amateur programmer obv)
Regarding the two if statements: If I combine them into one statement won't isprime(loop) execute for every 'loop' in range(...)? My thinking was that I could save time by nesting the two statements. But, I just checked and for this example there is no noticeable time difference. |
Re: ** Python Support Thread **
Quote:
FYI there is a Project Euler thread in this forum |
Re: ** Python Support Thread **
Quote:
This also works in similar manner for or statements. In the following block: Code:
for x in range(10):Here's an example that makes it a bit more clear: Code:
Code:
true and test never called |
Re: ** Python Support Thread **
Cool. Thanks for the explanation.
|
Re: ** Python Support Thread **
We have directories that end up with thousands of files in them, so many that ls times out. This makes it very difficult to look for a particular file in the directory and I'm going to write a little ditty to clean that up. What I'd like to avoid doing is writing something that causes more harm than good, so instead of just getting a glob that grabs all of the files in the directory and tries to work with them one after the other I'd rather limit the number of files I slurp and run the process multiple times (or run multiple slurps). Will glob.iglob(path) do that?
|
Re: ** Python Support Thread **
Re: the Windows IDE talk some pages back, I just discovered this:
http://****************/projects/pywin32/ |
Re: ** Python Support Thread **
Pywin32 is great. I'm using it pretty extensively at work to read data from Excel sheets and automate a whole bunch of stuff that would have been a huge PITA using VBA.
|
Re: ** Python Support Thread **
we use pywin32 at work to manage Windows services.
|
Re: ** Python Support Thread **
not much info on that page suggesting what it does? presumably python bindings for the entire Win32 API? but also COM (from the excel use above)?
|
Re: ** Python Support Thread **
I am learning python but I'm using 2.5.4 because the literature i have on it is old. Here is my question: Where is my syntax error stemming from it looks like it wants me to correct the 5 in 2.5.4, it doesn't point to any other errors. Here is my code, and tell me if it works or not because there's no teacher to grade me. The program is meant to ask you your last name then ask you your first, then print them out in first name to last name in that order.
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. ************************************************** ************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. ************************************************** ************** IDLE 1.2.4 >>> question1 = "What is your last name?" >>> print question1 What is your last name? >>> answer1 = raw_input() >>> question2 = "What is your first name?" >>> print question2 What is your first name? >>> answer2 = raw_input() >>> print answer2 >>> print answer1 >>> |
Re: ** Python Support Thread **
I'm a programming noob too, but syntactically it seems fine to me. The one thing I would say is that you can probably halve your variables by forgoing the assignment of the "question" variables, and doing away with printing the prompts like this:
Code:
lastName = raw_input("What is your last name? :") |
Re: ** Python Support Thread **
i don't see a syntax error in your post?
|
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
I have a wild guess here that you're pasting that whole block of text into the command line (or just trying to run that whole block of code) so the first word "python" is opening up the interpreter and the next word 2.5.4 gives you a syntax error.
Can you give more details on what you're doing to run this? |
Re: ** Python Support Thread **
Quote:
http://i1090.photobucket.com/albums/...onprntscrn.jpg So "python 2.5.4 etc..." is already generated when I open up python. So at the first command line is where I start my code or the other posters code and i get the same syntax error, and the only thing that gets highlighted when I try to run it is the "5". |
Re: ** Python Support Thread **
Can we see the code you ran and the actual error message? This will make it easier for us to see what is actually going wrong and why it is happening.
|
| All times are GMT -4. The time now is 05:08 PM. |
|
Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 2008-2020, Two Plus Two Interactive