0% found this document useful (0 votes)
61 views

2 - Python Basics & Functions (Solutions)

This document contains solutions to exercises from a Computer Science chapter on Python basics and functions. It includes the code and output for various Python programs and functions. Key points summarized: 1) Example Python code is given to calculate sums and print outputs using for loops over strings, lists, and ranges. 2) The flow of execution is outlined for a sample Python code snippet with line numbers. 3) The return value and output of functions are described, including a function to return the sum of inputs. 4) Syntax errors in code snippets are identified, such as missing colons. 5) A function is described to find place names with more than 5 characters from a dictionary of cities.

Uploaded by

Porkodi M
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)
61 views

2 - Python Basics & Functions (Solutions)

This document contains solutions to exercises from a Computer Science chapter on Python basics and functions. It includes the code and output for various Python programs and functions. Key points summarized: 1) Example Python code is given to calculate sums and print outputs using for loops over strings, lists, and ranges. 2) The flow of execution is outlined for a sample Python code snippet with line numbers. 3) The return value and output of functions are described, including a function to return the sum of inputs. 4) Syntax errors in code snippets are identified, such as missing colons. 5) A function is described to find place names with more than 5 characters from a dictionary of cities.

Uploaded by

Porkodi M
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/ 5

Class : XII Subject: Computer Science

Chapter: Python Basics & Functions Worksheet: 2 - Solutions


1. Page No. 1.70 – Unsolved Questions.
a. Q.No: 4

Write Python statement for the following in interactive mode:


(a) To display sum of 3, 8.0, 6*12
3 + 8.0 + 6 * 12
(b) To print sum of 16, 5.0, 44.0
print (16 + 5.0 + 44.0)
b. Q.No: 9

(a) for i in '123':


print("CPU", i)
CPU 1
CPU 2
CPU 3
(b) for i in [ 100, 200, 300] :
print(i)

100
200
300
(c) for j in range (10, 6, -2):
print(j*2)
100
200
300
(d) for x in range (1, 6):
for y in range (1, x+1) :
print (x,' ', y )
(e) for x in range (10, 20):
if (x == 15):
break
print (x)
15

(f) for x in range (10, 20) :


if (x % 2 == 0) :
continue
print (x)
19

c. Q.No:10
Write the output of the following program on execution if x = 50:

if x > 10 :
if x > 25 :
print("ok")
if x > 60 :
print("good")
elif x > 40 :
print("average")
else:
print("no output")
ok
d. Q.No: 21

A list Num contains the following elements:


3, 25, 13, 6, 35, 8, 14, 45

Write a function to swap the content with the next value divisible by 5 so that the
resultant list will look like:
25, 3, 13, 35, 6, 8, 45, 14

2. Page No. 2.70 – Unsolved Questions.


a. Q.No: 10
Consider the following code and write the flow of execution for this. Line numbers
have been given for your reference.

1->5->9->10->5->6->1->2->3->6->7->10->11
b. Q.No: 11
What will the following function return?
def addEm(x, y, z):
print (x + y + z)

x=y=z=10
It is a void function.
So, it will return None.
c. Q.No: 12
What will be the output displayed when addEM() is called/executed?

def addEm(x, y, z):


return x + y + z
x=y=z=10
When the addEm function is called, values of x,y & z will be added and the total
will be returned. But the total will neither be printed nor stored in any variable.
Hence nothing is shown as output.
d. Q.No: 13
i) What will be the output of the following programs?

1
1
1
ii)

1
10
1
iii)

1
10
10
iv)

Hello
bye!
e. Q.No: 16
Find the errors in the code given below:

i)

Statement 1 should have colon (: ) at the end.


ii)

Considered only syntax error

f. Q.No: 45
Write a method COUNTNOW(PLACES) to find and display those place names in which
there are more than 5 characters after storing the name of places in a dictionary.
For example,
If the dictionary PLACES contains:
{1:”DELHI”,2:”LONDON”,3:”PARIS”,4:”NEW YORK”,5:”DUBAI”}
The following output should be displayed:
LONDON
NEW YORK

You might also like