Skip to content

hlanchas/Programming-exercise-4-String-operations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

Programming exercise 4 - Operations with strings

πŸ“ Overview

In this assignment, you will practice various methods for manipulating and formatting text in Python using the Thonny IDE. You will replicate examples from class and solve a short coding challenge.

βš™οΈ Instructions

Part 1: Class Examples

  1. Open Thonny.
  2. Create a new file and save it exactly as OperationsWithStrings.py.
  3. For each string operation covered in the lecture slides, you must:
  • Write a print() statement indicating the operation name (e.g., print("--- f-strings ---")).
  • Copy the Python code examples from the slide into your file below that print statement.
  • Important: Do NOT copy any Java code examples found in the slides. Only the Python code.
  1. Run your code frequently to ensure each example works correctly.

Part 2: Coding Exercise

At the bottom of your OperationsWithStrings.py file, add a comment # --- CODING EXERCISE --- and solve the following problem:

The Scenario: You have received a raw data string containing a student's ID and name, but it is surrounded by unnecessary symbols. raw_text = "###ID:2024-Smith,John###"

Your Task: Write the code to clean this data and print a friendly welcome message.

  1. Clean it: Remove the # symbols from both ends using strip().
  2. Extract ID: The ID is the number between the colon : and the hyphen - (e.g., 2024). Use .find() and slicing to extract it.
  3. Extract Name: The first name is everything after the comma , (e.g., John). Use .find() or .rfind() and slicing to extract it.
  4. Final Output: Use an f-string to print the result in this exact format: "Welcome John! Your student ID is 2024."

βœ… Submission Checklist

  • File is named OperationsWithStrings.py.
  • All Python examples from the slides are included.
  • No Java code is included.
  • The Coding Exercise is completed and prints the correct welcome message.
  • Upload your file to this GitHub repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors