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]
2 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]2 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
An access control system that grants users only those rights necessary for them to perform their work is operating on which secu
solmaris [256]

Answer:

B. Least privilege                

Explanation:

  • The principle of least privilege an important principle in computer security.
  • It limits the access rights for users and only grant them with the rights that are sufficient for them to perform their required task.
  • For example a user is granted privilege to execute a file or manipulate data or use only the resources that are required for them to perform a particular task.
  • This principle can be used only to limit and control access rights to system resources and applications.
  • The least privilege is beneficial as it reduces the risk of unauthorized access.
  • For example a user whose task is data entry and has nothing to do with controlling access or granting access rights to users, will only be allowed to enter data to the DB by the principle of least privilege.
7 0
3 years ago
It's best to use assertive speech when you<br> I want to show respect. *<br> True<br> False
mestny [16]

Answer:

True

Explanation:

Hope this helps :)

6 0
2 years ago
Read 2 more answers
What are some tasks for which you can use the VBA Editor? i need help for my computer class.
Murljashka [212]

Answer:

Visual Basic for Applications runs as an internal programming language in Microsoft Office applications such as Access, Excel, PowerPoint, Publisher, Word, and Visio. VBA allows users to customize beyond what is normally available with MS Office host applications by manipulating graphical-user-interface (GUI) features such as toolbars and menus, dialogue boxes, and forms. You may use VBA to create user-defined functions (UDFs), access Windows application programming interfaces (APIs), and automate specific computer processes and calculations. Macros can automate just about any task—like generating customized charts and reports, and performing word- and data-processing functions. Programmers,like replicating large pieces of code, merging existing program functions, and designing specific languages. VBA can also work in non-Microsoft settings by using a technology called "COM interface," which allows commands to interact across computer boundaries. Many firms have implemented VBA within their own applications, both proprietary and commercial, including AutoCAD, ArcGIS, CATIA, Corel, raw, and SolidWorks.

<em>(Hope this helps/makes sense!)</em>

6 0
3 years ago
A computer can manipulate symbols as if it understands the symbols and is reasoning with them, but in fact it is just following
Law Incorporation [45]

Answer:

The symbols may or may not have meaning, but the machine does not need to know how the symbols are interpreted in order to manipulate the symbols in the right way.

Explanation:

The computer can change the symbols in the case when the computer understand but in actual following the cut-paste rules without having any understanding this is because the symbols might be have meaning or not but if we talk about the machine so actually they dont know how the symbols are interpreted and how it can be used so that it can be change in the accurate way

5 0
2 years ago
Instructions:Select the correct answer.
Luba_88 [7]
<span>A.) system administrator

Hope that helps</span>
8 0
3 years ago
Read 2 more answers
Other questions:
  • What is an advantage of sharing documents in PDF format instead of Word format?
    6·2 answers
  • In the space below, write the formula that needs to be added to the blank cells under the fourth column of the table.
    13·1 answer
  • After trying multiple times, a coworker is not able to fit a motherboard in a computer case, and is having difficulty aligning s
    11·1 answer
  • Describe how catching exceptions can help with file errors. Write three Python examples that actually generate file errors on yo
    12·1 answer
  • Jared recently sent an email to all the members of his department asking them for their opinions about where the department shou
    11·1 answer
  • Which code must be included to use Turtle Graphics?
    14·2 answers
  • What are Manuscript signs​
    8·1 answer
  • For this assignment your are to implement the Pet Class described in Programming Exercise 1, starting on page 494 in our textboo
    6·1 answer
  • Using a wireless technology known as ___, many smartphones can now be tapped on special payment devices to complete your purchas
    13·1 answer
  • State four input device that are used for playing gaming programs​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!