I have a program that was suppose to do the following:
Compute their Cartesian product, AxB of two lists. Each list has no more than 10 numbers.
For example, given the two input lists:
A = [1,2]
B = [3,4]
then the Cartesian product output should be:
AxB = [(1,3),(1,4),(2,3),(2,4)]
***********
The code that I have is this: (Thanks to other great answerers like you all)
What I need: Is for the code below to have the user prompted to enter the two list, not have them automatically entered.
def CartesianProduct(A,B):
lst = []
for x in A:
t = []
t.append(x)
for y in B:
temp = []
for x in t:
temp.append(x)
temp.append(y)
lst.append(temp)
return lst
A = [1,2]
B = [3,4]
print(CartesianProduct(A,B))
****
What I need: Is for the code above to have the user prompted to enter the two list, not have them automatically entered.
Here is the code to take input
A= list(map(int, input('Enter elements in list with spaces ').split()))
B = list(map(int, input('Enter elements in list with spaces ').split()))
Thus , u can pass the both lists A, B to the function named CartesianProduct().
IF YOU HAVE ANY DOUBTS PLEASE COMMENT.
If you like the answer please give THUMBS UP.
I have a program that was suppose to do the following: Compute their Cartesian product, AxB...
need java code. (d) is cartesian product rule.
Design a program to let user enter two lists of numbers within the range [0, 9] from keyboard, you could either use flag to denote end of the list or ask user to enter the list size first and then enter the list numbers. Each of these two lists represents a set (keep in mind that duplicate elements are not allowed in a set), so we have two sets A and B....
Directions: Write a code for the following programming exercise in PYTHON!!!!!!! -Design a program that lets the user enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Here is what i got so far, but for some reason this code only print the Minimum and Maximum. its not printing the Average. def...
Can someone fix this python program? I'm trying to do three things: Create a function that takes in a string as a parameter. Then create a dictionary of characters to integers, where the integer represents how many times the number of times the character appears in the word. Create a function that takes two lists as parameters and returns the elements they have in common of the two lists. Ask the user to create a list of numbers and keep...
Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...
How do you alter the following scanf statement in C? I have the following line of code: scanf("%[^.]s)", string); My problem is that this terminates the user input after the user enters a period, followed by Enter. for ex: Enter a string: Today is nice. How can I change this statement so that user would need to enter a new line, followed by a period and then press Enter so that the input would terminate? for ex. Enter a string:...
Hello, I need help with the following C code. This program asks the user to enter three numbers and outputs the sum on the screen , all im trying to do is have the program reprompt the user for a number if anything other than a number is entered for each of the entries. I wanted to use do while for each of the functions but that did not work for example: Enter Number 1: 2 Enter Number 2: Hello...
Phase 1 Requirements
Code submitted for Phase 1 will only have the following
capability. Any additional coding will result in the loss of
point.
code will have the main function, including looping until the
user enters input of 12
code will call the printMenu() function
theprintMenu() function will have the capability to print the
menu and receive input. AT THIS TIME do not worry
about implementing the try/except code
code will return the integer value (remember - the input()
function...
I need to create a Phyton program 1. Contains the following steps: a) Create a loop where you prompt the user to enter integers and calculate the average of the numbers entered. Exit the loop when the entered number is 0. b) Test Program_A works as designed. c) Use as a template Program_A, create a new file Program_B which uses a similar loop and calculates the max in the list. d) Test Progam_B
in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...
Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1) a.) [1, 2, 2, 2] b.) [1, 1, 1, 2] c.) [1, 2, 1, 2] d.) [1,...