Page 116 - Computer - 8
P. 116
(b) # Program to create a function that accepts two numbers and returns their sum.
def sum_num(a, b)
sum = a + b
return sum
sum_num(20, 45)
display(“Sum of numbers =”, sum)
3. Write the output of the following code segments in Python:
(a) str1 = “I love Programming in Python”
print(str1[2])
print(str1[-3])
print(str1[5])
(b) list_num_1 = [2, 3, 5, 7, 11, 13, 17, 19]
print(list_num_1)
list_num_1.pop(4)
print(llist_num_1[5])
list_num_1.append(23)
print(list_num_1[-1])
Lab Work Computational Skills
Write the following in Python:
(a) Program to create a function to accept length and breadth of a rectangle and display its area and
perimeter.
(b) Program to create a function that accepts three numbers from the user and displays the largest
number among the three.
(c) Program to create a function named “Factorial” that accepts a numeric variable “n” as argument and
returns its factorial.
(d) Program to create a list that stores all multiples of 11 between 1 and 100 and display the list.
(e) Program to accept three strings from the user and combine them to form a single string.
TEACHER’S DESK
TEACHER’S DESK
Explain to the students the use of different types of built-in functions used to work with strings and lists.
114