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

Python_Programming_Exam_Solutions_with_Section_C

Uploaded by

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

Python_Programming_Exam_Solutions_with_Section_C

Uploaded by

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

Python Programming Exam Solutions

Section A (10 x 2 = 20) - Short Answers

Define the term List.

- Definition: A list in Python is an ordered, mutable collection of elements that can store items of different data types.

- Characteristics: Lists are indexed and support slicing. Elements can be added, removed, or modified.

- Example: my_list = [1, 'apple', 3.14]

Write about Variable.

- Definition: A variable is a name given to a memory location that stores data. Variables in Python are dynamically typed,

meaning their type is inferred at runtime.

- Characteristics: Variable names can contain letters, numbers, and underscores, but cannot start with a number and are

case-sensitive.

- Example: x = 5

Define Reserve word.

- Definition: Reserved words or keywords in Python have predefined meanings and cannot be used as variable names

or identifiers.

- Examples: if, for, while, return, etc.

Write about Dictionary.

- Definition: A dictionary is a collection of key-value pairs, where each key is unique and maps to a value.

- Characteristics: Defined using curly braces {}. Keys are unique and immutable.

- Example: my_dict = {'name': 'Alice', 'age': 25}

Write about Type Coercion.

- Definition: Type coercion is the implicit conversion of one data type to another, such as automatically converting an

integer to a float during arithmetic operations.

- Example: result = 5 + 2.0 # result is 7.0

What is function?

- Definition: A function is a reusable block of code that performs a specific task. It is defined with the def keyword.

- Example: def greet(): print('Hello')

Write about Runtime Errors.


- Definition: Runtime errors occur during the execution of a program due to invalid operations, such as dividing by zero

or accessing a nonexistent file.

- Examples: ZeroDivisionError, FileNotFoundError.

Write note on Data Streams.

- Definition: Data streams are sequences of data used for input and output, such as reading from files or network

communication.

What is Class?

- Definition: A class is a blueprint for creating objects, defining properties and methods to model real-world concepts.

- Syntax: class MyClass: pass

Write about Inheritance.

- Definition: Inheritance allows a class to acquire attributes and methods from another class, facilitating code reuse.

Section B (5 x 5 = 25) - Brief Answers

Explain about Tuple.

- Definition: A tuple is an immutable, ordered collection in Python used to store related data.

- Characteristics: Defined with parentheses (). Elements cannot be modified, added, or removed once created.

- Advantages: Tuples are faster than lists and are hashable, making them suitable as dictionary keys.

- Example: coordinates = (10, 20)

Write a program using three built-in functions.

- Program demonstrating len(), max(), and sorted() functions:

- numbers = [3, 1, 4, 2]

- print('Length:', len(numbers)) # Output: 4

- print('Max:', max(numbers)) # Output: 4

- print('Sorted:', sorted(numbers)) # Output: [1, 2, 3, 4]

Write a program using List and Dictionary.

- Program to calculate and print the average grades for each student:

- students = {'Alice': [90, 85, 88], 'Bob': [70, 75, 80]}

- for name, grades in students.items():

- print(f'{name}: Average Grade = {sum(grades) / len(grades)}')

Write a note on Lambda.


- Definition: A lambda function is a small anonymous function defined with the lambda keyword.

- Characteristics: Accepts any number of arguments but only one expression.

- Example: add = lambda x, y: x + y

Write about dir() and help() functions.

- dir(): Lists all attributes and methods available for an object or module.

- help(): Provides a detailed description of an object, module, or function.

- Example: print(dir(str)), help(len)


Python Programming Exam Solutions

Section A (10 x 2 = 20) - Short Answers

Define the term List.

- Definition: A list in Python is an ordered, mutable collection of elements that can store items of different data types.

- Characteristics: Lists are indexed and support slicing. Elements can be added, removed, or modified.

- Example: my_list = [1, 'apple', 3.14]

Write about Variable.

- Definition: A variable is a name given to a memory location that stores data. Variables in Python are dynamically typed,

meaning their type is inferred at runtime.

- Characteristics: Variable names can contain letters, numbers, and underscores, but cannot start with a number and are

case-sensitive.

- Example: x = 5

Define Reserve word.

- Definition: Reserved words or keywords in Python have predefined meanings and cannot be used as variable names

or identifiers.

- Examples: if, for, while, return, etc.

Write about Dictionary.

- Definition: A dictionary is a collection of key-value pairs, where each key is unique and maps to a value.

- Characteristics: Defined using curly braces {}. Keys are unique and immutable.

- Example: my_dict = {'name': 'Alice', 'age': 25}

Write about Type Coercion.

- Definition: Type coercion is the implicit conversion of one data type to another, such as automatically converting an

integer to a float during arithmetic operations.

- Example: result = 5 + 2.0 # result is 7.0

What is function?

- Definition: A function is a reusable block of code that performs a specific task. It is defined with the def keyword.

- Example: def greet(): print('Hello')

Write about Runtime Errors.

You might also like