0% found this document useful (0 votes)
5 views9 pages

Python Practice

The document outlines programming tasks and concepts for Grade 10 IGCSE Computer Science focusing on Python. It includes exercises on raising errors, performing arithmetic operations, conditional statements, and list properties. Additionally, it covers list creation, accessing elements, iterating, and adding items to lists.

Uploaded by

biji
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

Python Practice

The document outlines programming tasks and concepts for Grade 10 IGCSE Computer Science focusing on Python. It includes exercises on raising errors, performing arithmetic operations, conditional statements, and list properties. Additionally, it covers list creation, accessing elements, iterating, and adding items to lists.

Uploaded by

biji
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Computer Science

GRADE 10 IGCSE

Programming : Python
Name: Remarks:
Class:
Marks: /

1. Write a program to purposefully raise Indentation Error and correct it.

2. write a program to perform different arithmetic operations on numbers in


python
There are three types of conditional statements.

1. if statement
2. if-else
3. if-elif-else
4. nested if-else

3. Python program to find square of a number.

4. Python program to check whether the given number is even or not.

5. Python program to find out the average of a set of integers.

6. Python program to check whether the given integer is a multiple of both 5 and 7.
7. Python program to find greater among two numbers

8. Python program to display all integers within the range 100-150 whose sum of digits
is an even number.
9. Python program to implement a calculator to do basic operations.

List
The following are the properties of a list.

 Mutable: The elements of the list can be modified. We can add or remove
items to the list after it has been created.

 Ordered: The items in the lists are ordered. Each item has a unique index
value. The new items will be added to the end of the list.

 Heterogenous: The list can contain different kinds of elements i.e; they can
contain elements of string, integer, boolean, or any type.
 Duplicates: The list can contain duplicates i.e., lists can have two items with
the same values.

Why use a list?

 The list data structure is very flexible It has many unique inbuilt functionalities
like pop(), append(), etc which makes it easier, where the data keeps
changing.

 Also, the list can contain duplicate elements i.e two or more items can have the
same values.

 Lists are Heterogeneous i.e, different kinds of objects/elements can be added

 As Lists are mutable it is used in applications where the values of the items change
frequently.

Creating a Python list

 The list can be created using either the list constructor or using square brackets [].

 Using list() constructor: In general, the constructor of a class has its class name.
Similarly, Create a list by passing the comma-separated values inside the list().

 Using square bracket ([]): In this method, we can create a list simply by
enclosing the items inside the square brackets.

10. Creating list


11. Length of a list

Accessing items of a List

 Using indexing, we can access any item from a list using its index number
 Using slicing, we can access a range of items from a list

 As Lists are ordered sequences of items, the index values start from 0 to the
Lists length.

 Whenever we try to access an item with an index more than the Lists length, it
will throw the 'Index Error'.
 Similarly, the index values are always an integer. If we give any other type,
then it will throw Type Error.

12. Accessing List elements

13. Negative indexing

14. Slicing

Iterating a List
The objects in the list can be iterated over one by one, by using a for a loop.
15. Iterating using for loop

16. Iterate along with an index number:

The index value starts from 0 to (length of the list-1). Hence using the function
range() is ideal for this scenario.
The range function returns a sequence of numbers. By default, it returns starting
from 0 to the specified number (increments by 1). The starting and ending values
can be passed according to our needs.

Adding elements to the list


We can add a new element/list of elements to the list using the list methods such as
append(), insert(), and extend().
Append item at the end of the list
The append() method will accept only one parameter and add it at the end of the list.

17. Let’s see the example to add the element ‘Emma’ at the end of the list.
18. Add item at the specified position in the list:
Use the insert() method to add the object/item at the specified position in the list.
The insert method accepts two parameters position and object.

You might also like