Question

In: Computer Science

- Create a list with 40 integer random numbers - With a function (def) create two...

- Create a list with 40 integer random numbers
- With a function (def) create two new lists from the list created by random numbers, in which on one are the even elements and on the other the odd elements - Create two variables with the length of both new lists and print the variables

All exercices must be done in Phyton

Solutions

Expert Solution

To create a list with random numbers we use the module named random.

Code:

import random
my_list=random.sample(range(100),40)

It creates a list my_list with 40 random integers in range 1 to 100.

Above screenshot shows the output of the code which has 40 random integers.

CODE:

Every line of the code is explained in the above pic

Above screenshot contains the code that creates the function of name lists to create two lists even,odd that contains even elements and odd elements from the list my_list created from numbers and two variables a,b to find the length of two lists..

Every time you run the above code it creates a lists with random integers.

OUTPUT1:

OUTPUT2:

ANY QUERIES REGARDING THE SOLUTION PLEASE COMMENT.


Related Solutions

Write a function that will accept a list of numbers and an integer (n). The function...
Write a function that will accept a list of numbers and an integer (n). The function should return a list containing every nth item from the input list, always starting with the first item in the list. The original list should not be modified. For example, if the function is passed the list [8, 3, 19, 26, 32, 12, 3, 7, 21, 16] and the integer 3, it will return the list [8, 26, 3, 16] If the function is...
Write a Scheme function that takes two integers and returns the list of all integer numbers...
Write a Scheme function that takes two integers and returns the list of all integer numbers between these two integers (inclusively) in increasing order. (numbers 10 20) (10 11 12 13 14 15 16 17 18 19 20) Please explain every step.
how to creat Create a text file that contains a list of integer numbers separated by...
how to creat Create a text file that contains a list of integer numbers separated by comma (numbers.txt). E.g. 3, 7, 5, 1, 11, 8,2, 6 2- how to Write a python program (minMax.py) to read the file numbers.txt and find the largest and smallest numbers in the file. (without using use min(), max()). calculate the average and output the results. 3-Use python file i/o, write a python program (fileCopy.py) that makes a copy of minMax.py (Read contents of minMax.cp...
create two random numbers between 1 and 6. if when the sum of two numbers are...
create two random numbers between 1 and 6. if when the sum of two numbers are added togethere their sum is less than 5 or greater than 12, output to the console: "you win". if is not, output "you lose" C++
Create a function that takes two numbers and a mathematical operator +, –, / , *...
Create a function that takes two numbers and a mathematical operator +, –, / , * and will perform a calculation with the given numbers. Examples: calculator(2, "+", 2) ➞ 4 calculator(2, "*", 2) ➞ 4 calculator(4, "/", 2) ➞ 2 Notes If the input tries to divide by 0, return: "Can't divide by 0!" Code in C++ language ...
Using python Create a function that inputs a list of numbers and outputs the median of...
Using python Create a function that inputs a list of numbers and outputs the median of the numbers. sort them and them show the output.
import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(")...
import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(") " + entry) return int(input(question)) plz explain this code
Create an integer to std_logic_vector function(i2std)
Create an integer to std_logic_vector function(i2std)
Challenge 4 – Random Integer in Range Write a function to return a random integer between...
Challenge 4 – Random Integer in Range Write a function to return a random integer between a minimum value and maximum value. var ival = IntRandomRange(, );
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT