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
What are the main differences between photo and video formats?
horrorfan [7]

Answer:

Nothing just the video is series of photos together

Explanation:

8 0
3 years ago
Does kohl's sell homecoming dresses?? And if do you know what the price rage would be !!
SpyIntel [72]

Answer:

Yes, the prices are anywhere from $30-$100 dollars+tax

https://www.kohls.com/catalog/juniors-homecoming-dresses-clothing.jsp?CN=Gender:Juniors+Occasion:Homecoming+Category:Dresses+Department:Clothing

6 0
2 years ago
Why does the definition of fair use remain ambiguous?
bogdanovich [222]
Millions of dollars in legal fees have been spent attempting to define what qualifies as a fair use.

There are no hard-and-fast rules, only general guidelines and varied court decisions, because the judges and lawmakers who created the fair use exception did not want to limit its definition.

Like free speech, they wanted it to have an expansive meaning that could be open to interpretation.
8 0
3 years ago
What is your definition of Green/Eco Driving?
Masja [62]
Using/driving with an electric car or using car that is ecologically friendly (less pollution) Ex.Bio Fuel
8 0
3 years ago
Please help me i dont know
rodikova [14]
There is something wrong with your photo you should try and re-post it again
4 0
2 years ago
Other questions:
  • what would happen if a large number of computer users are attempting to access a web site at the same time that you are
    15·2 answers
  • Fuel-pressure regulators on fuel-return-type fuel-injection systems are installed
    8·2 answers
  • Robert’s computer is not working properly. It has become too slow to respond to programs. What can he do to maintain his compute
    15·1 answer
  • Nonprogrammed decision
    7·1 answer
  • Answer this and you get free 100 points
    14·2 answers
  • Why might you want to save a downloaded file to your computer first instead of running it immediately?
    6·1 answer
  • Why might a company choose Linux for its operating system instead of Microsoft Windows or Mac OS? The company's employees can sy
    13·1 answer
  • If you want the input gear to spin in the same direction as the output gear you must use a _______ gear.
    13·1 answer
  • Create an application named SalesTransactionDemo that declares several SalesTransaction objects and displays their values and th
    12·1 answer
  • How many passes will it take to find 30 using a binary search?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!