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
lidiya [134]
3 years ago
12

Design and implement an algorithm that gets as input a list of k integer values N1, N2,..., Nk as well as a special value SUM. Y

our algorithm must locate a pair of values in the list N that sum to the value SUM. For example, if your list of values is 3, 8, 13, 2, 17, 18, 10, and the value of SUM is 20, then your algorithm would output either of the two values (2, 18) or (3, 17). If your algorithm cannot find any pair of values that sum to the value SUM, then it should print the message ‘Sorry, there is no such pair of values’. Schneider, G.Michael. Invitation to Computer Science (p. 88). Course Technology. Kindle Edition.

Computers and Technology
1 answer:
satela [25.4K]3 years ago
6 0

Answer:

Follows are the code to this question:

def FindPair(Values,SUM):#defining a method FindPair  

   found=False;#defining a boolean variable found

   for i in Values:#defining loop for check Value  

       for j in Values:#defining loop for check Value

           if (i+j ==SUM):#defining if block that check i+j=sum

               found=True;#assign value True in boolean variable

               x=i;#defining a variable x that holds i value

               y=j;#defining a variable x that holds j value

               break;#use break keyword

       if(found==True):#defining if block that checks found equal to True

           print("(",x,",",y,")");#print value

       else:#defining else block

           print("Sorry there is no such pair of values.");#print message

Values=[3,8,13,2,17,18,10];#defining a list and assign Values

SUM=20;#defining SUM variable

FindPair(Values,SUM);#calling a method FindPair

Output:

please find the attachment:

Explanation:

In the above python code a method, "FindPair" is defined, which accepts a "list and SUM" variable in its parameter, inside the method "found" a boolean variable is defined, that holds a value "false".

  • Inside the method, two for loop is defined, that holds list element value, and in if block, it checks its added value is equal to the SUM. If the condition is true, it changes the boolean variable value and defines the "x,y" variable, that holds its value.
  • In the next if the block, it checks the boolean variable value, if the condition is true, it will print the "x,y" value, otherwise, it will print a message.  

You might be interested in
The term "net radiation" refers to _____ the total amount of energy received by earth. the total amount of energy radiated by ea
Nimfa-mama [501]

The term "net radiation" refers to <span>the difference in amount of incoming and outgoing radiation the total amount of energy received by earth.
</span>
<span>Energy comes from the sunlight penetrates the top of the atmosphere- that's the incoming energy. Then some of it is lost by reflection of clouds or the Earth's surface, thermal radiation- that's the outgoing energy.</span>

5 0
3 years ago
Where would the information needed to start a computer be stored?
ASHA 777 [7]

Answer:

BIOS software is stored on a non-volatile ROM chip on the motherboard. … In modern computer systems, the BIOS contents are stored on a flash memory chip so that the contents can be rewritten without removing the chip from the motherboard.

Explanation:

8 0
3 years ago
Which software program is used to create a database on a computer, add, change, and delete data in the database, and create quer
Radda [10]
I'd say Microsoft access
3 0
3 years ago
Read 2 more answers
Given the following function definition
nasty-shy [4]

Answer:

The output of the given question is the option "B".

Explanation:

In the given code the output is the option B which is 1 6 3. Because in the function calc() we pass the two parameters and in this function we define an integer variable c that calculate the value of the variable a and b. in outside the function we declare three variable x,y and z in this we assign value that is 1,2,3 and call the function and print the value. The variable z is no pass in the function so the value of this variable is 3, x variable value is 1 and y variable value is 6. So the output of the code is 1 6 3.

7 0
3 years ago
Navigating to the Word Options will give me tools to
zloy xaker [14]

Answer:

lolololololololololol

Explanation:

lolololololololololol

7 0
2 years ago
Other questions:
  • Here are the codes for producer and consumer problems.
    10·1 answer
  • Is a way of grading web pages by the number of other web pages that link to them?
    10·1 answer
  • What is the number 5280 in binary
    14·1 answer
  • -How long does a copyright last?
    6·1 answer
  • What is you full name ?​
    15·2 answers
  • What is Access? When would you use Access instead of Excel?
    9·1 answer
  • Select the correct images Jane has to pick images that portray action photography. Which of these images would she pick? please
    9·1 answer
  • How is an API different from a web application?
    10·1 answer
  • Karen wants to create a program that will allow the user to input their age. Which of these lines of code should be used?
    11·1 answer
  • What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 0; j &lt; 5; j++) cout &lt;&lt;
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!