1. Engineering
  2. Computer Science
  3. python code 1 this question practices the use of a...

Question: python code 1 this question practices the use of a...

Question details

Python code:

1. This question practices the use of a list method. Assign to the variable grades a list of 10 letter

grades from among ‘A’, ‘B’, ‘C’, ‘D’, and ‘F’. For example:

grades = [‘A’, ‘F’, ‘C’, ‘F’, ‘A’, ‘B’, ‘A’, ‘C’, ‘A’, ‘B’]

Write a Python expression that creates a list named frequency, in which the elements are the

number of times each of the letters A, B, C, D and F appear in grades. For example, for the above value

of grades, the following would be correct output:

frequency = [4, 2, 2, 0, 2]

Your expression must give the correct values for any list of grades, not just the one in your list. Hint:

use the list method count.

2. This question practices list membership, list indexes and list slices.

a. Write a Python statement that creates a list named dog_breeds that contains the elements

‘collie’, ‘sheepdog’, ‘Chow’, and ‘Chihuahua’ in the order given.

b. Write a Python statement that uses list slicing to create a list herding_dogs that is made up of

the first two elements of dog_breeds.

c. Write a Python statement that uses list indexing to create a list tiny_dogs that is made up of

the last element of dog_breeds.

d. Write a Python statement that tests whether ‘Persian’ is in the list dog_breeds and prints

either True or False depending on the answer.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution