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

Grade 8_Python

Uploaded by

nisha.kawale
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Grade 8_Python

Uploaded by

nisha.kawale
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python: Lists, Functions and Modules

Q.1 Fill in the blank

a. Items in a list with five elements will have An index from 0 to 1.

b. Functions are defined using the def keyword.

c. To use a built-in Python module, you first need to import it.

d. Inputs passed to a function inside parentheses are called arguments.

e. To add an element to the end of a list, you use the append() method.

f. The return statement is used to send back a value from a function to the calling
program.

Q.2 Answer the following questions.

a. What are parameters? What is the purpose of using a parameter?

Ans- Parameters are inputs or data passed to a function. When a function is


called, we need to pass the value of the parameters to perform an action
specified in a function.

b. Describe any two advantages of functions in a program?

Ans- 1. Function heips in dividing the program into smaller parts. As a program
grows bigger and bigger, functions helps to make it more organized and easy to
manage.

2. It helps to avoid repetition of same code and also makes the code reusable. A
function needs to be defined only once, and can be called by its name anywhere
in any program.

c. What is the difference between remove() and pop() method?

Ans- remove() method is used to delete a particular element from the list by
specifying the element. It searches for the element and removes it from the list. If
there are multiple occurrences, only the first one will be removed.
Pop() method removes an element from the list using its index. If the index is not
specified, it will remove the last element from the list.

d. What is a module in Python?

Ans- Modules break down the program into smaller, manageable pieces, making
your code more organized and readable.

e. The following program gives the TypeError when it is executed. Why does this
error occur? What change should be made in the program to avoid this error?

Ans- The given program gives TypeError because the index specified in the list is a
float value which is not allowed. We should make following changes to avoid this
error:

Num=[-23,22,20.23,110,-10.98]
print(num[1:3])
print(num[:2])
print(num[2:])

Q.3 What will be the output of the following programs in Python?

Ans- output: [‘pug’,’boxer’]

Ans- Output:
Sample list: [‘red’,’yellow’,’blue’,’black’]
Updated list: [‘red’,’black’]

Ans- Output:

I love Python programming.


I love Scratch programming.

Ans- Output:
[ 7, 5 , 4 ,2 ,1 ]

Ans- Output:
20

You might also like