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
2. Which of the following functions adds a range of cells and then divides by the number of cell entries? *
postnew [5]
Hello Mate. Good Works!

Answer: B) Average
*The numbers entered will be divided.

Kind Regards
5 0
4 years ago
Read 2 more answers
Word provides a quicker way through the
Greeley [361]
You didn't finish your question 

4 0
4 years ago
A normal lens has
nekit [7.7K]
It has a larger field of view
8 0
3 years ago
In a server farm such as that used by Amazon or eBay, a single failure does not cause the entire system to crash. Instead, it wi
Jet001 [13]

Answer:12 days

Explanation:

Mean time to failure is given by

MTTF=\frac{Total working hours of running}{Total no. of units}

Let's say N is the average amount  of time system runs until \frac{1}{3} computer fail

MTTF of each computer =35

35=\frac{n\cdot 10,000}{10,000\cdot \frac{1}{3}}

35=N\cdot 3

N=\frac{35}{3}=11.667\approx 12days

8 0
3 years ago
Who coined the term web log for an online journal
astra-53 [7]
Jorn Barger did this
6 0
4 years ago
Other questions:
  • Define a function begins_with_line that consumes a string and returns a boolean indicating whether the string begins with a dash
    15·1 answer
  • A server core installation can't be converted to a minimal server interface.
    14·1 answer
  • Please select the word from the list that best fits the definition
    5·2 answers
  • When choosing a buffer to use for an experiment conducted at pH 5.3, it would be best to choose one with a pKa of: A.2.14. B.4.7
    14·1 answer
  • Which of the following is considered a benefit of using simulation programs? a. They allow users to experience potentially dange
    10·1 answer
  • Write a function called print_function that takes integer number as argument and prints the following pattern if input is 3
    14·1 answer
  • Mrs. Sims polled her students about which social media app they use most. Which type of chart would best display this data?
    9·1 answer
  • According to the video, what types of education are useful for Database Administrators? Check all that apply.
    5·2 answers
  • Can I control my digital footprint?
    9·2 answers
  • How to get someone off your best friends list without blocking them
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!