Sei sulla pagina 1di 12

Department of Education

Division of City Schools-Makati


Makati Science High School
School Year 2017– 2018

PYTHON PROGRAMMING HANDS-ON ACTIVITY


Python Activity 13: “Different Ways to Access Tuples”

Name:__________________________ Partner: _____________________

Learning Objectives
Students will be able to:
Content:

• Explain the methods and other tuple operations to access tuple.


• Differentiate ways to access tuple.
• Determine types of functions applicable to tuple.
Process:

• Create python codes to access tuple through methods and other


operations.
• Create personalized program applying the syntax and codes learned
from tuple methods and operations.
• Discuss problems and programs with all group members.
Prior Knowledge

• Understanding syntax, codes of functions used in list.


Further Reading

• Differentiate programs that use types of functions involving tuple


and its real-life system applications.

FYI: In Python programming, a tuple is similar to a list. The


difference between the two is that we cannot change the elements
of a tuple once it is assigned whereas in a list, elements can be
changed.

Critical Thinking Questions:


1. Creating tuple
a. Write a Python program to create a tuple by following the
instructions below.

1. Create an empty tuple

______________________________________________________________

1
2. Create an empty tuple with the built-in tuple() function in
Python
______________________________________________________________

b. Write a Python program to create a tuple with different


data types following the instructions below.

1. Create an empty tuple.

______________________________________________________________

2. Create an empty tuple with built-in tuple() function in


Python
______________________________________________________________

3. Write the program output.


______________________________________________________________

c. Write a Python program to create a tuple with numbers and


print one item following the instructions below.

1. Create an empty tuple.

______________________________________________________________

2. Create an empty tuple with built-in tuple() function in


Python
______________________________________________________________

3. Write the program output.


______________________________________________________________

d. Based on the sample tuple programs created:

1. How will you define tuple in your own context?

______________________________________________________________
______________________________________________________________

2. Identify the components of a tuple.

______________________________________________________________

2
3. What is the syntax in creating a tuple?
______________________________________________________________

2. Accessing tuple trough index and count methods:

NOTE: Analyze, examine, and rewrite the code below to create a tuple program
that can access items in tuple using indexing method.

a. Tuple Methods Index

1. Write a Python program that can create and access tuple


using indexing method of tuple items, following the
instructions below.

a. Create an empty tuple

______________________________________________________________

b. Get the index of the first item whose value is passed as


parameter
______________________________________________________________
c. Define the index from which you want to search
______________________________________________________________

d. Define the segment of the tuple to be searched


______________________________________________________________

FYI: if item does not exist in the tuple, it will return ValueError Exception

2. What are the missing components in a tuple program?


______________________________________________________________

3
3. What does the tuple program do?
______________________________________________________________

4. What does indexing do to the tuple program?


______________________________________________________________

5. Based on the edited sample tuple code programs created,


how will you define indexing method in your own words?
______________________________________________________________
______________________________________________________________

6. Write a Python program that creates a tuple using


indexing method. The program should be able to get the
4th element from the items inside the tuple. After that,
get the 4th element from the last location. Apply the
following instructions below.

a. Create a tuple containing 10 items.

______________________________________________________________

b. Assign an index to the target item in the tuple.


______________________________________________________________

c. Select the target item (4th element) of the tuple by index.


______________________________________________________________

d. Select the target item (4th element from the last) of the
tuple by the negative index.
______________________________________________________________

e. Write the program output.


______________________________________________________________

NOTE: Examine and analyze the tuple code program below that can access items
in tuple using count method.

4
b. Tuple Methods Count

1. Execute the Python tuple program code above and examine


the output.

a. What does the program do?

______________________________________________________________

b. What does the (n, tuple) in the conditional if statement do?


______________________________________________________________
c. How does it affect the output?
______________________________________________________________

d. What does the line codes “break” and “ctr += 1” do to the


program?
______________________________________________________________

NOTE: Examine and analyze the tuple code program below that can access items
in tuple using count method.

2. Execute the tuple program above and examine the output.

a. What does the program do?

______________________________________________________________

b. What does “random.count” do?


______________________________________________________________
c. How does it affect the output?
______________________________________________________________

3. Based on the tuple program codes you examined:


a. What does the count method do to the tuple program?
___________________________________________________________
___________________________________________________________

5
b. How will you define count method in your own words?
___________________________________________________________
___________________________________________________________

3. Accessing tuple trough other tuple operations:

a. Tuple Operation-Slicing
NOTE: Examine and analyze the tuple code program below that can access items
in tuple using slicing tuple operation.

1. Execute the Python tuple program above and examine the


output.

a. What does the program do?

______________________________________________________________

6
b. What does the slice tuple operation do?
______________________________________________________________
c. How does it affect the output?
______________________________________________________________

d. Write the program output.


______________________________________________________________

2. Based on the tuple program you examined

a. What does the slicing operation do to the tuple


program?
___________________________________________________________
___________________________________________________________

b. How will you define slice operation in your own words?


___________________________________________________________
___________________________________________________________

b. Tuple Operation-Changing (Reassigning trough adding item)

NOTE: The tuple program below can access items in tuple by reassigning the items
added items under a changing operation. Examine and analyze it.

1. Execute the Python tuple program code above and examine


the output.

a. What does the program do?

______________________________________________________________

7
b. What does the reassigning trough adding item to tuple
operation do?
______________________________________________________________
c. How does it affect the output?
______________________________________________________________

d. Write the program output.


______________________________________________________________

2. Based on the tuple program codes you have examined:


a. What does reassigning by adding item operation do to
the tuple program?
___________________________________________________________
___________________________________________________________

b. How will you define reassigning trough adding item


operation in your own words?
___________________________________________________________
___________________________________________________________

c. Tuple Operation-Changing (Repetition through count


method)

NOTE: The tuple code program below can access items in tuple using repetition
trough counting the number of times an item appears under changing operation.
Examine and analyze it.

1. Execute the Python tuple program code above and examine


the output.

a. What does the program do?

______________________________________________________________

8
b. What does the repetition trough count method tuple operation
do?
______________________________________________________________
c. How does it affect the output?
______________________________________________________________

d. Write the program output.


______________________________________________________________

2. Based on the tuple program codes you examined:

a. What does repetition trough count method operation do


to the tuple program?
___________________________________________________________
___________________________________________________________

b. How will you define repetition trough count method


operation in your own words?
___________________________________________________________
___________________________________________________________

3. Tuple Operation-Changing (Iteration using remove


function)

NOTE: The tuple code program below can access items in tuple using iteration
changing operation. Examine and analyze it.

1. Execute the Python tuple program code above and examine


the output.

a. What does the program do?

______________________________________________________________

9
b. What does the iteration using remove function in tuple
operation do?
______________________________________________________________
c. How does it affect the output?
______________________________________________________________

d. Write the program output.


______________________________________________________________

2. Based on the tuple program codes you examined:

a. What does iteration using remove function operation


do to the tuple program?
___________________________________________________________
___________________________________________________________

b. How will you define iteration using remove function


operation in your own words?
___________________________________________________________
___________________________________________________________

4. Tuple Operation-Changing (Check “item” if it exists)

NOTE: The tuple code program below can access items in tuple using check “item”
if it exists changing operation. Examine and analyze it

1. Execute the Python tuple program code above and examine


the output.

a. What does the program do?

______________________________________________________________

b. What does the check “item” if it exists in tuple operation


do?
______________________________________________________________

10
c. How does it affect the output?
______________________________________________________________

d. Write the program output.


______________________________________________________________

2. Based on the tuple program codes you examined:

a. What does check “item” if it exists operation do to


the tuple program?
___________________________________________________________
___________________________________________________________

b. How will you define check “item” if it exists


operation in your own words?
___________________________________________________________
___________________________________________________________

e. Tuple Operation-Changing (find the length)

NOTE: The tuple code program below can access items in tuple using find the
length changing operation. Examine and analyze it.

1. Execute the Python tuple program code above and examine


the output.

a. What does the program do?

______________________________________________________________

b. What does the find the length of tuple operation do?


______________________________________________________________

11
c. How does it affect the output?
______________________________________________________________

d. Write the program output.


______________________________________________________________

2. Based on the tuple program codes you examined:

a. What does find the length operation do to the tuple


program?
___________________________________________________________
___________________________________________________________

b. How will you define find the length operation in your


own words?
___________________________________________________________
___________________________________________________________

Application Question:

1. Create a program that prints a given tuple that will hold


information about Makati Science students (name, age, grade
level, and section), add new information to the list inside
the tuple, and print a new list nested to tuple. It will
also prompt a message if the elements in the list within
the tuple is not available. Write the code and the output
of the created program.

______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

12

Potrebbero piacerti anche