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]
3 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]3 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
When Adobe Photoshop was released for the first time? A: 1984 B: 1990 C: 1991 D: 1992
Natalija [7]

Answer:

B

Explanation:

4 0
3 years ago
A company has recently learned of a person trying to obtain personal information of employees illegally. According to which act
Juli2301 [7.4K]

Answer

Digital Millennium Act

Explanation

The Digital Millennium Copyright Act  is a United States copyright law that implements two  treaties of the World Intellectual Property Organization . The aim of this ACT is to protect the rights of both copyright owners and consumers. The law complies with the World Intellectual Property Organization  Copyright. The law has two basic functions. First, it protects copyright owners by providing them with a mechanism to enforce their rights without having to directly sue the infringer

7 0
2 years ago
Read 2 more answers
Universal containers wants to rollout new product bundles with several pricing options. Pricing options include product-price bu
ololo11 [35]

Answer:

a) Custom AppExchange-app for product-pricing

Explanation:

We can find a solution in AppExchange for this product-pricing, surfing in the option, we could get solutions like BoonPlus, and easy pricing Opportunity, this App has a free trial.

With this option is easy to choose a book price, add new products, select pricing rule, we can get an order's product, and calculate pricing, just we must download the app and install it.

6 0
3 years ago
You create a storyboard at the _____ stage of web development
ddd [48]

Answer:

initial stage of web development.

4 0
3 years ago
Read 2 more answers
Reading is the process of transferring data, instructions, and information from memory to a storage medium.
maksim [4K]
True, the computer will read from, say, a blu-ray and then transfer it to your RAM to before writing it to your hard drive and then, through the various other wonders of computers, it can be displayed on your monitor.
8 0
3 years ago
Other questions:
  • ORANGE COLORED SIGNS AND FLAGS MEAN THAT YOU MUST BE ALERT FOR:
    8·2 answers
  • What kind of battery does a dji spark have?
    12·1 answer
  • Write a program in which given an integer num, return the sum of the multiples of num between 1 and 100. For example, if num is
    7·1 answer
  • Heidi uses her computer to write articles for a newspaper. She uses a program to listen to the articles before she submits them
    5·1 answer
  • If you were required to give a speech identifying the risks of using computers and digital devices, which group of items would y
    7·1 answer
  • L00000000000000000000000000000000000000000000000000000000l they b00ty tickled
    6·2 answers
  • Kaitlin likes a particular design theme, but she is not sure about every single color for bullets, backgrounds, etc. found in th
    7·1 answer
  • What kind of energy transformation occurs when you call someone on a cell phone?
    11·1 answer
  • A trace table is used for
    5·2 answers
  • An online bank wants you to create a program that shows prospective
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!