Lab 6
1. Palindrome number
Write a function to check if the given number is a palindrome number. The function returns True
or False. A palindrome number is a number that is same after reverse. For example 98189, is a
palindrome number. Write a program using that function.
2. Counting characters occurrences
Write a program counting occurrences of all characters within a string. For example, the input is
“Letter”, the output is {‘L’:1, ‘e’:2, ‘t’:2, ‘r’: 1}. Hint: use dictionary.
3. Counting word occurrences
Write a program counting occurrences of all words within a text. For example, the input is “I chose
the red color, because I like red”, the output is {“I”:2, “chose”:1, “the”:1, “red”: 2, “color”:1,
“because”:1, “like”:1}. Hint: use dictionary and function split(str) returning a list with each
element as a word in str.
4. Matrix multiplication
Write a function to multiply two matrices: A[n,m] and B[n,o]. Then, check the result by using the
Numpy library (function matmul()).
Hint: use nested list to represent matrix. For example, the list [[1,2], [3,4], [4,5]] represents a 3x2
matrix. Use the statement: X = [ [ 0 for i in range(m)] for j in range(n)] to create an empty matrix
X of n rows and m columns.
5. Evaluating and plotting polynomial
Write a function to evaluate a polynomial f(x), defined by its coefficients (c[0] + c[1].x + c[2].x2
+ ...), at a given point x. Hint: x**i computes xi. Then, check the result by using the Numpy library
(function polyval()).
Plot the polynomial with X = [-4, -3, -2, -1, 0, 1, 2, 3, 4]. Hint: use library Matplotlib.
For example, the graph of f(x) = 2x3 - x2 + 1 is illustrated in the figure bellow.