CBSE class 8 Python list loop functions solved exercise question answer worksheet

CBSE class 8 Python list loop functions solved exercise question answer worksheet



Select the correct option.



a.

Which of the following is used to refer to each item in a list?

[R]



  1. base

  1. index




  1. integer

  1. strings







b.

Which error will be shown if you try to access the element that is not defined in the code?

[U]



  1. IndexError

  1. TypeError




  1. FileError

  1. TextError







c.

Which operator can be used to access the range of items from a list.

[R]



  1. :

  1. -




  1. +

  1. *







d.

Which of the following methods is used to delete a particular element from the list?

[R]



  1. delete()

  1. remove()




  1. cut()

  1. set()







e.

Which of the following can be used to add an item at the end of the list?

[R]



  1. add()

  1. append()




  1. plus()

  1. pop()







Answer in one word.

[U]


a.

A program structure containing one or more instructions that are excecuted repeatedly. 



Ans:

Loops



b.

The type of loop that is used to iterate over a sequence, such as a list or a string.



Ans:

Counter-controlled Loop/For loop



c.

The function that is used to generate a sequence of numbers.



Ans:

range () function



d.

What can be used to stop a ‘for’ loop before the loop ends?



Ans:

break statement






Answer the following.



a.

What will happen if you use a decimal value for an index while accessing a list? 

[Ap]


Ans:

When you use a decimal value for an index while accessing a list, it will raise a TypeError.



b.

Write a program to calculate the sum of the first ‘max’ integers. The value of ‘max’ is entered by the user.  (8 lines)

[R]


Ans:

max = input("Enter numbers separated by space ")

maxList = max.split()


print("\n")

print("All entered numbers ", maxList)


# Calculating the sum of all user entered numbers

sum1 = 0

for num in maxList:

    sum1 += int(num)

print("Sum of all entered numbers = ", sum1)



c.

Write a program in Python to access the elements of a list and display it one by one. 

[U]


Ans:

my_list = ['p', 'r', 'o', 'b', 'e']

print(my_list[0])

print(my_list[1])

print(my_list[2])

print(my_list[3])

print(my_list[4])






d.

Write a function to generate the multiplication table of a number passed to it as a parameter.

[U]


Ans:

num = int(input("Enter the number: "))


print("Multiplication Table of", num)

for i in range(1, 11):

   print(num,"X",i,"=",num * i)







What will be the output of the following code?

[An]


a.

for i in range(1, 10):

    if i==5:

        break

    print("i=", i*2)


print("Task completed")




Ans:

i= 2

i= 4

i= 6

i= 8

Task completed



b.

numbers =[1,5,3,4,2]

print (numbers)

sum=0

for i in numbers: sum=sum+i

print(sum)




Ans:

[1, 5, 3, 4, 2]

15



>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Comments

Popular posts from this blog