Question

PYTHON 3 Write a program that prints the count of all prime numbers between A and...

PYTHON 3

Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows:

A = 21212

B = A + 5000

Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29.

Rules:

  1. You should first create a boolean function called isPrime and use that function in your program. This function should take in any int and return true if the number is prime, otherwise, return a false. In the main body of your program, you should create a loop from A to B (inclusive) and use isPrime function to determine if the loop number should be counted or not.

  2. Your program SHOULD NOT PRINT the individual prime numbers. You can print them for your own testing purpose, but in the final submission, comment out such print statements.

  3. Your program SHOULD ONLY PRINT the answer -- which is a number.

  4. Do not print extra characters in your answer (E.g. "answer=123" instead of 123)

Homework Answers

Answer #1

Code:

def isPrime(x):
    if x >= 2:
        for y in range(2,x):
            if not ( x % y ):
                return False
    else:
        return False
    return True

def main():
    A = 2
    B = 29
    count = 0

    for i in range(A, B+1):
        if isPrime(i):
            count = count + 1

    print(count)

main()

Code screenshot:

Output:

496
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program with while loop that prints all numbers between 5 and 100 (inclusive) that...
Write a program with while loop that prints all numbers between 5 and 100 (inclusive) that are divisible by 5.
- Write a python program which prints all the numbers between 1 and 100 that are...
- Write a python program which prints all the numbers between 1 and 100 that are divisible by 3.
Design a program in Java that displays all of the prime numbers from 1 through 100....
Design a program in Java that displays all of the prime numbers from 1 through 100. The program should have a loop that calls the isPrime() function. 11 Prime Numbers List (15 points) Use CONSTANTS to set the maximum number in the table to 100 and the number of entries per row to 5.   Table of prime numbers from 1 to 100 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59...
An integer 'n' greater than 1 is prime if its only positive divisor is 1 or...
An integer 'n' greater than 1 is prime if its only positive divisor is 1 or itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Write a python program that defines a function isPrime (number) with the following header: def isPrime (number): that checks whether a number is prime or not. Use that function in your main program to count the number of prime numbers that are less than 5000....
Write a smallest_gap(start_num, end_num) function that finds smallest gap between successive primes, considering prime numbers in...
Write a smallest_gap(start_num, end_num) function that finds smallest gap between successive primes, considering prime numbers in the range from start_num to end_num (inclusive). For example, start_num = 5 and end_num = 12, the prime numbers in that range are: [5, 7, 11]. The smallest gap between any two prime numbers in this list is 2, so the function would return 2. Some example test cases (include these test cases in your program): >>> print(smallest_gap(5, 12)) 2 # The primes between...
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
write a C++ program that display a prime numbers between 1 and 100 number. Plase print...
write a C++ program that display a prime numbers between 1 and 100 number. Plase print the remaining primes by “dots” For gexample The output should appear like The prime numbers between 1 and 100 are: 1, 2, 3, 5, 7, .........
Write a program to find all the numbers divisible by 7 between a given range of...
Write a program to find all the numbers divisible by 7 between a given range of numbers [n1, n2] entered by the user using a FOR loop only. write C program. help
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes a ransom note. It is not wrriten by hand to avoid having his hand writing being recognized, so the kid napper uses a magazine to create a ransom note. We need to find out, given the ransom note string and magazine string, is it possible to given ransom note. The kidnapper can use individual characters of words. Here is how your program should work...