About Lesson
Hands-On Activity
Write a Program to Reverse a String
- Objective: Write a Python program that takes a string as input and returns the reversed string.
- Steps:
- Prompt the user to enter a string.
- Use slicing to reverse the string.
- Print the reversed string.
python
input_str = input("Enter a string: ") reversed_str = input_str-1 print("Reversed string:", reversed_str)
Implement a Program to Read Data from a File and Display It
- Objective: Write a Python program that reads data from a file and displays it.
- Steps:
- Open the file in read mode.
- Read the content using the
read()
method. - Print the content.
python
with open("data.txt", "r") as file: content = file.read() print(content)