In the previous post I showed the first batch of exercises (1.-5.). Here are the next 5:
6. Define a function sum()
and a function multiply()
that sums and multiplies (respectively) all the numbers in a list of numbers. For example, sum([1, 2, 3, 4])
should return 10
, and multiply([1, 2, 3, 4])
should return 24
.
7. Define a function reverse()
that computes the reversal of a string. For example, reverse("I am testing")
should return the string "gnitset ma I"
.
8. Define a function is_palindrome()
that recognizes palindromes (i.e. words that look the same written backwards). For example, is_palindrome("radar")
should return True
.
9. Write a function is_member()
that takes a value (i.e. a number, string, etc) x
and a list of values a
, and returns True
if x
is a member of a
, False
otherwise. (Note that this is exactly what the in
operator does, but for the sake of the exercise you should pretend Python did not have this operator.)
10. Define a function overlapping()
that takes two lists and returns True if they have at least one member in common, False otherwise. You may use your is_member()
function, or the in
operator, but for the sake of the exercise, you should (also) write it using two nested for-loops.
So in number 6 is not necessary to ask for the numbers of the list?
LikeLike
The instructions didn’t specify it, so I didn’t include any kind of user input,
LikeLike
This sounds like the meme of the guy pointing his head hahahaha but yeah you have a point, thanks
LikeLiked by 1 person
LOL
LikeLike