Extract Information From Parameters

Beginner

In this project, you will learn how to extract numbers from a given text, calculate the average of those numbers, and round the result to two decimal places. This project will help you practice working with regular expressions and handling command-line arguments in Python.

Python

Introduction

In this project, you will learn how to extract numbers from a given text, calculate the average of those numbers, and round the result to two decimal places. This project will help you practice working with regular expressions and handling command-line arguments in Python.

👀 Preview

$ python3 ~/project/find_num.py "a11 b3.14c15 16"
11.29
$ python3 ~/project/find_num.py "a 5 b 6 c7 dd8 9"
7.00
$ python3 ~/project/find_num.py "ad1dg6dgd9dg4qwe10"
6.00

🎯 Tasks

In this project, you will learn:

  • How to use regular expressions to find all the numbers (both integers and floating-point numbers) in a given text
  • How to convert the matched numbers from strings to floats
  • How to calculate the average of the extracted numbers
  • How to format the average result to two decimal places
  • How to handle command-line arguments in a Python script

🏆 Achievements

After completing this project, you will be able to:

  • Write a Python script that can extract numbers from a given text
  • Calculate the average of the extracted numbers
  • Format the average result to two decimal places
  • Run the script from the command line and pass the text as an argument

Teacher

labby

Labby

Labby is the LabEx teacher.