Lab Practice Lists in Python
Skill set for this LAB:
- Use Top-Down Design
- Lists and Functions
- Testing programs
Lab Practice
- Problem 1: In this program you will check the
expiration year of the prodcuts and create a list of expired, about to
expire and still good items. Write a program that reads a sequence of
integers, each integer represents the expiration year. Store the data in
one dimensional list. The program will ask to enter current year. The
program then will check expiration dates on all items and create three
different lists: expired (expiration year < current year), about_to_expire
(items with the expiration year equals to current year), still_good. The
program prints the sizes of each category and the values in each category.
-
Problem 2: Write a program that generates a list of student's GPAs. Honors
program requires GPA to be 3.5 or above. The program will create
two new lists: Honors and Regular. Honors will include all GPA that are
eligible for the Honors program and Regular will include the rest.
- Problem 3
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 4: Write a function
def separate(grades)
that has one parameter - list of grades in the class. The function creates
and RETURNS 3 new lists - list of failing grades (grades below 60), list
of A grades (90 and above) and the rest of the grades (between 60 and 89).
Write a program that randomly generates the list of grades of size 15,
calls function separate, and then prints THREE lists: failing grades, list
of A grades, and the rest of the grades.
- Problem 5:
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 main to test your program.
- Problem 6: 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