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
sladkih [1.3K]
3 years ago
9

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 the total exceeds n. Associate this number with the variable k.
Computers and Technology
1 answer:
Eva8 [605]3 years ago
4 0

Answer:

The solution code is written in Python

  1. def isPrime(num):
  2.    for x in range(2, num):
  3.        if(num % x == 0):
  4.            return True  
  5.    return False  
  6. n = 1000
  7. k = 0
  8. total = 0
  9. value = 2
  10. while(total <= n):
  11.    if(isPrime(value)):
  12.        total += value  
  13.        k += 1
  14.    
  15.    value += 1
  16. print(k)

Explanation:

Given a function isPrime to check if the input number, num, is a prime (Line 1 - 5). Create the variable n and set it to 1000. Create variable k to hold the number of prime numbers which are added before the total exceed n (Line 8).

Create a while loop and set the loop condition to ensure the loop will keep going until the total of prime value exceed n (Line 12). Within the loop call the isPrime function and if the current input value is a prime, add the value to total and increment k by one (Line 13 - 15). Increment value by one before proceed to next iteration (Line 17).

Lastly, print the value of k (Line 19) and the sample output value is 36.

You might be interested in
colby lives a very career-driven lifestyle. he works long hours and enjoys making a lot of money by working overtime. after he a
just olya [345]

The role of being a father will decrease Colby’s income and decrease the career-driven nature of his lifestyle.

8 0
3 years ago
Read 2 more answers
What type of malicious procedure involves using sniffing tools to capture network communications to intercept confidential infor
Alex_Xolod [135]

Answer:

eavesdropping

Explanation:

Eavesdropping is as an <em>electronic attack</em> where digital communications are intercepted by an individual whom they are not intended. This is done in two main ways: <em>Directly listening</em> to digital or analog voice communication or the <em>interception or sniffing</em> of data relating to any form of communication.

4 0
3 years ago
Write the Python programs for the
ArbitrLikvidat [17]

Answer:

num = int(input("Enter a number: "))

if (num % 2) == 0:

print("{0} is Even number". format(num))

else:

print("{0} is Odd number". format(num))

4 0
3 years ago
How technology bacome the mode of revealing​
maria [59]

Answer:

afefdasf

Explanation:

3 0
3 years ago
Write a program that has an input as a test score, and figures out a letter grade for that score, such as "A", "B", "C", etc. ac
Marizza181 [45]

Answer:

The program in csharp for the given scenario is shown.

using System;

class ScoreGrade {

static void Main() {

//variables to store score and corresponding grade

double score;

char grade;

//user input taken for score

Console.Write("Enter the score: ");

score = Convert.ToInt32(Console.ReadLine());

//grade decided based on score

if(score>=90)

grade='A';

else if(score>=80 && score<90)

grade='B';

else if(score>=70 && score<80)

grade='C';

else if(score>=60 && score<70)

grade='D';

else

grade='F';

//score and grade displayed  

Console.WriteLine("Score: "+score+ " Grade: "+grade);

}

}

OUTPUT1

Enter the score: 76

Score: 76 Grade: C

OUTPUT2

Enter the score: 56

Score: 56 Grade: F

Explanation:

1. The variables to hold the score and grade are declared as double and char respectively.

int score;

char grade;

2. The user is prompted to enter the score. The user input is not validated and the input is stored in the variable, score.

3. Using if-else-if statements, the grade is decided based on the value of the score.

if(score>=90)

grade='A';

else if(score>=80 && score<90)

grade='B';

else if(score>=70 && score<80)

grade='C';

else if(score>=60 && score<70)

grade='D';

else

grade='F';

4. The score and the corresponding grade are displayed.

5. The program can be tested for different values of score.

6. The output for two different scores and two grades is included.

7. The program is saved using ScoreGrade.cs. The .cs extension indicates a csharp program.

8. The whole code is written inside a class since csharp is a purely object-oriented language.

9. In csharp, user input is taken using Console.ReadLine() which reads a string.

10. This string is converted into an integer using Convert.ToInt32() method.

score = Convert.ToInt32(Console.ReadLine());

11. The output is displayed using Console.WriteLine() or Console.Write() methods; the first method inserts a line after displaying the message which is not done in the second method.

12. Since the variables are declared inside Main(), they are not declared static.

13. If the variables are declared outside Main() and at the class level, it is mandatory to declare them with keyword, static.

6 0
3 years ago
Other questions:
  • Which is the last step in conducting a url research
    11·1 answer
  • You need to put cabling for connecting two new computers in a room, which did not have any network infrastructure. Because of th
    9·2 answers
  • The maximum number of colors that should be used on a slide is _____. 2 4 6 8
    5·1 answer
  • Give a recursive implementation for the function: def is_sorted(lst, low, high) This function is given a list of numbers, lst, a
    10·1 answer
  • Almost immediately after a server migration project, employees are complaining that they can't reach the Internet. You sit down
    8·1 answer
  • Both the Alphabetic Index and the Tabular List must be used to locate and assign a diagnosis code in ICD-10-CM. Group of answer
    7·1 answer
  • How many days till earth ends
    12·1 answer
  • PLEASE HELP! (NO LINKS)
    7·1 answer
  • Look at the code in the example below, and then answer the question.
    9·1 answer
  • Which website offers guidance on putting together a checklist to provide guidance on configuring and hardening operating systems
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!