Write a program that will print out the length of each item in the list as well as the first and last characters of the item.
weather = ["sunny", "cloudy", "partially sunny",
"rainy", "storming", "windy", "foggy",
"snowy", "hailing"]
---
for condition in weather:
---
print("The word is", len(condition), "characters")
---
first_char = condition[0]
last_char = condition[-1]
---
print("The first character is: " + first_char)
print("The last character is: " + last_char)
Checkpoint9.12.2.
Write code to determine how many βtβs are in the following sentences.
phrases = ["My, what a lovely day today is!",
"Have you mastered cooking yet? A tasty treat could be in your future.",
"Have you ever seen the leaves change color?"]
---
for sentence in phrases:
---
print(sentence.count("t"))
Checkpoint9.12.3.
Although Python provides us with many list methods, it is good practice and very instructive to think about how they are implemented. Implement a Python function that works like the following:
count
in
reverse
index
insert
Checkpoint9.12.4.
Write a Python function that will take a list of 100 random integers between 0 and 1000 and return the maximum value. (Note: there is a builtin function named max but pretend you cannot use it.)
Checkpoint9.12.5.
Write a function sum_of_squares(xs) that computes the sum of the squares of the numbers in the list xs. For example, sum_of_squares([2, 3, 4]) should return 4+9+16 which is 29:
Checkpoint9.12.6.
Create a list of 100 random integers between 0 and 1000, and write code for the function called countOdd(lst) to count every odd number in the list
Checkpoint9.12.7.
Create a list of 100 random integers between -1000 and 1000, and write code for the function called sumEven(lst) to sum up all the even numbers in the list
Checkpoint9.12.8.
Create a list of 100 random integers between -1000 and 1000, and write code for the function called sumNegatives(lst) to sum up all the negative numbers in the list