Question

In: Computer Science

python coding Suppose a list of positive numbers is given like the following list (remember this...

python coding

Suppose a list of positive numbers is given like the following list (remember this is only an example and the list could be any list of positive numbers) exampleList: 15 19 10 11 8 7 3 3 1 We would like to know the “prime visibility” of each index of the list. The “prime visibility” of a given index shows how many numbers in the list with indexes lower than the given index are prime. For instance, in the examplList, the “prime visibility” of the index 4 is 2 because there are 2 numbers (19 and 11) before index 4 that are prime. To solve this problem, design and implement a function called primeVisibility with two parameters: 1- The list of numbers 2- The index The function finds and returns the “prime visibility” of the given index.

Solutions

Expert Solution

Source Code:

def isPrime(n):
   prime=False
   for i in range(2,n//2+2):
       if(n%i==0):
           prime=True
           break;
   return prime

def primeVisibilty(lst,index):
   count=0
   for i in range(0,index):
       if(isPrime(lst[i])==True):
           count=count+1
   return count

print(primeVisibilty([15,19,10,11,8,7,3,3,1],4))


Related Solutions

in PYTHON given a specific text file containing a list of numbers on each line (numbers...
in PYTHON given a specific text file containing a list of numbers on each line (numbers on each line are different) write results to a new file after the following tasks are performed: Get rid of each line of numbers that is not 8 characters long Get rid of lines that don't begin with (478, 932, 188, 642, 093)
#Write a program in Python that given a list of positive integers, return another list where...
#Write a program in Python that given a list of positive integers, return another list where each element corresponds to the sum of the digits of the elements o#f the given list. #Example: # input # alist=[124, 5, 914, 21, 3421] # output # sum=[7, 5, 14, 3, 18]
In Python, Given a list of numbers, return a list where all adjacent == elements have...
In Python, Given a list of numbers, return a list where all adjacent == elements have been reduced to a single element, so [1,2,2,3,3,2,2,4] returns [1,2,3,2,4]. You may create a new list or modify the passed in list (set function does not work in this case).
In Python And Use List comprehension to solve this question Given a file like this: Blake...
In Python And Use List comprehension to solve this question Given a file like this: Blake 4 Bolt 1 De Grasse 3 Gatlin 2 Simbine 5 Youssef Meite 6 Your program when completed should produce output like this: >>> In the 2016 100 yard dash the top finishers were: Blake Bolt De Grasse Gatlin Simbine Youssef Meite The people with a two part name are: ['De Grasse', 'Youssef Meite'] The top three finishers were: ['Bolt', 'De Grasse', 'Gatlin'] Your mission...
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are...
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are divisible by 3. Arrange these numbers in a list called “result”. Hint: similar to page 9 in the slides.
This is for python coding First of all, you need to know what Natural Numbers are....
This is for python coding First of all, you need to know what Natural Numbers are. They are the positive integers (whole numbers) 1, 2, 3, etc., and zero as well. For this project, there are TWO PORTIONS: PORTION 1: Write a program to find the SUM of the first n natural numbers the user wants to add. The program should first prompt the user for how many natural numbers are to be summed. The use for loop to do...
Answer the following questions. Remember that you can only enter numbers in the boxes given and...
Answer the following questions. Remember that you can only enter numbers in the boxes given and that decimal places are separated with a dot (not with a comma). Do not leave empty boxes, otherwise partial marks will not be given. Also, enter at least 4 decimals in your answers whenever possible. Suppose you have the following AD and AS equations: ?=82−0.8?Y=82−0.8π (AD equation) ?=−7+1.8?Y=−7+1.8π (Short Run AS equation) ?=49.15Y=49.15 trillions (Long Run output) a) The real GDP in equilibrium the...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." In C, Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program in C to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume the length...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT