Question

In: Computer Science

1. Write a python program to create a list of integers using random function. Use map...

1. Write a python program to create a list of integers using random function. Use map function to process the list on the expression: 3x2+4x+5 and store the mapped elements in another list. Now use filter to do sum of all the elements in another list.

2. Write a function that takes n as input and creates a list of n lists such that ith list contains first 10 multiples of i.

3. Write a function that takes a number as input parameter and returns the corresponding text in word. For example, on input 458, the function should return ‘Four Five Eight’. Use dictionary for mapping digits to their string representation.

4. Write a program to create two sets of integer type using random function. Perform following operations on these two sets:

a) Union

b) Intersection

c) Difference

d) Symmetric difference

Solutions

Expert Solution

Problem 1:

import random
def myfunc(x):
return 3*2+4*x+5

x = random.sample(range(10, 30), 5)
y = map(myfunc, x)
#convert the map into a list, for readability:
print(list(x))
print(list(y))

Output:

Poblem 2:

def myfunc():
n = int(input('Enter n: '))
requiredlist = []
for i in range(n):
templist = []
for j in range(1,11):
templist.append(i*j)
requiredlist.append(templist)
print(requiredlist)
  
myfunc()

Output:

Problem 3:

def myfunc(n):
numdict = {'1':'One','2':'Two','3':'Three','4':'Four',
'5':'Five','6':'Six','7':'Seven','8':'Eight','9':'Nine','0':'Zero'}
x = str(n)
ret = ""
for i in x:
ret = ret + numdict[i]+" "
return ret[0:len(ret)-1]
  
print(myfunc(458))

Output:

Problem 4:

import random
x = set(random.sample(range(10, 50), 10))
y = set(random.sample(range(10, 50), 10))
union = x.union(y)
intersection = x.intersection(y)
difference = x-y
symmetric = union-intersection

Output vaiables:

Hope this helps.


Related Solutions

USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
Python: How would I write a function using list comprehensions to list of integers into two...
Python: How would I write a function using list comprehensions to list of integers into two halves with the evens first, followed by odds? And on top of that, the numbers should be listed in their original order.
Write a  program in c++ using a map to create the following output. Here is the list...
Write a  program in c++ using a map to create the following output. Here is the list of students: 100: Tom Lee 101: Joe Jones 102: Kim Adams 103: Bob Thomas 104: Linda Lee Enter a student an ID to get a student's name: ID:  103 students[103] - Bob Thomas # of students: 5 Delete a student (Y or N)?  Y Enter ID of student to be deleted:  103 Here is the list of students after the delete: 100: Tom Lee 101: Joe Jones...
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Create a Python program that will take an unsorted list of 1000 integers and sort them...
Create a Python program that will take an unsorted list of 1000 integers and sort them using a bubble sort and an insertion sort. Your output should include displaying both sorted lists (from each algorithm) identifying each sorted list by the algorithm used.
#Write a program in Python that given a list of positive integers, return another list where...
#Write a program in Python that given a list of positive integers, return another list where each element corresponds to the sum of the digits of the elements o#f the given list. #Example: # input # alist=[124, 5, 914, 21, 3421] # output # sum=[7, 5, 14, 3, 18]
In python write a program that first creates a list with the integers 0 through 9...
In python write a program that first creates a list with the integers 0 through 9 and then traverses that list RECURSIVELY (no for/while loops allowed) and prints out the integers on the list. NOTE: creating the list does not have to be done recursively.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT