Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 1st, 2006, 3:01 PM   #1
Vahagn
Newbie
 
Join Date: Feb 2006
Posts: 5
Rep Power: 0 Vahagn is on a distinguished road
KeyboardInterrupt when calling a function

Hi, I am toying with the following program to generate prime numbers:

import sys
from math import sqrt, floor

def prime_gen(count):

    num = 2
    ct = 0  
    while ct < count:
        for i in range(2, int(floor(sqrt(num)))):
            if num % i == 0:             
                num = num + 1
            elif num % i != 0:
                print num
                ct = ct + 1
                num = num + 1               
         
prime_gen(100) 
#x = int(sys.argv[1])
#prime_gen(x)

When I call prime_gen at the prompt (=execute the program), the prompt freezes and I have to exit it with Ctrl+C. The error message says there is a KeyboardInterrupt and the lines 17 and 9 cause the problem, I however do not understand WHAT the problem is - thanks beforehand for help.

V.
Vahagn is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC