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)
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).
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...
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 language 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....
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times,...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times, each time using a different syntax to define the list. Write a while loop that prints the numbers from 1 to 10. Convert your previous loop into a for loop. Rewrite your for loop to only have one number in the range. Write a for loop to print out each item of your list of 10 numbers, all on the same line, separated by...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT