Question: need help with python assignment, previous code is below :param n: any integer :return: returns TRue if n is prime number else it returns
need help with python assignment, previous code is below
""" :param n: any integer :return: returns TRue if n is prime number else it returns False """ if n == 2 or n == 3: # if n=2 or n=3 then return True return True else: count = 0 # else initialize count = 0 for i in range(2, (n // 2)+1): # iterate for loop from 2 to n / 2 if n % i == 0: # if n mod i == 0 then increment count count += 1 if count == 0: # if count is 0 then return True else return False return True else: return False print(is_prime(2)) # call the function is_prime with any integer it prints True if prime False if not prime print(is_prime(15)) print(is_prime(199)) print(is_prime(311)) print(is_prime(267)) print(" ") def main(): """ :return: return total count of prime number in the given range """ m = int(input('Enter first range: ')) # asks user to enter first range n = int(input('Enter second range: ')) # asks user to enter second range list_of_bool = [] # initialize list_of_bool = [] it contains True or False as the value returned from is_prime func for i in range(m, n+1): # loop iterate through m to n+1 here m is always 2 as given in question list_of_bool.append(is_prime(i)) # call the function is_prime with each element and append the result ot the list_of_bool count = len([i for i in list_of_bool if i is True]) # count how many True are there in list_of_bool using list comprehension print(count) # print the count if __name__ == '__main__': # program starts from this statement main() # call main functionHow Many Terms of The Abraham Series? Write a well-documented Python program, hmwk4Q3.py, that determines the number of terms in the infinite series of Abraham to obtain a specified level of precision with the actual value of it, as compu Your main program prompts a user for an integer M. Your application identifies the number of terms N to achieve an estimate of n within 10M. Your program should call upon your function defined in hmwk4Q2.py. As a comment include the answer to the question when M - 9. Grading Correct main() function (4 points). Include_name_ is set to'_main_' to ensure the program initiates when it is run (+2 points). Correct answer to M-9 question (+4 points)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
