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
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.
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.
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Please prove 1. Every positive integer is a product of prime numbers. 2. If a and...
Please prove 1. Every positive integer is a product of prime numbers. 2. If a and b are relatively prime, and a|bc, then a|c. 3. The division algorithm for F[x]. Just the existence part only, not the uniqueness part
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT