0% found this document useful (0 votes)
9 views

BA.Python_Prog-NEP-2024-Scheme (2)

The document states that the training data is current only up to October 2023. No additional information or context is provided. It emphasizes the limitation of the data's recency.

Uploaded by

Sahana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

BA.Python_Prog-NEP-2024-Scheme (2)

The document states that the training data is current only up to October 2023. No additional information or context is provided. It emphasizes the limitation of the data's recency.

Uploaded by

Sahana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Q.P.

Code – 11E403/2211E403
Fourth Semester B.A./BSc./B.Com./B.B.A/B.S.W. Degree
Examination, August/September 2024
(UG-NEP -Scheme)

Computer Science

PYTHON PROGRAMMING CONCEPTS


SCHEME
[Time :2 Hours] [Max. Marks : 60]

Instructions to Candidates : Answer All the Sections.

SECTION – A

I. Answer any SIX questions : (6 x 2 = 12)

1. Define High level and machine level languages.


High level language is a programming language Programmers can easily understand
or interpret or compile in comparison of machine. On the other hand, Machine can
easily understand the low level language in comparison of human beings. Examples
of high level languages are C, C++, Java, Python, etc.

2. Differentiate between a assembler and an interpreter.


Interpreter: A interpreter takes in the basic instructions and converts them into pattern
of bits that the computer program can use to perform basic operations.
Interpreter: An interpreter translates code written in a high-level programming language
into machine code line-by-line as the code runs.

3. Define Python. Mention any one application of Python.

Definition – Python is a high level programming language that contains the feautures
of functional programming language like C and object oriented programming language
like java.
Applications –
Web Development.
Game Development.
Machine Learning and Artificial Intelligence.
Data Science and Data Visualization.

4. Define keywords and identifiers.


Keywords are the reserved words with a special meaning. Eg. Elif, else, except.
Identifiers are the user-defined names of variables, functions, etc.
Q.P. Code – 11E403/2211E403

5. What is indentation? Justify.

Most of the programming languages like C, C++, Java use braces { } to define a
block of code. Python uses indentation. A code block (body of function, loop etc.)
starts with indentation & ends with the first unindented line. The amount of
indentation is up to you, but it must be consistent throughout that block. Generally,
four white spaces are used for indentation and is preferred over tabs.

e.g.: for i in
range(1,11):
print(i)

if i == 5: break
6. Define range () with its syntax.
The range data type represents a sequence of numbers. The numbers in the range are
not modifiable.
Syntax : range(start, stop, step)
Start – an integer number specifying which position to start.
Stop – an integer number specifying which position to stop.
Step – an integer number specifying incementation.
r=range(10)
Here, the range object is created with the numbers starting from 0 to 9

7. Explain type conversions.


The process of converting a Python data type into another data type is known as type
conversion.
There are mainly two types of type conversion methods in Python:
 Implicit type conversion - In Implicit type conversion of data types in
Python, the Python interpreter automatically converts one data type to
another without any user involvement.
 Explicit type conversion - In Explicit Type Conversion in Python, the data
type is manually changed by the user as per their requirement. With
explicit type conversion, there is a risk of data loss since we are forcing an
expression to be changed in some specific data type.

8. What is the difference between break & exit?


exit() function in Python is used to terminate the program and exit to the command line.
Also exit() is a standard library function, while the break statement is used to exit a
loop prematurely. Break is a keyword.

SECTION - B
II. Answer any FOUR questions : (4 x 5 = 20)
Q.P. Code – 11E403/2211E403

9. Explain the features of Python.

The following are some of the important features of python:

 Simple Easy to learn: Python is a simple programming language. When we need a


python program, we feel like reading English sentences. Python programs use very
simple structure hence, developing and understanding programs will become easy.
 Open source: There is no need to pay for python software. Python can be freely
downloaded from WWW.python.org website. Its source code can be read, modified
and can be used in programs as desired by the programmers.
 High level language: Since python uses English words in its programs and hence it
is called high level programming language.
 Dynamically typed: In python, we need not declare anything. Statements binds a
name to an object and the object can be of any type.
 Platform independent: python programs are not dependent on any specific operating
system since python virtual machine (PVM), runs the byte code instructions on any
computer system. Hence python runs on almost all operating systems like UNIX,
Linux, Windows etc...
 Portable: When a program yields the same result on any computer in the world, then
it is called a portable program.
 Procedure and object oriented: Python is a procedure oriented as well as an object-
oriented programming language.
 Extensible: The programs written in C or C++ can be integrated into python and
executed using PVM.
 Scripting language: Python is considered as a scripting language like PHP as it is
interpreted and it is used on the internet to support other software.
 Database connectivity: python provides interfaces to connect its programs to all
major databases like Oracle, Sybase or MySQL.

10. Briefly explain different number systems.


There are four number systems –

 Binary Number System – In general, a binary number represents a 0 or 1 in the system. The
base or radix of the binary number system is 2. The possible digits that are used in a binary
number system are 0 and 1. If we wanted to store a binary number in python variable, that
number should starts with 0b.
 Octal Number System - The base or radix of the octal number system is 8. The possible
digits that are used in the octal number system are 0 to 7. To represent an octal number in
Python, the number should start with 0 (python2) or ox (python3).
 Decimal Number System - The base or radix of the decimal number system is 10. The
possible digits that are used in the decimal number system are 0 to 9. The default number
system followed by python is the decimal number system.
 Hexadecimal Number System - The base or radix of the hexadecimal number system is 16.
The possible digits that are used in hexadecimal number systems are 0 to 9 and a to f. To
represent a hexadecimal number in Python, the number should start with 0x.
Q.P. Code – 11E403/2211E403

11. What is an algorithm? Write an algorithm to find the sum of two numbers.

Algorithms are a set of instructions that are executed to get the solution to a given
problem.

Step 1 : Start.
Step 2 : Read A,B.
Step 3 : Sum = A + B.
Step 4 : Print Sum.
Step 5 : Stop.

12. Explain the format specifiers in python.


There are four different ways to perform string formatting in Python
 Formatting with % Operator.
 Formatting with format() string method.
 Formatting with string literals, called f-strings.
 Formatting with String Template Class
Formatting with % Operator
Strings in Python possess a unique built-in operator that is % operator. This % Operator, also known as Modulo or
Interpolation Operator, helps you do simple positional formatting in strings. This is the oldest method used
for string formatting, also known as C-Style String Formatting.

E.g., print('The value of pi is: %5.4f' %(3.141592))

Formatting with format() string method


Format() method was introduced with Python3 for handling complex string formatting more efficiently.
Formatters work by putting in one or more replacement fields and placeholders defined by a pair of curly
braces

{ } into a string and calling the str.format(). The value we wish to put into the placeholders and concatenate
with the string passed as parameters into the format function.

Syntax: ‘String here {} then also {}’.format(‘something1′,’something2’)

E.g., print('{2} {1} {0}'.format('directions','the', 'Read'))

Formatting with string literals, called f-strings


Python 3.6 added a new string formatting mechanism known as Literal String Interpolation or more commonly
as F-strings (because of the leading f character preceding the string literal). The idea behind f-String in
Python is to make string interpolation simpler.

To create an f-string in Python, prefix the string with the letter “f”. The string itself can be formatted in much the
same way that you would with str. format(). F-strings provide a concise and convenient way to embed
Python expressions inside string literals for formatting.

E.g., name =
'Ram'
print(f
"My
Q.P. Code – 11E403/2211E403
name
is
{name
}.")

Formatting with String Template Class


Template strings are not a basic language feature, but they’re made available by the string module in the standard
library. To use template class need to import from Python's built-in string module to implement string
formatting. Template strings don’t allow format specifiers instead they use placeholder names formed by $
with valid Python identifiers.

E.g., from string


import
Template n1
= 'Hello'

n2 = 'GeeksforGeeks'

n = Template('$n3 ! This is $n4.')


print(n.substitute(n3=n1, n4=n2))

13. Explain any five string handling functions.


Python string is a sequence of Unicode characters that is enclosed in quotation
marks.

Function Name Description

capitalize() Converts the first character of the string to a capital (uppercase) letter

casefold() Implements caseless string matching

center() Pad the string with the specified character.

count() Returns the number of occurrences of a substring in the string

find() Returns the lowest index of the substring if it is found

format() Formats the string for printing it to console

isalnum() Checks whether all the characters in a given string is alphanumeric or not

14. Write a program to find factorial of a number.

# Input: An integer number


Q.P. Code – 11E403/2211E403

num = 6

# Initialize the factorial variable to 1


factorial = 1

# Calculate the factorial using a for loop


for i in range(1, num + 1):
factorial *= i

print(f"The factorial of {num} is {factorial}")

SECTION - C
III. Answer any FOUR questions : (4 x 7 = 28)

15. Explain different types of computers.

The types of computers.


 Super Computer
 Mainframe computer
 Mini Computer
 Workstation Computer
 Personal Computer (PC)
 Server Computer
 Analog Computer
 Digital Computer
 Hybrid Computer
 Tablets and Smartphone

16. Briefly explain different data types in python.

The following are the standard or built-in data types in Python:


 Numeric
 Sequence Type
 Boolean
 Set
 Dictionary
 Binary Types( memoryview, bytearray, bytes)

17. Convert :
(101101)2 = (45)10 (55)8 (2D)16
(AB5)16 = (101010110101)2 (5265)8 (2741)10
(307)10 = (100110011 )2

18. Define software. Explain the classification of software.


Q.P. Code – 11E403/2211E403

Definition Of Software - the software is a computer program that provides a set of


instructions to execute a user’s commands and tell the computer what to do. Software is
used to control a computer. There are 3 types of Software – System Software, Utility
software & Application software.

1. System software

 If you think of software as being in layers, the system software is the bottom layer: it
sits between the hardware and the application software.

 Operating systems like Windows, macOS, Android and iOS are examples of system
software. Operating systems are loaded into RAM when the device starts up, and have
access to the hard drive.

 System software coordinates the activities and functions of hardware and software,
and it controls the operations of computer hardware.

2. Utility software

 Utility software helps to manage, maintain and control computer resources.


Operating systems typically contain the necessary tools for this, but separate utility
programs can provide improved functionality.
 Utility software is always runs in the background and provides security and
optimisation to computer.
 Examples of utility programs are antivirus software, backup software and disk
tools.

3. Application software

 An application program (software application, or application, or app for short) is a


computer program designed to carry out a specific task other than one relating
to the operation of the computer itself, typically to be used by end-users.

 Anything that is not an operating system or a utility is an application or app. So a


word processor, spreadsheet, web browser, and graphics software are all examples of
application software, and they can do many specific tasks.

 You can remove and add applications on your computer using the operating system.

 Application software like a word processor regularly directs the operating system to
load and save files from and to the hard drive. When you are working on a file, it is
saved temporarily in the RAM. It is only when you choose to save it that it is written
to the hard drive.
Q.P. Code – 11E403/2211E403

19. Explain conditional statements available in python with syntax.


Conditional Statements are statements in Python that provide a choice for the control
flow based on a condition. It means that the control flow of the Python program will
be decided based on the outcome of the condition.
1. The if statement –
A one-way if statement executes the statements if the condition is true. The syntax for
a one- way if statement is:

if boolean-expression:
statement
• The reserved word if begins as if statement.
• The condition is a Boolean expression that determines whether or not the body will be
executed . A colon (:) must follow the condition.
• The block (one or more statements) is executed if the condition is true. The statements
within the block must be indented the same number of spaces from the left.

2. The if -else statement –


A two-way if-else statement decides which statements to execute based on
whether the condition is true or false. The syntax for a two-way if-else statement:
if boolean-expression: statement1
else:
statement2

3. if_elif_else statement –
In python we can define a series of conditionals (multiple alternatives) using if for the
first one, elif for the rest, until the final (optional) else for anything not caught by the
other conditionals.
Syntax :
if condition1:
Statement 1
elif condition2:
Statement 2

else:
Statement 3
Q.P. Code – 11E403/2211E403

20. What is function? Explain types of function.

A function is a block of organized, reusable code used to perform a single, related action.
Functions provide better modularity and a high degree of code reusing.

Basically, the functions are divided into four types :

1. Built-in functions – functions that are built into python. Eg:print()


2. User-defined functions – Functions defined by the programmers to reduce the
complexity of big programs and to use that function according to need.

3. Anonymous functions or Lambda functions - These functions are not declared in the
standard manner by using the def keyword. We can use the lambda keyword to create
small anonymous functions.
4. Recursion functions - A recursive function is one that invokes itself. Or A recursive
function is a function that calls itself in its definition. For example the mathematical
function, factorial, defined by factorial(n) = n*(n-1)*(n- 2)*...*3*2*1.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy