Quiz - 10¶
Develop the function how_many_donuts
that takes n
, a positive integer, as a parameter,
and returns a string in the form of "Number of donuts: n"
, where n
is the value
passed to the function as an argument. However, if n
>= 10, how_many_donuts
will
return "many"
instead of n
.
Examples:
how_many_donuts(5)
-> "Number of donuts: 5"
how_many_donuts(23)
-> "Number of donuts: many"
Develop the function chain_of_extremes
that, given a string s
,
returns a string with the first two and last two letters of s
.
However, if the string has less than 2 letters, it returns an empty string.
Examples:
chain_of_extremes("palms")
-> "pams"
chain_of_extremes("a")
-> ""
Develop the function replace_first_character
that, given a string s
,
returns a string in which all occurrences of the first character in s
are replaced by “*”, except for the first one. Note:
use the method .replace(value_to_replace, new_value)
to solve the
exercise.
Examples:
replace_first_character("google")
-> "goo*le"
replace_first_character("donut")
-> "donut"
Develop the function combine_two_chains
that takes two strings as
arguments, a
and b
, and returns a new string in the following way:
The new string has to be a combination of
a
andb
.The new string will have the form
"<a> <b>"
, note the space between both.The new string will interchange the first two letters of
a
andb
.
Suppose that a
and b
have more than 2 characters.
For better clarification, see the following examples.
Examples:
combine_two_chains("mix", "pod")
-> "pox mid"
combine_two_chains("pezzy", "firm")
-> "fizzy perm"
Develop the function is_palindrome
that takes a string s
as
parameter and checks if s
is a palindrome or not, returning True
or
False
accordingly.
Examples:
is_palindrome("ivi")
-> True
is_palindrome("civil")
-> False
Develop the function count_occurrences
that takes two parameters:
phrase
and word
, both of type string. The function should return
the number of times that word
occurs in phrase
.
Examples:
count_occurrences("ana and mariana like amanatsu", "ana")
-> 3