Project1 Presentation
Project1 Presentation
The calculator.py file contains the Calculator class, which has a memory attribute and six methods: add,
subtract, multiply, divide, root, and reset. The test_calculator.py file contains the TestCalculator class, which
is a unit test case for the Calculator class using the unittest module. I have written docstrings for each
method and class, and followed the PEP 8 style guide for Python code. I have also used descriptive variable
names and comments to make the code more readable and maintainable.
•It can handle both positive and negative numbers, as well as zero.
•It can perform addition, subtraction, multiplication, and division operations, as well as taking the n-th root
of a number.
•It can raise appropriate exceptions for invalid inputs, such as dividing by zero or taking a zero or negative
root.
•It can store the result of the last operation in the memory attribute, and use it for subsequent operations.
•It has a comprehensive test suite that covers all the methods and edge cases of the Calculator class.
Some of the design choices and challenges that I faced while developing this package are:
•I decided to use the ** operator to calculate the n-th root of a number, instead of using a more complex
algorithm such as Newton’s method. This is because the ** operator is built-in, fast, and accurate, and it can
handle fractional and negative exponents as well.
•I decided to use the unittest module for testing, instead of other alternatives such as pytest or nose. This is
because the unittest module is part of the standard library, and it provides a simple and consistent way of
writing and running test cases.
•I decided to use the setUp and tearDown methods to create and delete a Calculator object before and
after each test. This is because it ensures that each test is independent and isolated, and it avoids code
duplication and side effects.
I hope this introduction gives you a clear overview of my calculator package. I would be happy to answer
any questions you may have, or demonstrate how to use the package in action. Thank you for your
attention.
• What is Object-Oriented Programming? Select and explain two examples
where using OOP concepts can improve the quality and usability of code.
• What is "Clean Code"? Select four main key concepts and explain them
using real-world examples.
• Why do we need to document code? How can you do it? What should be
provided inside the documentation?
Object-Oriented Programming (OOP) is a programming paradigm that uses objects to represent data and
behavior. Objects are instances of classes, which define the properties and methods of the objects.
example of where OOP can improve the quality and usability of code is:
• Modeling real-world entities: OOP can help you create classes that represent real-world entities,
such as animals, cars, or users. This can make your code more intuitive and easier to understand, as
well as facilitate reuse and maintenance. For example, you can create a class called Animal that has
properties like name, age, and color, and methods like eat, sleep, and make_sound. Then you can
create subclasses that inherit from Animal, such as Dog, Cat, or Bird, and override or extend the
methods as needed.
Clean Code is a term that refers to code that is easy to read, understand, and maintain. Clean code follows
a set of principles, standards, and practices that make it simple, concise, and expressive.
• Format and syntax: Clean code should follow a consistent format and syntax that adhere to the
conventions and standards of the programming language and the project. It should use proper
indentation, spacing, and alignment, and avoid long lines and large blocks of code.
• Conciseness versus clarity: Clean code should be concise but not at the expense of clarity. It should
avoid unnecessary comments, code duplication, and dead code, and use abstraction and refactoring
to reduce code length and complexity. However, it should not sacrifice readability and
understandability for brevity and cleverness.
• Re-usability: Clean code should be reusable and modular, and avoid tight coupling and high
cohesion. It should use functions, classes, and modules to encapsulate and abstract functionality,
and follow the principle of single responsibility.
Code documentation is the process of writing text that accompanies and explains the code. Code
documentation helps other developers and users to understand the purpose, structure, and functionality of
the code, as well as how to use, modify, and maintain it.
There are different types of code documentation, such as:
• Code comments: These are annotations or explanations that are embedded within the code, usually
preceded by a special symbol or syntax. Code comments are used to describe the logic, purpose,
and behavior of the code, as well as any assumptions, limitations, or dependencies.
• API documentation: This is a type of documentation that describes the interface and functionality
of a software component, such as a library, a framework, or a service. API documentation is used to
specify the inputs, outputs, parameters, and exceptions of the component, as well as how to use,
configure, and integrate it. API documentation is mainly intended for developers who use the
component, and can be generated by tools or written manually.
• User documentation: This is a type of documentation that describes how to use a software product,
such as an application, a tool, or a system. User documentation is used to provide instructions,
tutorials, examples, and references for the product, as well as how to troubleshoot, update, and
support it. User documentation is mainly intended for end-users or customers who interact with the
product, and can be written in various formats, such as text, images, videos, or interactive elements.