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
Which of the following might a small local bakery hire a multimedia artist to do? (Select all that apply).
Temka [501]

Answer:

B and C

Explanation:

Multimedia artists create art, they do not program or do the cooking for the business.

7 0
4 years ago
Why can a CPU retrieve and process bits of data quickly?
skad [1K]

Answer: an Arithmetic Logic Unit (ALU) that knows how to add numbers

Explanation:

The CPU can process those instructions easily, thanks to a control unit that knows how to interpret program instructions and an Arithmetic Logic Unit (ALU) that knows how to add numbers. With the control unit and ALU combined, the CPU can process much more complex programs than a simple calculator.

7 0
3 years ago
Given a variable, polygon_sides, that is associated with a dictionary that maps names of polygons to number of sides, create a n
sveticcg [70]

Answer:

polygon_sides = {"Triangle" : 3,"Square" : 5}

n_polygons = {}

for key in polygon_sides:

   n_polygons[polygon_sides[key]] = key

print("Polygon sides: ", polygon_sides)

print("Names of polygons: ", n_polygons)

Explanation:

  • Initialize the polygon_sides dictionary.
  • Loop through polygon_sides dictionary and assign the associated names to n_polygons variable.
  • Display the polygon sides and the names of polygons.
3 0
3 years ago
Which of the following is NOT included in the entry career pathway?
SVETLANKA909090 [29]
Looking for jobs is NOT included in the entry career pathway. When you state entry career path, you need to reconsider what kind of job you are going to proceed in. 

Happy studying ^-^
3 0
3 years ago
Read 2 more answers
Analyze the given word pattern and choose the correct option.
frozen [14]

Answer:

The code for DOOR would be <u>3775</u>.

Explanation:

WORD - 9753

W - 9

O - 7

R - 5

D - 3

DOOR: 3775

5 0
2 years ago
Other questions:
  • One thing we might want to know, given an input to a chatbot, is if the input is a question.
    10·1 answer
  • Which one of the following words means most nearly the opposite of RANDOM? (remember,opposite)
    12·1 answer
  • Mobile Device Company (MDC) discovers that defamatory statements about its policies and products are being posted in an online f
    8·1 answer
  • Which of the following should you NOT do when using CSS3 properties to create text columns for an article element? a. make the c
    12·2 answers
  • Please help ASAP, will mark brainliest!
    10·1 answer
  • Which is a popular IRC chat service?
    8·1 answer
  • BRAINLIEST AND A LOT OF PTS Which line of code will only allow a symbol to be stored in a variable?
    12·2 answers
  • Modifying the column widths usually is done last because other formatting changes may affect the size of data in the cells in th
    10·1 answer
  • You compared each letter in the correct word to the letter guessed.
    5·1 answer
  • Ok it is important aspects which is perfect
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!