This project demonstrates various fundamental Python concepts including functions, decorators, and object-oriented programming. It was created as part of a Python coding assessment to showcase understanding of basic Python principles.
The project consists of two main Python files:
functions.py
: Contains implementations of various utility functions.car.py
: Contains the Car class implementation.
To use this project, follow these steps:
-
Fork the repository:
- Go to the GitHub page of this project.
- Click the "Fork" button in the top-right corner to create your own copy of the repository.
-
Clone your forked repository:
git clone https://github.com/your-username/python-fundamentals-assessment.git cd python-fundamentals-assessment
-
(Optional) Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
You're all set! No additional dependencies are required as the project uses only Python standard libraries.
-
add_numbers(num1, num2)
:- Adds two numbers and returns the sum.
-
is_even(number)
:- Checks if a number is even, returns True if even, False otherwise.
-
reverse_string(text)
:- Reverses a given string.
-
count_vowels(text)
:- Counts the number of vowels in a given string (case-insensitive).
-
calculate_factorial(n)
:- Calculates the factorial of a non-negative integer using recursion.
-
decorator_func(func)
:- A decorator function that prints "Decorator Applied" before executing the decorated function.
-
apply_decorator(func)
:- Applies the
decorator_func
to a given function.
- Applies the
-
sort_by_age(people)
:- Sorts a list of (name, age) tuples by age in ascending order.
-
merge_dicts(dict1, dict2)
:- Merges two dictionaries, summing values for common keys.
The Car
class represents a car with the following attributes:
make
: The manufacturer of the carmodel
: The model of the caryear
: The year the car was manufactured
It includes a method display_info()
that prints out the car's information.
Here are some examples of how to use the functions and the Car class:
from functions import add_numbers, is_even, reverse_string, count_vowels, calculate_factorial, apply_decorator, sort_by_age, merge_dicts
from car import Car
# Using functions
print(add_numbers(5, 3)) # Output: 8
print(is_even(4)) # Output: True
print(reverse_string("hello")) # Output: olleh
print(count_vowels("Python")) # Output: 1
print(calculate_factorial(5)) # Output: 120
@apply_decorator
def greet(name):
return f"Hello, {name}!"
print(greet("Alice")) # Output: Decorator Applied \n Hello, Alice!
people = [("Alice", 25), ("Bob", 30), ("Charlie", 20)]
print(sort_by_age(people)) # Output: [('Charlie', 20), ('Alice', 25), ('Bob', 30)]
dict1 = {"a": 1, "b": 2}
dict2 = {"b": 3, "c": 4}
print(merge_dicts(dict1, dict2)) # Output: {'a': 1, 'b': 5, 'c': 4}
# Using Car class
my_car = Car("Toyota", "Corolla", 2022)
my_car.display_info() # Output: 2022 Toyota Corolla
This project was created for assessment purposes, but contributions for educational purposes are welcome. To contribute:
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Make your changes and commit them (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature-branch
) - Create a new Pull Request
Please ensure your code adheres to the existing style and includes appropriate comments.
This project is part of a Python fundamentals assessment and demonstrates basic concepts in Python programming.