GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Mar-2009, 21:20
bsiguenza bsiguenza is offline
New Member
 
Join Date: Mar 2009
Posts: 2
bsiguenza is on a distinguished road

Program for Prime


I am doing an assignment of a program that prints out all the prime numbers between two values which the user provides.

AND

we're suppose to start with

num= input ("enter starting number") and do likewise to get the stopping number.


then after outputting all the primes the program is to query the user to see if it is desired to do another run. with ans= raw-input("again (y/n)")

please help
  #2  
Old 01-Mar-2009, 21:49
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,627
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Program for Prime


So what's the problem? You want someone to do it for you? If so, that won't happen here.

Try writing the program and see how far you get. If you post what you come up with to this forum, you are more likely to get assistance. Most of the members here have no problem helping out others, but you have to give us something to work with.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #3  
Old 01-Mar-2009, 23:34
bsiguenza bsiguenza is offline
New Member
 
Join Date: Mar 2009
Posts: 2
bsiguenza is on a distinguished road

Re: Program for Prime


Python Code:
num = input("enter starting number")
num*=1.0
prime = True
for divisor in range(2,num**0.5+1):
    if num/divisor==int(num/divisor):
        prime=False

def isprime(num):
    num*=1.0
    for divisor in range(2,int(num**0.5)+1):
        if num/divisor==int(num/divisor):
            return False
    return True
for a in range(2,num):
    if isprime(a):
        print a


THIS IS THE CODE THAT I HAVE BUT I DON'T KNOW HOW TO ENTER THE LOOP FOR IT TO BE ONLY BETWEEN TWO NUMBERS.
Last edited by admin : 01-Mar-2009 at 23:47. Reason: Please insert your example Python codes between [PY] and [/PY] tags
  #4  
Old 03-Mar-2009, 18:23
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,627
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Program for Prime


Currently it is printing all numbers from 2 to whatever the input number is. You never call for a second number to be input so it will never ask for the second number.

Basically what you need to do is ask for the starting and ending numbers. You have the function to determine the prime numbers; all you have to do is rewrite your loop to iterate through the isprime() function, making sure that the user-given numbers are used as the range.

I also got 2 DeprecationWarnings about integers being expected but float values being given on lines 4 and 14. You may want to look into those but I don't know if you get the same errors. I'm using Python 2.5.1.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Equation solver RazoR C Programming Language 3 18-May-2008 10:24
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 04:48
Help with a complex program lordfuoco C++ Forum 5 24-Jun-2006 07:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:31.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.