1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AysviL [449]
2 years ago
15

Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the stateme

nts 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.
Computers and Technology
1 answer:
vivado [14]2 years ago
6 0

Answer:

def main():

   n = int(input('Enter the value of the variable n:'))

   k=2;

   totalSum = 0

   print('The list of the prime numbers are as follows:')

   while k <= n:

       totalSum = totalSum+is_prime(k)

       k=k+1

   print('Total sum of the prime numbers:',totalSum)

def is_prime(k):

   primeNumber = 0      

   i=1

   while i<=int(k):

       if (k % i) == 0:

           primeNumber = primeNumber + 1

       i=i+1

   if(primeNumber==2):      

       print(k)

       return k;

   else:        

       return 0;

main()

Explanation:

  • Run the while loop until k is less than n.
  • Determine if the variable k is prime then add it to the totalSum variable.
  • Increment the value of k by 1.
  • Create a function isPrime to check whether the number is prime  or not by determining the factors of k which can be found using the modulus operator.
  • Call the main function at the end.

You might be interested in
What keyboard combination can you use to open the windows tool context menu, which contains options such as power options and di
Shkiper50 [21]
Windows button and x
8 0
3 years ago
What four things does steering control involve?
Dafna1 [17]

Answer:

putting your hands one the wheel, putting the car in gear, putting your foot on the brakes when you need to, and watch for cars when you're driving. hope it helps

Explanation:

7 0
3 years ago
In this assignment we are going to practice reading from a file and writing the results of your program into a file. We are goin
zhenek [66]

Answer:

In Python:

import os.path

from os import path

fname = input("Filename: ")

if path.exists(fname):

with open(fname) as file_in:

 lines = []

 for line in file_in:

  lines.append(line.rstrip('\n'))

f = open("stat.txt","r+")

f.truncate(0)

f = open("stat.txt", "a")

f.write("Names\tTotal\tSubjects\tAverage\n")

for i in range(len(lines)):

 rowsum = 0; count = 0

 nm = lines[i].split()

 for j in nm:

  if (j.isdecimal()):

   count+=1

   rowsum+=int(j)

 average = rowsum/count

 f.write(nm[0]+"\t %3d\t %2d\t\t %.2f\n" % (rowsum, count, average))

f.close()

else:

print("File does not exist")

Explanation:

See attachment for explanation where comments were used to explain each line

Download txt
6 0
3 years ago
Addition and subtraction are considered to be ____ operations performed by a computer.
Natali5045456 [20]

Answer:

Mathematical operations

4 0
3 years ago
Rickie gets a message from the school’s tech support department. Their computer is supposed to be running the latest system soft
raketka [301]

Answer:

the operating system or web browser

6 0
3 years ago
Read 2 more answers
Other questions:
  • You want to register the domain name ABCcompany.org, but the registration service is not allowing you to do that. What's the mos
    10·1 answer
  • Which of the following Statements accurately describes the legality of telemarketing
    12·1 answer
  • In which of the following scenarios would you use the Redo function?
    12·1 answer
  • Use of the internet to access programs and data on computers that’s are owned and managed by the other using large data centers.
    11·1 answer
  • Which type of market are you in if your firm, along with three other firms, controls 95% of the total music industry?
    13·1 answer
  • What is the problem with the code snippet below? public class Test { public static void main(String[] args) { System.out.println
    6·1 answer
  • GPS data can be used to track the rate and direction of plate movement. If a GPS unit measures a latitude velocity of 28.2 mm/yr
    8·1 answer
  • What direction would a sprite go if you constantly increased its x property? Your answer What direction would a sprite go if you
    7·1 answer
  • Someone please help will mark as brainliest
    8·2 answers
  • How does a programmer use digital waves to transfer sound?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!