Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help! Q1: Assume the availability of a function is_prime. Assume a variab

ID: 3693496 • Letter: P

Question

Please help!

Q1: Assume the availability of a function is_prime. Assume a variable  n has been associated with positive integer. Write the statements needed to find out how many prime numbers (starting with 2 and going in increasing order with successively higher primes [2,3,5,7,11,13,...]) can be added before exceeding n. Associate this number with the variable  k.

What I have so far:

k=0
i=2
sum=0

while sum<=n:
if is_prime(i):
sum+=i

k = k + 1
i = i + 1

Q2: Create a dictionary that maps the first n counting numbers to their squares. Associate the dictionary with the variable  squares.

What I have so far:

dictionary={}
for k in range(n+1):
   dictionary[k]=k

for x in range(1,n)
       squares=(x**2)
       dictionary[x]=squares

Q3:Given the list value_list, assign the number of nonduplicate values to the variable distinct_values.

What I have:

temp= set(value_list)

distinct_values = []


len(distinct_values.append(temp))

Q4:Given the string line, create a set of all the vowels in line. Associate the set with the variable  vowels.

What I have:

temp = set(vowels)
for line in temp:
   if line.lower() in ["a","e","i","o","u"]:
       vowels.append(line)

Explanation / Answer

Multiple Question : ANswering 1st one.

k=0
i=2
while i<=n:
if is_prime(i):
k = k + 1
i = i + 1
print k