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
How many residues separate amino acids that are stabilized by hydrogen bonds in α helices?.
irina [24]

The numbers of residues separate amino acids that are stabilized by hydrogen bonds in α helices is  3.6 amino acid residues.

<h3>Why are amino acids called residues?</h3>

The  Amino acids are known to be compounds that are said to be called residues if there is  two or more amino acids that are known to be bond with each other.

Note that the amino group on one amino acid is one that tends to interacts with the carboxyl group and as such  form a peptide bond.

Therefore, The numbers of residues separate amino acids that are stabilized by hydrogen bonds in α helices is  3.6 amino acid residues.

Learn more about amino acids from

brainly.com/question/2526971

#SPJ1

5 0
1 year ago
What is the most efficient<br> form of transportation we<br> have?
alisha [4.7K]

Answer:

The bicycle is a tremendously efficient means of transportation. In fact cycling is more efficient than any other method of travel--including walking! The one billion bicycles in the world are a testament to its effectiveness

Explanation:

6 0
2 years ago
Read 2 more answers
The means by which you interact with any program on a computer is called the ____. Answer
Elodia [21]
User interface is the answer
4 0
3 years ago
Revenue xls en excel
igor_vitrenko [27]
Whast does this mean

5 0
3 years ago
In preparing categorical variables for analysis, it is usually best to a. combine as many categories as possible. b. convert the
Genrish500 [490]

Answer:

In the given question the correct option is missing, which can be described as follows:

"It transforms binary, null variables into the groups."

Explanation:

These variables are real variables, which could also take up a series of variables, that are either constrained or defined. This can be regarded as a listing. It is used to analyze and convert it, into binary in the following ways, and wrong choices can be described as follows:

  • In option a, It can't combine, it only converts.
  • Option b and Option c is wrong because, it can't convert numeric, it only convert binary number to dummy variables.

5 0
3 years ago
Other questions:
  • Using the merge method of the Map interface, which statement correctly updates the salesTotalByDept map of type Map to update th
    7·1 answer
  • Which three phrases describe a wireframe
    12·1 answer
  • Enables businesses and consumers to share data or use software applications directly from a remote server over the Internet or w
    6·1 answer
  • A computer is a multipurpose device that accepts input, processes data, stores data, and produces output, all according to a ser
    9·1 answer
  • The 8-bit ____ field is used by source network hosts and forwarding routers to distinguished classes or priorities in ipv6 packe
    11·1 answer
  • What is the importance of human flourishing to science and technology?​
    8·1 answer
  • Caroline is building an expert system for wartime defense. Which of these is true about the system she is building?
    14·1 answer
  • In the program below, which two variables have the same scope?
    9·2 answers
  • When can designers use rapid application development?
    8·1 answer
  • If you want to share information with individuals who are internal to your organization, which type of network would you want to
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!