PP Model Answer
PP Model Answer
Program: BCA-IV
Semester: Fourth
Course: Python Programming
Course Code: 3C.274
UNIT-I
SECTION A
(EACH QUESTION CARRIES 5 MARKS )
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:
2. **Boolean:** The Boolean data type in Python is `bool`, which has two possible values:
`True` and `False`. Example: `True`.
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]`.
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 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
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 )
(ii) >>>
print(156 % 7)
(iii) >>> print((34 < 20) and ( 2 == 4))
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
if n % i == 0:
return False
return True
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 = []
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]
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]
python
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
first_three = numbers[:3]
last_four = numbers[-4:]
every_other = numbers[::2]
reversed_list = numbers[::-1]
(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:
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 )
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]
# initialize result by 1
pow = 1
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')
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 .