0% found this document useful (0 votes)
5 views2 pages

Worksheet 4

Uploaded by

shivani16257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Worksheet 4

Uploaded by

shivani16257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Worksheet 4

Q1 Trace the flow of execution for following program. 1


1 def power (b,p):
2 r = b**p
3 return r
4
5 def calcsquare(a):
6 a= power(a,2)
7 return a
8
9 n=5
10 result = calcsquare(n)
11 print(result)

Q2 What will be the output of the following statement: 1


print(3-2**2**3+99/11)
a. 244 b. 244.0 c. -244.0 d. Error

Q3 Select the correct output: 1


s="remedial class worksheet 4"
L=s.split()
L1=L[0].upper() + L[1] + L[2].capitalize()
print(L1)

Q4 Find and write the output of the following Python code: 1

def fun(s):
k= len(s)
m=""
for i in range(0,k):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else:
m=m+'bb'
print(m)
fun('CS Worksheet#4')

Q5 Assertion(A): List is an immutable data type 1


Reasoning(R): When an attempt is made to update the value of an immutable
variable, the old variable is destroyed and a new variable is created by the same
name in memory.
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is false but R is True
Q6 def simple_interest(p, r, t): 1
return (p*r*t)/100
print (simple_interest(100,5,2))

Identify the formal and actual parameters in the above code snippet.
Q7 The code given below accepts a number as an argument and returns the reverse 2
number. Observe the following code carefully and rewrite it after removing all
syntax and logical errors. Underline all the corrections made.

Q8 (a) Write a function in Python, which accepts a list Arr of numbers, the function will 2
replace the even number by value 10 and multiply odd number by 5.
OR
(b) Write a function that replaces elements having even values with its half and
elements having odd values with twice its value in a list.

You might also like