Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Lab 5 – Python

#What will the following programs print one mark for each correct answer
# Total 30 marks
## Q1 2marks
sentence = “Humming bird in the garden “
L = sentence.split(” “)
print(“Number of words:”, len(L))
## Q2 2marks
name = “Random Kindness”
L = name.split()
print(“{0:s}, {1:s}”.format(L[1], L[0]))
## Q3 2marks
name = “Random actof Kindness”
L = name.split()
print(“Middle Name:”, L[1])
##Q4 1mark
# empty tuple
my_tuple = ()
print(my_tuple)
##Q5 1mark
# tuple having integers
my_tuple = (1, 2, 3)
print(my_tuple)
##Q6 1mark
# tuple with mixed datatypes
my_tuple = (1, “Hello”, 3.4)
print(my_tuple)
##Q7 1mark
# nested tuple
my_tuple = (“mouse”, [8, 4, 6], (1, 2, 3))
print(my_tuple)
##Q8 4marks
# tuple can be created without parentheses
my_tuple = 3, 4.6, “dog”
print(my_tuple)
# tuple unpacking is also possible
a, b, c = my_tuple
print(a)
print(b)
print(c)
##Q9 2marks
# Nested List
n_list = [“Happy”, [2,0,1,5]]
# Nested indexing
print(n_list[0][1])
print(n_list[1][3])
##Q10 2marks
my_list = [‘p’,’r’,’o’,’b’,’e’]
print(my_list[-1])
print(my_list[-5])
##Q11 6marks
x = 10
y = 12
print(‘x > y is’,x>y)
print(‘x < y is’,x<y)
print(‘x == y is’,x==y)
print(‘x != y is’,x!=y)
print(‘x >= y is’,x>=y)
print(‘x <= y is’,x<=y)
##Q12 3marks
x = True
y = False
print(‘x and y is’,x and y)
print(‘x or y is’,x or y)
print(‘not x is’,not x)
##Q13 3marks
x1 = 5
y1 = 5
x2 = ‘Hello’
y2 = ‘Hello’
x3 = [1,2,3]
y3 = [1,2,3]
print(x1 is not y1)
print(x2 is y2)
print(x3 is y3)

 

Answer:

Q1

Number of words: 6

Q2

Kindness, Random

Q3

Middle Name: actof

Q4

 ()

Q5

 (1, 2, 3)

Q6

 (1, ‘Hello’, 3.4)

Q7

 (‘mouse’, [8, 4, 6], (1, 2, 3))

Q8

 (3, 4.6, ‘dog’)

3

4.6

dog

Q9

a

5

 

Q10

e

p

Q11

x > y is False

x < y is True

x == y is False

x != y is True

x >= y is False

x <= y is True

Q12

x and y is False

x or y is True

not x is False

Q13

False

True

False

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!