Write the program in python Using a list of integers (which you may code directly into your program, rather than inputting), write a program to find and print all pairs of integers in the list whose sum is equal to a given input number, as long as the two numbers are not the same. For example, if the list is [4, 5, 7, 1, 9, 3, 4, 2, 6] and given input sum is 8, the output should be the pairs (5,3) (7,1) (2,6). Note that (4,4) is not a valid pair since the two numbers are the same. Your program should include the following functions to generate the output: function main which gets the required sum number and uses the following functions to generate the desired output as shown below function findPairs which, given the list of integers and the desired sum, finds and returns a list of strings showing the found pairs of numbers that meet the criteria given above; each string should be of the form "(num1,num2)"; note that your function must use a nested loop for this rather than using built-in list functions function printResults which, given the two lists and the sum, prints the original list, the given sum and the resulting list of strings, in the format as shown below Sample input/output for run 1: Enter the expected sum of two values: 8 The given list is: [4, 5, 7, 1, 9, 3, 4, 2, 6] The list of pairs that add to the given sum of 8 is: (5,3) (7,1) (2,6) Sample input/output for run 2: Enter the expected sum of two values: 88 The given list is: [17, 22, 25, 31, 32, 33, 40, 44, 44, 45, 47, 49, 50, 53, 55, 59, 62, 66, 67, 78, 80] The list of pairs that add to the given sum of 88 is: (22,66) (33,55)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write the program in python

Using a list of integers (which you may code directly into your program, rather than inputting), write a program to find and print all pairs of integers in the list whose sum is equal to a given input number, as long as the two numbers are not the same. For example, if the list is [4, 5, 7, 1, 9, 3, 4, 2, 6] and given input sum is 8, the output should be the pairs (5,3) (7,1) (2,6). Note that (4,4) is not a valid pair since the two numbers are the same. Your program should include the following functions to generate the output:

  • function main which gets the required sum number and uses the following functions to generate the desired output as shown below

  • function findPairs which, given the list of integers and the desired sum, finds and returns a list of strings showing the found pairs of numbers that meet the criteria given above; each string should be of the form "(num1,num2)"; note that your function must use a nested loop for this rather than using built-in list functions

  • function printResults which, given the two lists and the sum, prints the original list, the given sum and the resulting list of strings, in the format as shown below

    Sample input/output for run 1:

    Enter the expected sum of two values: 8 The given list is: [4, 5, 7, 1, 9, 3, 4, 2, 6] The list of pairs that add to the given sum of 8 is: (5,3)

    (7,1) (2,6)

    Sample input/output for run 2:

    Enter the expected sum of two values: 88 The given list is: [17, 22, 25, 31, 32, 33, 40, 44, 44, 45, 47, 49, 50, 53, 55, 59, 62, 66, 67, 78, 80] The list of pairs that add to the given sum of 88 is: (22,66) (33,55)
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education