CIT 101 Practical 04 Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Bachelor of Applied Information Technology

Module Code CIT101


Module Title: Fundamentals of Programming

Date: 27th February 2023

Practical 4 – Python Modules and Packages


The objective of this practical is to get familiarized with builtin-functions and standard library
modules in Python.

Before you start I suggest you study the following.

1. Supplement 1 Numeric Data


2. CIT 101 Py Lsn 2 Final
3. CIT 101 Py Lsn 3 Final
4. CIT 101 Py Lsn 4 Final
5. CIT 101 Py Lsn 5 Final
6. ICO 101 Py Lesson 6 Final
7. SUP 2 Formats

What do you learn?

We will learn the following:

 Built-in functions of Python


 Standard library and its modules
 How to use them in programs?

Built-in Module

 In any language you will have a set of short pre-written codes for the programmers
to use whenever they need. They are readily available and they are built into the
core of the Compiler/Interpreter.

 We can get a list of content in the built-in module as follows.

>>> dir (__builtins__)


['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError',
'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError',
'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning',
'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError',
'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning',
'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt',
'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError',

Page 1 of 4
Bachelor of Applied Information Technology
Module Code CIT101
Module Title: Fundamentals of Programming
'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning',
'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning',

'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning',


'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError',
'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError',
'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError',

'__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__',


'__spec__',

'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod',
'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit',
'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int',
'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next',
'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr',
'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']

 The first set (blue) is the exceptions (Something to do with errors).

 The second set (violet) is the attributes

 Third set (violet) is the built-in functions.

In lesson 6, there is a comprehensive description of the frequently used


functions. [At this moment we don't need all. We need a few of them only. But students
who want to be professional programmers would need them]

Therefore READ & UNDERSTAND Lesson 6 & Associated Videos as much as you could.

Practical 4 Submission

You have to submit all your workings to LMS clearly in a .pdf file by putting the file name as
follows. (Delete all error messages)

Module Code Registration number Pra4.pdf


Eg. CIT101- 22UG3 xxxx Pra3.pdf
You may discuss things with your friends, but do not copy. Copying will be a disqualification and you
will get 0 marks if you get caught. For late submissions, 10% of the marks will be deducted for each
day.

Time Allocated: As notified in the LMS

Page 2 of 4
Bachelor of Applied Information Technology
Module Code CIT101
Module Title: Fundamentals of Programming

Practical 4:

1. Using built-in functions (without import) in Python perform the following in the interactive mode.

Note: Use meaningful variable names, beautiful input prompts, and output descriptions.

Example:

Input a real (+ or – integer/floating point) number and display its absolute value.

>>> real_number = float(input("Enter a real number:"))


Enter a real number:-12.7
>>> print(f'The absolute value of the real number is {abs(real_number)}')
The absolute value of the real number is 12.7

a) Input a sentence and display its length.

b) Input a positive integer and display it in binary.

c) Input a reference number of an object in memory in decimal (e.g. 2463465499216) and


display it in hexadecimal.

d) Input your mail address and display the user name and the domain separately.

e) Input a complex number and display its type in Python.

f) Input five integers and display the maximum and the minimum numbers separately.

g) Input two integers and find the quotient and the remainder.

h) Input an uppercase letter and display its ASCII code. (E.g. 'A'  65)

2. Example:

Input a real number and display the difference between its ceiling value and floor value.

>>> import math


>>> real_num = float(input("Enter a number:"))
Enter a number:245.035
>>> print(f"Difference between the ceiling value and the floor value = {math.ceil(real_num)
- math.floor(real_num)}")
Difference between the ceiling value and the floor value = 1

Page 3 of 4
Bachelor of Applied Information Technology
Module Code CIT101
Module Title: Fundamentals of Programming

a) Input three integers and display their GCD (Greatest Common Divisor).

b) Input three integers and display their LCM (Least Common Denominator).

c) Input a finite, positive number and display its factorial.

d) Input the length of the hypotenuse of an isosceles right-angled triangle and display the
length of a side rounded to two decimal places.

e) A pipe repairman uses adhesive tape to repair cracks in some cylindrical pipes of
different diameters. Write a program to calculate the length of the tape needed as he
enters the diameter and the number of turns to cover each pipe

End of Practical 4

Page 4 of 4

You might also like