Question

In: Computer Science

1. Write a python function that receives two positive numbers and displays the prime numbers between...

1.

Write a python function that receives two positive numbers and displays the prime numbers between them.Note: A prime number (or a prime) is a natural number greater than 1 and that has no positive divisors other than 1 and itself.

2.

Using either Whileor Foriteration loops, write a python code that prints the first Nnumbers in Fibonacci Sequence, where N is inputted by the user. Now, revise this code to instead print a) the Nthnumber in Fibonacci Sequence.b) the summation of these N numbers in this sequence.

Solutions

Expert Solution

def is_prime(number):
    if(number <= 1):
        return False
    for x in range(2,number):
        if number%x == 0:
            return False
    return True

def primesBetween(A,B):
    for i in range(A,B+1):
        if(is_prime(i)):
            print(i)

# Testing
primesBetween(5,15)

########################################

#Code.py
N = int(input("Enter a number: "))
sum = 0
if N>0:
    if(N==1):
        print("the Nthnumber in Fibonacci Sequence:",0)
    if(N==2):
        print("the Nthnumber in Fibonacci Sequence:",1)
        sum += 1
    if(N>=3):
        fold1 = 0
        fold2 = 1
        fnew = 1
        for i in range(N-2):
            fold1 = fold2
            fold2 = fnew
            fnew = fold1 + fold2
            sum += fnew
        print("the Nthnumber in Fibonacci Sequence:", fnew)
    print("the summation of these N numbers in this sequence:",sum)
else:
    print("Invalid input")


Related Solutions

(Use the GenericStack class) Write a program that displays the first 100 prime numbers in descending...
(Use the GenericStack class) Write a program that displays the first 100 prime numbers in descending order. Use a stack to store the prime numbers.
Write a python program to sum the prime numbers existing in an array . For instance...
Write a python program to sum the prime numbers existing in an array . For instance , if A = [4, 7, 12, 3, 9] the output should be 10
PYTHON: Implement the sieve of Eratosthenes: a function for computing prime numbers, known to the ancient...
PYTHON: Implement the sieve of Eratosthenes: a function for computing prime numbers, known to the ancient Greeks. Choose an integer n. This function will compute all prime numbers up to n. First insert all numbers from 1 to n into a set. Then erase all multiples of 2 (except 2); that is, 4, 6, 8, 10, 12, . . . . Erase all multiples of 3, that is, 6, 9, 12, 15, ... . Go up to √ n. The...
Write following program using Python: A positive integer greater than 1 is said to be prime...
Write following program using Python: A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer greater than 1 is composite if it is not prime. Write a program that asks the user to enter a integer greater than 1, then displays all of the prime numbers that are less than or equal to the number entered. Last, create two files. One file will hold all of...
Python: Write a function that receives a one dimensional array of integers and returns a Python...
Python: Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions. Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result. Below...
In PYTHON: Write a function that receives a sentence and returns the last word of that...
In PYTHON: Write a function that receives a sentence and returns the last word of that sentence. You may assume that there is exactly one space between every two words, and that there are no other spaces at the sentence. To make the problem simpler, you may assume that the sentence contains no hyphens, and you may return the word together with punctuation at its end.
In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The...
In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The decryption does not change the lowercase letters ‘e’, ‘w’, and ‘l’ (lowercase L). For any other character, we change it to a number using ord(). We then take the number to a power of 19, and then find the remainder after diving by 201. Finally, we take the character corresponding to the number we obtained (using chr()). For example, assume that we receive the...
use Python The assertion that every even number is the sum of two prime numbers is...
use Python The assertion that every even number is the sum of two prime numbers is called Goldbach’s conjecture. You will write a program that asks the user for an integer number, then checks if the integer is even, and finally determines two prime numbers that sum to the user’s entered integer number. Assignment Requirements Three functions are required: get_input(): This function takes no parameters, but will ask the user for an integer number. It will return a valid integer....
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. You may want to modify your solution from Problem 1 on Assignment 4, or you can use this starter...
Find the biggest “*prime gap” (see definition) from the prime numbers between 1 and 1,000,000. *Prime...
Find the biggest “*prime gap” (see definition) from the prime numbers between 1 and 1,000,000. *Prime gap = the difference between two consecutive primes. The exercise can be completed manually or with a computer program. Whichever seems easiest.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT