0% found this document useful (0 votes)
31 views13 pages

PP Model Answer

Uploaded by

Naresh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views13 pages

PP Model Answer

Uploaded by

Naresh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

MODEL PAPER

End Semester Examination, June -2023

Program: BCA-IV
Semester: Fourth
Course: Python Programming
Course Code: 3C.274

UNIT-I
SECTION A
(EACH QUESTION CARRIES 5 MARKS )

1. What is Python and Is Python - Interpreted and (Byte) Compiled language?


[CO1- Remember]
2. What are keywords and also write the name of all the keywords of Python.
[CO1- Remember]
3. Define single-line comment & multi-line comment along with an example.
[CO2- Understand]
SECTION B
(EACH QUESTION CARRIES 10 MARKS )
4. What is an operator and what are the different arithmetic operators in python along with an
example of each. [CO4- Apply]
5. Describe logical operators & its types in python along with an example of each.
[CO2- Understand]
6. What is set? What are the different ways of representation of a set with an example of
each?[CO2- Understand]

7. Describe Indentation in Python along with an example. [CO2- Understand]

8. Write a python program showing that Set and Dictionary datatypes do not allow duplicate
elements (But List and tuple datatypes allow duplicate elements). [CO3- Create]

SECTION C
(EACH QUESTION CARRIES 20 MARKS )
9. Describe the different data types in Python with examples.[CO2- Apply]
Python supports several built-in data types. Here are the main data types in Python:

1. **Numeric:** Numeric data types in Python include integers (`int`), floating-point


numbers (`float`), and complex numbers (`complex`). Examples of numeric data types
are `3` (an integer), `3.14` (a float), and `2 + 3j` (a complex number).

2. **Boolean:** The Boolean data type in Python is `bool`, which has two possible values:
`True` and `False`. Example: `True`.

3. **String:** A string is a sequence of characters, enclosed in single quotes (`'...'`) or double


quotes (`"..."`). Examples are `'hello'` and `"Python"`.

4. **List:** A list is a collection of items, enclosed in square brackets (`[...]`). Lists can
contain items of different data types and can be modified after creation. Example: `[1,
2, 'three', 4.5]`.

5. **Tuple:** A tuple is similar to a list, but it is immutable (cannot be modified after


creation) and is enclosed in parentheses (`(...)`). Example: `(1, 'two', 3.0)`.
6. **Set:** A set is a collection of unique items, enclosed in curly braces (`{...}`) or created
using the `set()` function. Example: `{1, 2, 3}`.

7. **Dictionary:** A dictionary is a collection of key-value pairs, enclosed in curly braces


(`{key1: value1, key2: value2, ...}`) or created using the `dict()` function. Example:
`{'name': 'John', 'age': 30, 'city': 'New York'}`.

These are the most commonly used data types in Python. There are also additional
built-in data types, such as bytes, bytearrays, and None. Additionally, Python allows
you to create your own custom data types using classes.

10. (i) Write a python program to perform different arithmetic operations on numbers in
python. [CO3- Create]
# declare two variables and assign values
a = 10
b=5

# perform addition
result = a + b
print("Addition of a and b is:", result)

# perform subtraction
result = a - b
print("Subtraction of b from a is:", result)

# perform multiplication
result = a * b
print("Multiplication of a and b is:", result)

# perform division
result = a / b
print("Division of a by b is:", result)

# perform integer division


result = a // b
print("Integer division of a by b is:", result)

# perform modulo
result = a % b
print("Modulo of a by b is:", result)

# perform exponentiation
result = a ** b
print("a raised to the power of b is:", result)

output:
Addition of a and b is: 15
Subtraction of b from a is: 5
Multiplication of a and b is: 50
Division of a by b is: 2.0
Integer division of a by b is: 2
Modulo of a by b is: 0
a raised to the power of b is: 100000

(ii) Write a python program to find largest of three numbers. [CO3- Create]
# declare three variables and assign values
a = 10
b = 20
c = 15

# check which is the largest number


if a >= b and a >= c:
largest = a
elif b >= a and b >= c:
largest = b
else:
largest = c

# print the largest number


print("The largest number is:", largest)

output:
The largest number is: 20

11. (i) Python program to add and update Items in a Set. [CO3- Create]
(ii) Python program to remove Items from a Set. [CO3- Create]
UNIT II
SECTION A
(EACH QUESTION CARRIES 5 MARKS )

12. Write a program to print “Hello” five times. [CO2- Apply]


13. Give the output of the following :-
(i) >>>
print(“Hello”)

(ii) >>>
print(156 % 7)
(iii) >>> print((34 < 20) and ( 2 == 4))

(iv) >>> print( -2 * 4 + 3 * * 2)


(v) >>> print( -2 * 3 + 3 % 2) [CO4- Evaluate]

SECTION B
(EACH QUESTION CARRIES 10 MARKS )

14. Write a python program to find factorial of a number using recursion. [CO3- Create]
15. Write a short note on Conditional statements in Python along with suitable examples.
[CO2- Apply]
16. Justify how Lists are mutable in nature through an example.[CO2- Apply]
17. Justify how Tuples are immutable in nature through an example.[CO2- Apply]

18. Describe Nested if statement & Switch statement in python along with an example of
each. [CO2- Apply]

19. Describe if-elif-else ladder statement & Switch statement in python along with an
example of each. [CO2- Apply]

20. Describe looping statements in python along with an example of each. [CO2- Apply]
21. What is a Jump statement. Also,Explain return statement & pass statement in Python along
with an example of each. [CO2- Apply]
22. Explain break statement, continue statement & goto statement in Python along with an
example of each. [CO2- Apply]

SECTION C
(EACH QUESTION CARRIES 20 MARKS )

23. (i) Write a python program to print prime numbers less than 20. [CO3- Create]
# function to check if a number is prime

def is_prime(n):

if n < 2:

return False

for i in range(2, int(n**0.5) + 1):

if n % i == 0:

return False

return True

# loop through numbers less than 20 and print primes

print("Prime numbers less than 20:")

for i in range(2, 20):

if is_prime(i):

print(i)

(ii) Write a python program to create, append and remove lists in python. [CO3- Create]
# create an empty list
my_list = []

# append elements to the list


my_list.append(1)
my_list.append(2)
my_list.append(3)

# print the list


print("After appending elements, the list is:", my_list)

# remove an element from the list


my_list.remove(2)

# print the list again


print("After removing an element, the list is:", my_list)

output:
After appending elements, the list is: [1, 2, 3]
After removing an element, the list is: [1, 3]

UNIT III

SECTION A
(EACH QUESTION CARRIES 5 MARKS )
24. Differentiate between JAVA and PYTHON. [CO1-Remember]
25. Describe the types of prompts exist in the Python language with an example of each.
[CO2- Apply]
26. What is string? What are the different ways of representation of a String with an
example of each? [CO2- Apply]
SECTION B
(EACH QUESTION CARRIES 10
MARKS)

27. What is tuple? What are the different ways of representation of tuple with an
example of each? [CO2- Apply]
28. What is List? What are the different ways of representation of List with an example
of each?[CO2- Apply]

29. Describe Dictionary datatype along with an example. [CO2- Apply]


30. Difference between Positive indexing & Negative indexing along with an example of
each. [CO2- Apply]

31. Describe Python built-in functions along with an example of each. [CO2- Apply]
32. Difference between raw_input( ) method & input( ) method along with an example of
each. [CO2- Apply]
SECTION C
(EACH QUESTION CARRIES 20 MARKS )

33. (i) Describe list slicing technique of python along with an example . [CO2- Apply]
List slicing is a feature in Python that allows you to extract a subset of a list by specifying a range of
indices. The syntax for list slicing is as follows:

list[start:stop:step]

Here is an example of how to use list slicing in Python:

python

# Define a list of numbers

numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

# Get the first three elements using slicing

first_three = numbers[:3]

print(first_three) # Output: [0, 1, 2]

# Get the last four elements using slicing

last_four = numbers[-4:]

print(last_four) # Output: [6, 7, 8, 9]

# Get every other element using slicing

every_other = numbers[::2]

print(every_other) # Output: [0, 2, 4, 6, 8]

# Reverse the list using slicing

reversed_list = numbers[::-1]

print(reversed_list) # Output: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

(iii) Find the output of the following python program:- [CO4- Evaluate]

List1=[52,1,3,40,5,6,7,8,11]
print("\nOriginal List:\n")
print(List1)

print(List1[4:9:5])
print(List1[-5::1])
print(List1[::2])

List2=List1[::3] + List1[1::2]
print(List2)

Original List:

[52, 1, 3, 40, 5, 6, 7, 8, 11]


[5]
[6, 7, 8, 11]
[52, 3, 5, 7, 11]
[52, 40, 6, 8, 1, 5, 7, 11]

UNIT IV
SECTION A
(EACH QUESTION CARRIES 5 MARKS )

34. Describe the file’s built-in method (i.e write( string) ) using an example.
[CO2- Apply]
35. Describe the file’s built-in method (i.e Open() ) and also different types of access
mode using an example. [CO2- Apply]
SECTION B
(EACH QUESTION CARRIES 10 MARKS )

36. Explain different Files built-in Methods in Python.[CO2- Understand]

37. Write a Python program to find largest number in a list. [CO3- Create]

38. Write a python program to convert temperature to and from Celsius to Fahrenheit.
[CO3- Create]

SECTION C
(EACH QUESTION CARRIES 20 MARKS )

39. (i) Write a Python function to implement pow (x, n). [CO3- Create]

# Python3 program for the above approach


def power(x, n):

# initialize result by 1
pow = 1

# Multiply x for n times


for i in range(n):
pow = pow * x

return pow

# Driver code
if __name__ == '__main__':

x=2
n=3

# Function call
print(power(x, n))

Output
8

(ii) Write a short note on File Handling in Python along with an example. [CO2- Apply]
File handling is an essential part of programming that allows you to read and write data to and
from files. Python provides several built-in functions and modules to work with files, including the
`open()` function, which is used to open a file and return a file object that can be used to read or
write data to the file.

Here's an example of how to use file handling in Python to read data from a text file and print it to
the console:

```python
# Open the file in read mode
file = open('example.txt', 'r')

# Read the contents of the file


content = file.read()

# Print the contents to the console


print(content)

# Close the file


file.close()

40. Write a python program to run a SQL Query by connecting Python with mySql database?
[CO3- Create]
Prepared By: Shashank Sawan Reviewed By:

Disclaimer : This is a Model Paper. The Question in End term examination will differ from the
Model Paper. This Model paper is meant for practice only .

You might also like