ITWorks
L91709029N
www.it-works.io
contact@it-works.io
+355 4 562 9090
Programming Exercises
1 Write a function to check if a number is even.
(input 2: output True, input 3: output False)
2 Write a function to check if a number is palindrome.
(121 is palindrome, 321 is not)
3 Write a function to check if a number is power of 2.
(1, 2, 4 power of 2, 3 is not)
4 Write a function to convert a given string to all uppercase if it contains at least 2
uppercase characters in the first 4 characters.
5 Given a list iterate it and display numbers which are divisible by 5 and if you
find number greater than 150 stop the loop iteration
list1 = [12, 15, 32, 42, 55, 75, 122, 132, 150, 180, 200]
6 Write a function that takes a list of words and groups the words by their length
using a dictionary
Input: [‘Lorem, ‘ele’, ‘sit’, ‘incididunt’, ‘a’, ‘su’, ‘dom’, ‘ouch’, ‘ipsum’’]
Output:
{
1: [‘a’],
2: [‘su’],
3: [‘ele’, ‘sit’, ‘dom’]
5: [‘Lorem’, ‘ipsum’]
10: [‘incididunt’]
}
7 Create a class Person with first_name and last_name as constructor
parameters. The class should have a function get_fullname which returns the
person’s full name (first_name + last_name). Create another class Student,
inheriting from Person. Student’s get_fullname function should return students
full name followed by ‘-st.’