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 does limiting a company's scope benefit the company? A. It encourages the company to use division of labor. B. It makes it e
Luda [366]

Answer

It makes it easier to produce a high quality product.

Explanation

Project scope is the part of project planning that involves determining and documenting a list of specific project goals, deliverable, tasks, costs and deadlines. in Project management it  involves the planning and organization of a company's resources to complete a specific task, event, or action and is usually a one-time event. It is an activity that is engaged in for the primary purpose of making a profit. These activities includes things like  production, operations, marketing, and administration

6 0
3 years ago
Read 2 more answers
A(an)_______is built-in preset calculation. <br>formula <br> function <br>equation <br>AutoSum​
Yanka [14]

Answer:

Hello! The answer to your question is function I had the same question and got it right!

Explanation:

Hope this helped:)

3 0
2 years ago
The current in a resistor is 5.0 A, and its power is 60 W. What is the voltage?
alexandr1967 [171]

The voltage on a resistor will be "12 V".

According to the given question,

Current,

  • I = 5.0 A

Power,

  • P = 60

As we know the formula,

→ Power (P)= Current(I)\times Voltage (V)

or,

→              V = \frac{P}{I}

By putting the giving values, we get

→                  = \frac{60}{5}

→                  = 12 \ V

Thus the solution above is right.

Learn more about voltage here:

brainly.com/question/18883096

8 0
2 years ago
Read 2 more answers
What kind of word is the pronoun in bold letters?
tresset_1 [31]

Answer:

Subject

Explanation:

The kind of word that is pronoun in bold letters is "Subject".

In Example

We get our paychecks on Friday, and I always need mine.

There We and I are subjects.

5 0
3 years ago
Read 2 more answers
____ uses markup to define the structure and layout of a web document.
cupoosta [38]
HTML: Hyper Text Markup Language.

HTML is the markup language used for defining the structure, and very basics of a web page - one wouldn't be possible without this language!

HTML is combined with CSS (Cascading Style Sheet) to improve visuals, and combined with a language such as Javascript to add functionality and interaction with the web page.
8 0
3 years ago
Other questions:
  • It creates an SQL statement to find the project that has the most employees from the same department. If more than one project m
    11·1 answer
  • You have dinner with your family and tell them that you have taken bcis. your mother tells you that she is proud of you and that
    9·1 answer
  • When a workforce scheduling problems is formulated as an integer programming model, it has:?
    6·1 answer
  • Sandy's keyboard is not inputting data into her computer which key should she press to verify it is connected to her computer...
    11·1 answer
  • Which of the following statements is false? a. InputStream and OutputStream are abstract classes for performing byte-based I/O.
    7·1 answer
  • Website administrators relay on ______, which is data such as the number of users who commented on, shared, viewed, or liked web
    7·2 answers
  • One of the driving forces in operating system evolution is advancement in the underlying hardware technology.
    8·1 answer
  • The most common clefs for high notes are what?
    6·2 answers
  • Which of the following is NOT an algorithm?
    15·1 answer
  • in a small town, there are two providers of broadband internet access: a cable company and the phone company. the internet acces
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!