FYUG Even Semester Exam, 2025
Computer Science: Python Programming
UNIT-I
1. (a) How do you declare a variable in Python? [1 Mark]
In Python, variables are created the moment you assign a value to them
.
There is no command for declaring a variable; you simply use the assignment operator (=).
x = 5
name = "Knowlet"
1. (c) What is sequence data type? [1 Mark]
Sequence data types are a collection of similar or different data types that allow storing multiple values in an organized and efficient fashion
.
Examples include Strings, Lists, and Tuples.
2. (a) Mention the different features of Python programming language. [2 Marks]
- Easy to Read and Learn: Python has a simple syntax similar to the English language
.
- Interpreted Language: Python code is executed line by line, making debugging easier
.
- Dynamically Typed: You don't need to declare the type of variable; it is determined at runtime
.
- Large Standard Library: Provides a rich set of modules and functions for various tasks
.
2. (b) Difference between mutable and immutable data types. [2 Marks]
| Feature |
Mutable |
Immutable |
| Definition |
Objects whose state or content can be changed after creation. |
Objects whose state or content cannot be changed once created. |
| Examples |
List, Dictionary, Set. |
Int, Float, String, Tuple. |
3. (a) Discuss different built-in data types available in Python. [5 Marks]
Python provides several standard built-in data types categorized as follows
:
- Numeric Types: int, float, complex
.
- Sequence Types: list, tuple, range
.
- Text Type: str
.
- Mapping Type: dict
.
- Set Types: set, frozenset
.
- Boolean Type: bool
.
- Binary Types: bytes, bytearray, memoryview
.
UNIT-II
4. (a) How do you write a basic 'if' statement in Python? [1 Mark]
A basic 'if' statement uses the if keyword followed by a condition and a colon
.
The code block must be indented.
if x > 0:
print("Positive")
5. (a) Write the importance of indentation in Python conditional statements. [2 Mark]
Indentation is mandatory in Python to define the scope of loops, functions, and conditional blocks
.
While other languages use curly braces, Python uses whitespace to indicate which lines of code belong to a particular statement.
6. (a) Write the syntax and usage of 'break' and 'continue' statements. [5 Marks]
Break Statement: Used to terminate the loop entirely and move the control to the next statement after the loop
.
for i in range(5):
if i == 3: break
print(i) # Prints 0, 1, 2
Continue Statement: Used to skip the current iteration of the loop and move to the next iteration
.
for i in range(5):
if i == 3: continue
print(i) # Prints 0, 1, 2, 4
UNIT-III
7. (a) Define Python module. [1 Mark]
A Python module is a file containing Python definitions and statements (like functions and variables) that can be reused in other programs
.
7. (c) What is the purpose of the 'None' keyword? [1 Mark]
The None keyword is used to define a null value or no value at all
.
It is an object of its own data type (NoneType).
8. (a) Differentiate between list and tuple. [2 Marks]
| List |
Tuple |
| Mutable (can be changed). |
Immutable (cannot be changed). |
| Defined using square brackets []. |
Defined using parentheses (). |
9. (a) Discuss various string manipulation operations available in Python. [5 Marks]
- Concatenation: Joining two strings using the + operator
.
- Repetition: Repeating a string using the * operator
.
- Slicing: Accessing a part of a string using [start:stop:step]
.
- upper() / lower(): Converting the case of the string
.
- strip(): Removing whitespace from the beginning and end
.
UNIT-IV
10. (a) Why is 'def' keyword used in Python? [1 Mark]
The def keyword is used to define a user-defined function in Python
.
10. (b) What do you mean by the lifetime of a variable? [1 Mark]
The lifetime of a variable is the period during which the variable exists in memory
.
A variable's lifetime usually ends when the function in which it was defined returns.
11. (c) Write the general syntax to define a function in Python. [2 Mark]
def function_name(parameters):
"""docstring"""
statement(s)
return expression
12. (b) Demonstrate the concept of pass by value and pass by reference. [5 Marks]
Python uses a mechanism called "Pass by Object Reference"
. If you pass a mutable object (like a list), it behaves like pass by reference. If you pass an immutable object (like an integer), it behaves like pass by value.
UNIT-V
13. (b) Write down the purpose of tell() method. [1 Mark]
The tell() method returns the current file pointer position (the number of bytes from the beginning of the file)
.
13. (d) What is matplotlib? [1 Mark]
Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations (graphs and plots) in Python
.
15. (a) Write a Python program to show exception handling. [5 Marks]
try:
num = int(input("Enter a number: "))
result = 10 / num
except ZeroDivisionError:
print("Cannot divide by zero!")
except ValueError:
print("Invalid input! Enter an integer.")
else:
print("Result is", result)
finally:
print("Execution complete.")
Exam Success Strategy
- Syntax Matters: Python is strict about indentation. In your exam, use a clear margin for indented blocks.
- Data Types: Be ready to compare Lists and Tuples—it's a favorite question
.
- Control Flow: Always use colons (:) at the end of
if, for, and while statements .
- File Handling: Remember that
tell() gives the position, while seek() changes it .
Frequently Asked Formulas
Factorial (n!) = n * (n-1) * (n-2) * ... * 1
String Slicing = string[start : stop : step]