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
Korolek [52]
3 years ago
11

Implement the function pairSum that takes as parameters a list of distinct integers and a target value n and prints the indices

of all pairs of values in the list that sum up to n. If there are no pairs that sum up to n, the function should not print anything. Note that the function does not duplicate pairs of indices
Computers and Technology
1 answer:
Yuki888 [10]3 years ago
6 0

Answer:

Following are the code to this question:

def pairSum(a,x): #find size of list

   s=len(a) # use length function to calculte length of list and store in s variable

   for x1 in range(0, s):  #outer loop to count all list value

       for x2 in range(x1+1, s):    #inner loop

           if a[x1] + a[x2] == x:    #condition check

               print(x1," ",x2) #print value of loop x1 and x2  

pairSum([12,7,8,6,1,13],13) #calling pairSum method

Output:

0   4

1   3

Explanation:

Description of the above python can be described as follows:

  • In the above code, a method pairSum is declared, which accepts two-parameter, which is "a and x". Inside the method "s" variable is declared that uses the "len" method, which stores the length of "a" in the "s" variable.
  • In the next line, two for loop is declared, in the first loop, it counts all variable position, inside the loop another loop is used that calculates the next value and inside a condition is defined, that matches list and x variable value. if the condition is true it will print loop value.
You might be interested in
What is the use of html in websites
Alborosie
HTML is a very basic markup language and requires memorization of a few dozen HTML commands that structure the look and layout of a web page. Before writing <span>any HTML code or designing your first web page, you must decide on an HTML editor or text editor, such as Notepad or Word Pad.</span>
4 0
2 years ago
Read 2 more answers
An array similar to a phone book has 1000 names arranged as names [0], names[1]....names[999]. Nancy wants to search a name X in
sammy [17]

Answer:

b. The names in the list should be in alphabetical order.

Explanation:

A binary search is an algorithm used for searching for an item in a list or array. The algorithm first sorts the data structure into order and then divides it into halves. If the searched item is less than the middle item in the list, then the algorithm searches for the target in the first half, else, in the second half. This reduces the time complexity of the search.

5 0
2 years ago
Types of antivirus explain them
Veronika [31]

Answer: an antivirus is a type of program designed  to protect computers from  viruses, spyware, botnets, rootkits, keyloggers and such. There are many versions and types of anti-virus programs which can be very helpful.

Such as:

Norton.

Kaspersky.

Ad Aware.

AVG

Mc Afee

Hope this helps u...

Explanation:

3 0
3 years ago
What is the mean of 9, 25, and 53?
Alex17521 [72]

Answer:

i think its 29

- add all the numbers up and divide by how many numbers there are.

8 0
3 years ago
JAVA
marshall27 [118]

Answer:

Answer is in the provided screenshot!

Explanation:

Steps required to solve this problem:

1 - define what characters are "vowels" by assigning them to an array.

2 - create a variable to record the amount of vowels there are in the string.

3 -  convert the input string into a character array and iterate through each character

4 - for each of the character of the string we go through, check if it matches any of the vowels

5 - return true if the vowel count is greater than 1

Alternative methods using the Java Stream API have also been wrote, please respond if you require them.

7 0
2 years ago
Other questions:
  • The system administrator in your office quits unexpectedly in the middle of the day. It's quickly apparent that he changed the s
    10·1 answer
  • Assume you have a sorting algorithm that you can use as a black box. Use the sorting algorithm to sort the input list. Now write
    10·1 answer
  • Uses of keyboard as a input device
    13·2 answers
  • PLEASE HELP!
    13·2 answers
  • True or false. Every word has only one correct spelling and pronunciation.
    6·1 answer
  • Write a program that asks the user for three strings. Then, print out whether the first string concatenated to the second string
    8·1 answer
  • The Fibonacci numbers are the numbers
    15·1 answer
  • Write a program that asks the user to input
    11·1 answer
  • Select the correct answer.
    15·1 answer
  • Which is a natural hazard that can cause extinctions? Choose all that apply.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!