Mixed-up Code QuestionsΒΆ
Create a function password_maker(word_list)
that takes a list of words, word_list
and returns a string with the first and last character of
each word in a list. For example, password_maker("show", "me", "the", "money")
would return swmetemy
.
Write a function password_maker(word_list)
that takes a a list of words, word_list
and returns a string with the first and last character of each
word in a list. For example, password_maker(["show", "me", "the", "money"])
would return swmetemy
.
Create a function avg_rainfall(day_list)
that takes a list with the amount of rain for each day.
There are some problems with the equipment, so ignore days that have a negative number for the amount of rain. Calculate the average rainfall as the sum of the non-negative values divided by the number of non-negative values. If at least one day has a non-negative rainfall return Average: (average)
and otherwise return No rain
. For example, avg_rainfall([30,-2, 0])
should return Average: 15
and avg_rainfall([-3, -2])
should return No rain
.
Write a function avg_rainfall(day_list)
that takes a list with the amount of rain for each day.
There are some problems with the equipment, so ignore days that have a negative number for the amount of rain. Calculate the average rainfall as the sum of the non-negative values divided by the number of non-negative values. If at least one day has a non-negative rainfall return Average: (average)
and otherwise return No rain
. For example, avg_rainfall([30,-2, 0])
should return Average: 15
and avg_rainfall([-3, -2])
should return No rain
.
Create a function mix
that takes a list list1
and returns a new list with the first and last items from the original list swapped. For example, mix([3, 2, 1, 4]
should return [4, 2, 1, 3]
.
Write a function mix
that takes a list list1
and returns a new list with the first and last items from the original list swapped. For example, mix([3, 2, 1, 4])
should return [4, 2, 1, 3]
.
Create a function discount(price_list)
that takes a list of prices and returns a new list with the original price reduced by half.
Limit each price to two digits after the decimal by rounding to the closest value. Hint, you can use the round
function to do this.
Write a function discount(price_list)
that takes a list of prices and returns a new list with the original price reduced by half.
Limit each price to two digits after the decimal by rounding to the closest value. Hint, you can use the round
function to do this.
Create a function filter_a(word_list)
that takes a list of words, word_list
and returns a new list with only the words in word_list
that start with the letter a
.
For example, filter_a(['a', 'bye', 'above'])
should return ['a', 'above']
.
Write a function filter_a(word_list)
that takes a list of words, word_list
and returns a new list with only the words in word_list
that start with the letter a
.
For example, filter_a(['a', 'bye', 'above'])
should return ['a', 'above']
.
Create a function vocab_list
that takes two lists: terms
and vocab
. It should loop through the list of terms and add each item to
vocab
if it is not already in that list. It should return the list vocab
.
Write a function vocab_list
that takes two lists: terms
and vocab
. It should loop through the list of terms and add each item to
vocab
if it is not already in that list. It should return the list vocab
.