CSCI 152: LAB 1
Skill set for this LAB:
- Use Top-Down Design
- Lists and Functions
- Testing programs
- Python Programming Practice
Problem 1
Write a function def compare(list_a, list_b) that accepts two lists of integers. The function counts
the number of odd numbers in the first list and the
number of ODD
numbers in the second list, and returns 1, if the first
list has more
odd
numbers, -1 if the second list has more odd numbers, and 0 if both lists
have the same amount of odd numbers.
Write a main program that testing your functon: randomly generate the list of size 15, range of integers from -10 to 10
Problem 2: Write a function def index_list(my_list, my_word)
that has two parameters - list of strings and additional string,
the function creates and returns the list of ALL positions string my_word appears in my_list.
Write main that first asks user to enter the number of students in class, then asks to enter the name for each students and store all names in
the list of string. Then the program is asking to enter the name to search. The program uses function index_list to find all positions that name
appears in the list
Problem 3:
Write a function def even_list(my_list) that has one parameter - list of integers. The function creates and returns TWO new lists: list of all
even elements from my_list, and list of all positions of even elements in my_list
Write a function def remove_even(my_list, even)
that has two parameters, list of integers, and list of all even elements in my_list.
Function removes all even elements from my_list.
Pay attention, you don't need to return an updated list, since Python will preserve the change that made in the function for the list parameter.
Write main to test your program.
Problem 4: Write a function that accepts
two parameters - list of integers and additional value. Function counts the number of times
the value appears in the list and returns the counter. Write the main program to test your function.
Write main to test your function