You are on page 1of 5

Symbiosis Institute of Computer Studies & Research

Answer Sheet

(Note: Write all the details carefully below)


Program Name:  BBA(IT)                        Batch: 21-24

Program Code: 030122 Semester: 1

Course Name: Python Course Code: 0301220107

Seat No: 412546

PRN: 21030122043

___________________________________________________________________________

Instructions: Save file in your record and give file name as mentioned below:
PRN_Seat Number_Course name in full form_Programme

Q1)
c) Accept a number N and display all the EVEN factors of the number N.

num = int(input("Enter the number: "))

print("The even factors are:")

for i in range(1, num + 1):


if num % i == 0:
if i% 2 == 0:
print(a)

g) Display letters ABCD....up to M using a loop. The ASCII equivalent of charac-


ter A is 65.

g)
character = 'M'
a = ord(character)
print('The ASCII value of letter M is', a)

for j in range(65,a+1):
print(chr(j))

Page 1 of 5
F ) Write a function, which accepts a string as a parameter and returns how
many times
vowel ‘a’ occurs in the string.

str = input("Enter the string:")


sum = 0
letter = ("a", "A")

for i in str:
if i in letter:
sum += 1
print("vowel a is repeating:", sum ,"many times")

E) Program to accept 10 numbers and print the largest number

# Program to accept 10 numbers and print the largest number

a = int(input('Enter number: '))


b = int(input('Enter number: '))
c = int(input('enter number: '))
d = int(input('enter number: '))
e = int(input('enter number: '))
f = int(input('enter number: '))
g = int(input('enter number: '))
h = int(input('enter number: '))
i = int(input('enter number: '))
j = int(input('enter number: '))

lis = [a,b,c,d,e,f,g,h,i,j]

lis.sort()

print('The largest number from the given list is: ‘,lis[-1])

D) Accept a numbers N1. Pass N1 to a user defined function, which returns the sum of
digits of N1.

Page 2 of 5
def Sum(n):

sum = 0
while (n != 0):

sum = sum + int(n % 10)


n = int(n/10)

return sum

n = int(input('Enter any number: '))


print(Sum(n))

Q2) Explain following using a suitable example.

1) // operator : // operator in python represents floor divison. It is a division


that results into whole number adjusted to the left in the number line

For example : x//y

2) Python’s list pop(): This function removes and returns the final value from
a List or the supplied index value. The value at index is popped out and re-
moved using the parameter index (optional). The last element is popped out and
eliminated if the index is not provided.

For example :

numbers = [2, 3, 5, 7, 9]
element = numbers.pop(2)
print('Removed Element:', element)
print('Updated List:', numbers)

3)find() method of a string object

find() is a Python library function that returns the index of a substring's first oc-
currence from a specified string. If find() fails to discover the substring, it re-
turns -1 rather than throwing an exception.

Page 3 of 5
For example :

str = "Hello my name is Ishika Srivastava."


str2=str.find(“name”)
print(str2)

e) Union operation on a set

The set Union() function in Python creates a new set with all of the items from
the original set.

For example :

The smallest set that contains all of the items of two given sets is the union of
the two sets. A set consisting of all the elements of A and all the elements of B
with no element duplicated is called a union of two given sets A and B.

f) is operator :

Python operator “is” used to check whether a value exist in a set of value .
They're used to see if two values (or variables) are in the same memory loca-
tion. The fact that two variables are equal does not mean they are identical.

Eg – 10 is (1,2,3,4,5)
Output - false

Page 4 of 5
Page 5 of 5

You might also like