Overview

Project details

A project to explore and manipulate tuples in Python.


Tracks: Python

40

number of points you will earn

2

launches to complete the project

4

tasks to complete the project

This project is part of the following tracks:

Learning outcomes

  • Understand the concept of tuples and their properties in Python.

  • Learn how to create and manipulate tuples.

  • Gain experience in handling user input and implementing error handling.

  • Develop skills in accessing and slicing tuples.

  • Recognize the immutability of tuples and its implications in programming.


Project Launches & Tasks

launch_1

  • task_1 (10 points)
    • Create a new Python file named tuple_explorer.py.

    • Define a function get_items() that prompts the user to input a list of items separated by commas.

    • Convert the input string into a list and then into a tuple.

    • Return the tuple from the function.

    • Do not forget to implement unit tests, use pytest for tests

  • task_2 (10 points)
    • In the same tuple_explorer.py file, define a function display_tuple(t) that takes a tuple as an argument.

    • Print the tuple to the console.

    • Call this function after creating the tuple in get_items() to display the user's input.

    • Do not forget to implement unit tests, use pytest for tests

launch_2

  • task_3 (10 points)
    • In the tuple_explorer.py file, define a function access_element(t, index) that takes a tuple and an index as arguments.

    • Use a try-except block to access the element at the given index.

    • If the index is valid, return the element; if not, return an error message indicating the index is out of range.

    • Do not forget to implement unit tests, use pytest for tests

  • task_4 (10 points)
    • In the tuple_explorer.py file, define a function slice_tuple(t, start, end) that takes a tuple and two indices as arguments.

    • Return the sliced portion of the tuple from the start index to the end index.

    • Ensure to handle cases where the indices are out of range by returning an appropriate message.

    • Do not forget to implement unit tests, use pytest for tests

Log in to launch project