Python Tutorial – 13 – Prime Number Program


Video is ready, Click Here to View ×

Learn how to generate prime numbers.

15 thoughts on “Python Tutorial – 13 – Prime Number Program

  1. The Main Program 
    Write a program that allows the user to select from one of the following tasks. After the task 
    runs, the user should be able to select another task. There should also be an option to end the 
    program when they are done. 
    Task #1 
    Simple Divisibility Test 
    Determine if a number, n, is evenly divisible by a number, m. Both n and m are entered by the 
    user. The program should prompt the user for both numbers and then report if n is evenly 
    divisible by m. 
    Task #2 
    Prime Test 
    Report if a user entered integer is prime. The user should be prompted for the number. When 
    displaying the result to the display, be sure to be descriptive so that the program is user friendly. 
    Task #3 
    This task should ask the user to enter a positive integer, and report all positive integers that are a 
    factor of the user entered number. If zero or a negative number is entered, the user should be 
    informed that the number is not positive and be prompted to repeatedly enter an integer until a 
    positive integer is entered. 

    i have this project and am not a tech or science major so i am totally confused with this project. please help me

  2. I found a flaw when you input 4 it says that is prime but it is actually a composite number at 10:19. This is because the square root of 4 is 2 so it skips over 2 and marks it prime, the initial state of it.

  3. I evaluated the following in IDLE with a discrepancy that you might be able to explain to me:

    >>>def is_prime(n):
           for i in range(3, n):
               if n % i == 0:
                   return False
           return n

    >>>filter(is_prime, range(3,50))
    [3, 4, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

    What the heck is the number '4' doing in there?

  4. I made it on python 3.3 but i had to change it. Here's what i did:

    def prime(number):
        if number<2: return False
        for factor in range(2, int(number**.5)+1):
            if number%factor==0: return False
        return True

    print(prime(1)) # This will print(False)

    1.Return False if number less than 2
    2.Return False if number%factor==0 for factor in range 2 and sqrt(number)
    (If sqrt(number) is a fraction round it up)
    3.Return True if you reach the end

Leave a Reply

Your email address will not be published. Required fields are marked *