Solution - Python Programming (203105211) Mid Sem
Solution - Python Programming (203105211) Mid Sem
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
B.TECH MID SEM EXAMINATION
3rd SEMESTER
ACY-2022-23
Python Programming Solution (203105211) Branch: CSE/IT
Date: 05/08/2022 Time: 2.30 PM to 4.00 PM Total Marks: 40
(2) In Python, we know that a function can call other functions. It is even possible for
the function to call itself. These types of construct are termed as recursive functions.
def factorial(x):
"""This is a recursive function
to find the factorial of an integer"""
Page 1 of 5
if x == 1:
return 1
else:
return (x * factorial(x-1))
num = 3
print("The factorial of", num, "is", factorial(num))
(3) The slice() constructor creates a slice object representing the set of indices
specified by range(start, stop, step).
Syntax:
slice(stop)
slice(start, stop, step)
s1 = slice(3)
s2 = slice(1, 5, 2)
s3 = slice(-1, -12, -2)
(4)
(2**3 + (19 // 6)**(1 + 1))
=(8 + (3)**(2))
=8+9=17
(5)
Python Lambda Functions are anonymous function means that the function is without
a name.
Syntax: lambda arguments: expression
Ex
tables = [lambda x=x: x*10 for x in range(1, 11)]
o/p: 10 20 30 40 50 60 70 80 90 100
Q.3 Attempt any two 08
(1) Python is used in many application domains. Here's a sampling:
Web Applications
We can use Python to develop web applications. It provides libraries to handle
internet protocols such as HTML and XML, JSON, Email processing, request,
beautifulSoup, Feedparser, etc. One of Python web-framework named Django is used
on Instagram.
Desktop GUI Applications
The GUI stands for the Graphical User Interface, which provides a smooth
interaction to any application.
Software Development
Python is useful for the software development process. It works as a support
language and can be used to build control and management, testing, etc.
Scientific and Numeric
Page 2 of 5
This is the era of Artificial intelligence where the machine can perform the task the
same as the human. Python language is the most suitable language for Artificial
intelligence or machine learning. It consists of many scientific and mathematical
libraries, which makes easy to solve complex calculations.
The ides I am using: pydev, sublime text, Visual Studio Code, Spyder etc
(2)
Functions that we define ourselves to do certain specific task are referred as user-
defined functions. The way in which we define and call functions in Python are
already discussed. Functions that readily come with Python are called built-in
functions.
def fun():
print("Inside function")
# Driver's code
# Calling function
fun()
(3)
The if statement alone tells us that if a condition is true it will execute a block of
statements and if the condition is false it won’t. But what if we want to do something
else if the condition is false. Here comes the else statement. We can use the else
statement with if statement to execute a block of code when the condition is false.
if (condition):
# Executes this block if
# condition is true
else:
# Executes this block if
# condition is false
for: Iterate a predefined number of times. This is also known as a definite iteration
while: Keep on iterating until the condition is false. This is known as an indefinite
iteration
(B)
In Python, Strings are arrays of bytes representing Unicode characters. A string is a
collection of one or more characters put in a single quote, double-quote or triple
quote. In python there is no character data type, a character is a string of length one.
It is represented by str class.
OR
(B) 05
# Program to display the Fibonacci sequence up to n-th term
Page 4 of 5
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
Page 5 of 5