Python Practical Questions For HND Pearson
Python Practical Questions For HND Pearson
Duration : 3 hours
Note : Create separate python files for each question and add them to a one folder with
naming the folder with your index number and send it to tharaka.m@esoft.lk before 4.00pm.
1. Write a Python program to print the following string in a specific format (see
the output).
Sample String : "Twinkle, twinkle, little star, How I wonder what you are! Up
above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star,
How I wonder what you are" Output :
Twinkle, twinkle, little star,
How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are
2. Write a Python program to get the Python version you are using.
4. Write a Python program which accepts the radius of a circle from the user
and compute the area.
Sample Output :
r = 1.1
Area = 3.8013271108436504
5. Write a Python program which accepts the user's first and last name and
print them in reverse order with a space between them.
7. Write a Python program to accept a filename from the user and print the
extension of that.
Sample filename : abc.java
Output : java
8. Write a Python program to display the first and last colors from the following
list.
color_list = ["Red","Green","White" ,"Black"]
10. Write a Python program that accepts an integer (n) and computes the
value of n+nn+nnn.
Sample value of n is 5
Expected Result : 615
12. Write a Python program to print the calendar of a given month and year.
Note : Use 'calendar' module.
13. Write a Python program to print the following here document.
Sample string :
a string that you "don't" have to escape
This
is a ....... multi-line
heredoc string --------> example
16. Write a Python program to get the difference between a given number and
17, if the number is greater than 17 return double the absolute difference.
18. Write a Python program to calculate the sum of three given numbers, if the
values are equal then return three times of their sum.
19. Write a Python program to get a new string from a given string where "Is"
has been added to the front. If the given string already begins with "Is" then
return the string unchanged.
21. Write a Python program to find whether a given number (accept from the
user) is even or odd, print out an appropriate message to the user.
22. Write a Python program to count the number 4 in a given list.
28. Write a Python program to print all even numbers from a given numbers
list in the same order and stop the printing if any numbers that come after 237
in the sequence.
Sample numbers list :
numbers = [
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978,
328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866,
950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379,
843, 831, 445, 742, 717,
958,743, 527
]
29. Write a Python program to print out a set containing all the colors from
color_list_1 which are not present in color_list_2.
Test Data :
color_list_1 = set(["White", "Black", "Red"])
color_list_2 = set(["Red", "Green"])
Expected Output :
{'Black', 'White'}
30. Write a Python program that will accept the base and height of a triangle
and compute the area.
32. Write a Python program to get the least common multiple (LCM) of two
positive integers.
34. Write a Python program to sum of two given integers. However, if the sum
is between 15 to 20 it will return 20.
35. Write a Python program that will return true if the two given integer values
are equal or their sum or difference is 5.
36. Write a Python program to add two objects if both objects are an integer
type.
37. Write a Python program to display your details like name, age, address in
three different lines.
38. Write a Python program to solve (x + y) * (x + y).
Test Data : x = 4, y = 3
Expected Output : (4 + 3) ^ 2) = 49
40. Write a Python program to compute the distance between the points (x1,
y1) and (x2, y2).
46. Write a python program to get the path and name of the file that is
currently executing.