Pakistan International School Jeddah - English Section
Y8-Computing
Unit 1.6: Library programs
Task 10 – Y8 -____ Total marks: 15 Marks obtained:
Name: Student ID: Date:
Library functions
Each programming language has its own programming libraries, you can think of a program library
as a code library, where you can get program code to use. Some libraries have a specific function
like mathematical library, graphic functions library or artificial intelligence.
To use a library in python at the start of your program you need to use command import then the
name of the library e.g. math.floor()
We will be using math library functions. Some of these functions include:
Floor
Ceiling
Pi
Floor function:
The floor() function rounds a number down to the nearest whole number e.g 4.55 4, 99.8563 99
1. Open a new file in script mode and save it by the name floor.py
2. Import math library, now take a number=2.6543 in next line.
3. Display “what is”, number, “ rounded down to the nearest whole number?”.
4. Take input for variable answer
5. If answer is math.floor(number) display Correct otherwise display Incorrect
6. Save and run the program with following inputs
2.83 12.65 03.5555 14.678
7. Take screenshot of all the outputs under evidence 1.
Evidence 1: Take the screenshot of python shell & script mode both and paste it in your
evidence file.
Y8-Computing 2024-25 Practical 10 1|Page
Ceiling function:
The ceil() function rounds a number up to the next whole number e.g. 22 22, 3.1 4
8. Open a new file in script mode and save it by the name ceiling.py
9. Import math library, now take a number=33.426 in next line.
10. Display “what is”, number, “rounded up to the nearest whole number?”.
11. Take input for variable answer.
12. If answer is math.ceil(number) display Correct otherwise display Incorrect.
13. Save and run the program with following inputs
34 38 47.52 26.12
14. Take screenshot of all the outputs under evidence 2.
Evidence 2: Take the screenshot of python shell & script mode both and paste it in your
evidence file.
pi function:
The math library has a function that will give you the value of pi e.g
circleCircumference=math.pi*diameter
Radius of circle ( π r 2 ¿ :
15. Open a new file in script mode and save it by the name pi_radius.py
16. Import math library, now take radius=2 in next line.
17. Calculate area of circle as area=(radius*radius) *math.pi
18. Display “The area is”, area
19. Save and run the program .
20. Take screenshot of the outputs under evidence 3.
Evidence 3: Take the screenshot of python shell & script mode both and paste it in your
evidence file.
Y8-Computing 2024-25 Practical 10 2|Page
diameter of circle ( 2r ):
21. Open a new file in script mode and save it by the name pi_diameter.py
22. Import math library, now take radius=10 in next line.
23. Calculate area of diameter 2*radius
24. Display “The diameter is”, diameter
25. Save and run the program with following inputs
1 4 10 12
26. Take screenshot of all the outputs under evidence 3.
Evidence 3: Take the screenshot of python shell & script mode both and paste it in your
evidence file.
27. Now calculate
28. Save and print your Evidence file. Make sure to add header with name, student Id and class.
Y8-Computing 2024-25 Practical 10 3|Page