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 question is MOST important for an office to consider when upgrading to new software
Marina CMI [18]
Either B or D those are the most reasonable answers if it were up to me to answer i would pick B but that is up to you go ahead and try your best i hope u have a nice day ✨✌️✨
6 0
3 years ago
HELP!!!
jeyben [28]

Answer:

A. a tool tip

Explanation:

6 0
3 years ago
Read 2 more answers
c++ design a class named myinteger which models integers. interesting properties of the value can be determined. include these m
klemol [59]

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. class myinteger {
  4.    
  5.    private:
  6.        int value;
  7.        
  8.    public:
  9.        myinteger(int x){
  10.            value = x;
  11.        }
  12.        
  13.       int getValue(){
  14.           return value;
  15.       }
  16.        
  17. };
  18. int main()
  19. {
  20.    myinteger obj(4);
  21.    cout<< obj.getValue();
  22.    return 0;
  23. }

Explanation:

Firstly, we use class keyword to create a class named myinteger (Line 5). Define a private scope data field named value in integer type (Line 7 - 8).

Next, we proceed to define a constructor (Line 11 - 13) and a getter method for value (Line 15 -17) in public scope. The constructor will accept one input x and set it to data field, x. The getter method will return the data field x whenever it is called.

We test our class by creating an object from the class (Line 23) by passing a number of 4 as argument. And when we use the object to call the getValue method, 4 will be printed as output.

4 0
4 years ago
For most people, the most effective way to save is:
oksian1 [2.3K]
I would say it's by creating a spending budget. 
3 0
3 years ago
What kind of device does a computer need to provide information to a person or something else?
yanalaym [24]
An input device is something that gives information to the computer. On the other hand, an output device is something that gives you information.
7 0
3 years ago
Read 2 more answers
Other questions:
  • Which description best describes how mass spectroscopy is useful in the field of forensic toxicology
    6·1 answer
  • The desktops of computers running the same OS all look the same
    8·1 answer
  • Makes it possible to distribute both power and data using ethernet cabling. select one:
    12·1 answer
  • What could cause a fixed disk error.
    15·1 answer
  • 1. A microprocessor supports a single hardware timer. Suppose instruction SET_TIMER permits one to set the timer value1. Does th
    15·1 answer
  • A dietician wants you to write a program that will calculate the number of calories a person can lose by walking at a slow pace
    13·1 answer
  • Advancements in nuclear science have led to technological advances which are both harmful and beneficial. Which would be conside
    15·1 answer
  • Which communication device uses wireless data transmission? Select 4 options.
    8·1 answer
  • 5. Played electronically by manipulating images on a television screen produced by a
    15·1 answer
  • GIVING 50 POINTS!
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!