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
solniwko [45]
2 years ago
5

Compute their Cartesian product, AxB of two lists. Each list has no more than 10 numbers.

Computers and Technology
1 answer:
Alexus [3.1K]2 years ago
6 0

Answer:

The program written in Python is as follows: (See Attachments for source file and output)

def cartesian(AB):

     if not AB:

           yield ()

     else:

           for newlist in AB[0]:

                 for product in cartesian(AB[1:]):

                       yield (newlist,)+product  

A = []

B = []

alist = int(input("Number of items in list A (10 max): "))

while(alist>10):

     alist = int(input("Number of items in list A (10 max): "))

blist = int(input("Number of items in list B (10 max): "))

while(blist>10):

     blist = int(input("Number of items in list B (10 max): "))

print("Input for List A")

for i in range(alist):

     userinput = int(input(": "))

     A.append(userinput)

print("Input for List B")  

for i in range(blist):

     userinput = int(input(": "))

     B.append(userinput)  

print(list(cartesian([A,B])))

Explanation:

The function to print the Cartesian product is defined here

def cartesian(AB):

This following if condition returns the function while without destroying lists A and B

    if not AB:

         yield ()

If otherwise

    else:

The following iteration generates and prints the Cartesian products

         for newlist in AB[0]:

              for product in cartesian(AB[1:]):

                   yield (newlist,)+product

<em>The main method starts here</em>

The next two lines creates two empty lists A and B

A = []

B = []

The next line prompts user for length of list A

alist = int(input("Number of items in list A (10 max): "))

The following iteration ensures that length of list A is no more than 10

while(alist>10):

    alist = int(input("Number of items in list A (10 max): "))

The next line prompts user for length of list B

blist = int(input("Number of items in list B (10 max): "))

The following iteration ensures that length of list B is no more than 10

while(blist>10):

    blist = int(input("Number of items in list B (10 max): "))

The next 4 lines prompts user for input and gets the input for List A

<em>print("Input for List A")</em>

<em>for i in range(alist):</em>

<em>     userinput = int(input(": "))</em>

<em>     A.append(userinput)</em>

The next 4 lines prompts user for input and gets the input for List B

<em>print("Input for List B")  </em>

<em>for i in range(blist):</em>

<em>     userinput = int(input(": "))</em>

<em>     B.append(userinput)</em>

This line calls the function to print the Cartesian product

print(list(cartesian([A,B])))

Download txt
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> txt </span>
278935241de85ee14f3de061ede70974.jpg
You might be interested in
What is the function of ctrl+Q​
vlabodo [156]

Answer:

Ctrl+Q is used to remove a paragraph's formatting

Explanation:

Hope that's the answer you're looking for!

5 0
2 years ago
What is typically unique in each database table?
andriy [413]

ID number APEX  answer

4 0
3 years ago
Read 2 more answers
Common separators or delimiters used when converting a table to text include _______________________ , paragraph marks, or comma
Anon25 [30]

Answer:

tabs.

Explanation:

Microsoft Word refers to a word processing software application or program developed by Microsoft Inc. to enable its users to type, format and save text-based documents.

In Microsoft Word 2019, the users are availed with the ability to edit the word document in the following view type;

I. View Mode.

II. Print Mode.

III. Drift Layout.

To easily and quickly convert text to tables in Microsoft Word, you should insert common separators between the text columns. The common separators or delimiters used when converting a table to text include tabs, paragraph marks, or commas.

Tabs or commas are used to indicate where the texts are divided into table columns while paragraph marks indicate where a new table row begins.

6 0
3 years ago
A(n) _____ is a common output device for hard copy.
Sidana [21]
The answer is d it is d it is d I think I think, I’m not sure though
8 0
3 years ago
What is the fullform of BIT​
Natalija [7]

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

The full Form of BIT is "Binary digit" which is the basic unit of information in computing . A Binary digit can be 0 or 1 . 0 represents off state & 1 represents on state .

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

8 0
2 years ago
Other questions:
  • When employees are hired, they agree to only use cell phones during breaks. How would you classify this?
    8·2 answers
  • Two different names that refer to the same data item best defines:
    12·1 answer
  • 11.
    11·1 answer
  • Write a program that computes the monthly net pay of the employee for a steel factory. The input for this program is the hourly
    10·1 answer
  • Ternary operators of computer<br><br>please explain. ​
    15·1 answer
  • python A pet shop wants to give a discount to its clients if they buy one or more pets. The discount is equal to 20 percent of t
    12·1 answer
  • _____________________ denotes the use of human interactions to gain any kind of desired access. Most often, this term involves e
    11·1 answer
  • , 13 dB correspond to a power ratio of ....?
    14·1 answer
  • All dogs = 199999990158161231
    11·2 answers
  • PLZZZ HELP!!!
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!