Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Podar International School Chinchwad

Grade-8: Python-List, Loops and Functions


Programs for practice
----------------------------------------------------------------------------------------------------
1) Write a Python program to print the odd numbers from the following list using for loop.
List of numbers: 10, 21, 66, 93

Answer:

2) Write a function in Python that accepts two integers from the user and displays its sum and
product.

Answer:
Q.3 Do the following in Python:
-Create a list of the squares of first 5 numbers and print the list.
-Add the squares of next two numbers to this list and print it.
-Display the number of items on the list.
-Remove the last two items of the list.
-Display the range of items from the second position to the fourth position.
-Empty the list and display it.
(Learning by doing activity: page-107)
Answer:

Output:
Q.4 Write a program in Python to:
-create a list of integers.
-display only even numbers from the list.
-calculate the sum of the odd numbers
(Learning by doing activity: page-112)

Answer:

Q.5: Find the answer of the following: (Textbook Page 105)

Answer:
Output:
[‘pug’, ‘poodle’, ‘beagle’]

Explanation:
• After giving the command ‘dog_breeds.pop(1), the item at the first index
number (labrador) will be removed (Index numbers starts from 0 index number)
• After giving the command ‘dog_breeds.pop(), the last item (boxer) will be
removed.
Q.6 Find the output of the following: (Textbook Page 110)

Answer:
The Output will be:
*
*
(It will display ‘*’ on two different lines.)

Q.7 Answer the following: (Textbook Page 114)

Answer:
a) int() takes a string value as a parameter. Integer (numerical) value is returned by
this function.
b) Numerical parameters are required by the range() function.

Q.8 Accept a number from the user and print the table of the same.
Answer:
Output:

*********************

You might also like