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

CS7 Worksheet2 Strings

This document is a worksheet for Computer Science 7 focused on Python programming, specifically on string slicing, negative indexing, and advanced indexing techniques. It contains a series of questions requiring students to predict outputs of Python code snippets or fill in blanks to demonstrate their understanding of string manipulation. The worksheet is designed for educational purposes and is submitted to Asst. Prof. Michael A. Manalo.

Uploaded by

24-71564
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 views3 pages

CS7 Worksheet2 Strings

This document is a worksheet for Computer Science 7 focused on Python programming, specifically on string slicing, negative indexing, and advanced indexing techniques. It contains a series of questions requiring students to predict outputs of Python code snippets or fill in blanks to demonstrate their understanding of string manipulation. The worksheet is designed for educational purposes and is submitted to Asst. Prof. Michael A. Manalo.

Uploaded by

24-71564
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
You are on page 1/ 3

Name: Date:

Grade and Section: Subject: Computer Science 7

Worksheet #2
Python Programming
Strings (Slicing, Negative Indexing, Advanced Indexing)

Instructions:

Answer the following questions by writing the output of the given Python code snippets or filling
in the blanks.

Part 1: Basic String Slicing

1. What will be the output of the following code?

text = "Python Programming"


print(text[0:6])

Answer: ________________

2. What is the output of this code when slicing from the end?

text = "Python Programming"


print(text[-11:])

Answer: ________________

Part 2: Negative Indexing

3. What will be the output of the following code?

text = "It is more fun in the Philippines"


print(text[-5:-1])

Answer: ________________

4. Fill in the blank to get the output "thon" from the string:

text = "Python"
print(text[___:___])

Answer: print(text[_____:_____])

Part 3: Advanced Slicing

5. What is the output of the following code using step slicing?

text = "Programming"
print(text[0:11:2])

Answer: ________________

6. What will be the output of the following code?

text = "ABCDEFGHIJ"
print(text[2:8])

Computer Science 7 Python Programming Page 1 of 3


Submitted to: Asst. Prof. Michael A. Manalo
Answer: ________________

7. What will be the output of the following code?

text = "Data Science"


print(text[-7:])

Answer: ________________

8. Fill in the blanks to get "ence" from the string:

text = "Experience"
print(text[___:___])

Answer: print(text[_____:_____])

9. What will be the output of the following slicing operation?

text = "Platform Technology"


print(text[:8])

Answer: ________________

10. What will be the output of this code using step slicing?

text = "123456789"
print(text[::3])

Answer: ________________

11. What is the output when slicing with a negative step?

text = "Computer Science"


print(text[::-1])

Answer: ________________

12. Fill in the blank to extract "Sci" from "Science" using slicing:

text = "Science"
print(text[___:___])

Answer: print(text[_____:_____])

13. What will be the output of the following code?

text = "Python Scripting"


print(text[1:10:2])

Answer: ________________

14. What will be the output of the following code when slicing with a negative index?

text = "Artificial Intelligence"


print(text[-10:-4])

Answer: ________________

15. What will be the output when slicing the last three characters?

Computer Science 7 Python Programming Page 2 of 3


Submitted to: Asst. Prof. Michael A. Manalo
text = "Machine Learning"
print(text[-3:])

Answer: ________________

16. What is the output when slicing every second character from index 1 to 9?

text = "Information"
print(text[1:9:2])

Answer: ________________

17. What will be the output of this step slicing operation?

text = "abcdefghijkl"
print(text[::4])

Answer: ________________

18. What will be the output when reversing a substring?

text = "Programming Language"


print(text[5:14][::-1])

Answer: ________________

19. What is the output when slicing every third character starting from index 2?

text = "1234567890"
print(text[2::3])

Answer: ________________

20. Write a Python statement that extracts and prints "gram" from the string text =
"Programming" using slicing.

text = "Programming"
print(_________________)

Answer: print(__________)

Computer Science 7 Python Programming Page 3 of 3


Submitted to: Asst. Prof. Michael A. Manalo

You might also like