0% found this document useful (0 votes)
47 views4 pages

ITC Final Sol

Questions at the end test comprehension of lists and their methods, string operations, loop and function behavior, and parsing the student grade code. Concepts illustrated include lists,

Uploaded by

Hafeez Ali
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)
47 views4 pages

ITC Final Sol

Questions at the end test comprehension of lists and their methods, string operations, loop and function behavior, and parsing the student grade code. Concepts illustrated include lists,

Uploaded by

Hafeez Ali
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/ 4

Q.

1
(a)
Input:
count = 0
while(count < 5):
print(count)
count += 1
else:
print("count value reached %d" %(count))
for i in range(1, 10):
if(i%5 == 0):
break
print(i)
else:
print("this is not printed because for loop is terminated because of break but not due to fall in condition")
Output:
0
1
2
3
4
count value reached 5
1
2
3
4
(b)
Code:
r = float(input("Enter the radius of the sphere: "))
vol = (4/3)*(3.14)*(r**3)
print("Radius of shpere = %f" %(r))
print("Volume of shpere = %f" %(vol))
(c)
Input:
print('Art:({a:5d}, Price:{p:8.2f}'.format(a=453,p=59.058))
print("Art: %2d, Price per Unit: %8.3f"%(453,59.058))
Output:
Art: 453, Price: 59.06
Art: 453, Price per Unit: 59.058
Q.2
(a)
Input:
a = ['foo', 'bar', 'bar', 'qux', 'quux', 'corge']
Output:
i. ['foo', 'bar', 'quux']
ii. []
iii. []
iv. error
v. error
vi. ['foo', 'bar', 'bar', 'qux', 'quux', 'corge', 'grault', 'garply']
vii. bar
viii. error
ix. error
x. ['foo']
xi. ['corge', 'quux', 'qux', 'bar', 'bar', 'foo']
xii. ['corge']
xiii. ['corge', 'quux', 'qux', 'bar', 'bar', 'foo']
xiv. ['bar', 'bar']
(b)
Input:
str = "this is string example....wow!!!"
print("str.capitalize():",str.capitalize())
s = 'foobar'
print(s[3-len(s)])
str = "this is string example....wow!!!";
print("Length of the string: ",len(str))
Output:
i. str.capitalize(): This is string example....wow!!!
ii. b
iii. Length of the string: 32
Q.3
(a)
Input:
def foo(x, y):
global a
a = 42
x,y = y,x
b = 33
b = 17
c = 100
print(a,b,x,y)
a,b,x,y = 1,15,3,4
foo(17,4)
print(a,b,x,y)
Output:
42 17 4 17
42 15 3 4
(b)
Code:
def linearSearch(array, n, x):
for i in range(0, n):
if (array[i] == x):
return i
return -1

array = [4, 2, 8, 9, 3, 7]
x = int(input(“Enter the number to be searched: ”))
n = len(array)
result = linearSearch(array, n, x)
if(result == -1):
print(“Element not found”)
else:
print(“Element found at index: “, result)
Q.4
(a)
Output:
Name: Zara
quiz1: 7 mid 28 quiz2: 8 Final: Total Marks = 81
Grade A-

Name: Manni
quiz1: 7 mid 20 quiz2: 10 Final: Total Marks = 72
Grade B

Name: Fahad
quiz1: 6 mid 30 quiz2: 9 Final: Total Marks = 65
Grade C+

Name: Riaz
quiz1: 8 mid 2 quiz2: 8 Final: Total Marks = 26
Grade is F
"

Total Students 4

(b)

You might also like