This project focuses on counting the total number of digits in a given number using a while loop in Python. The project consists of an implementation file for the counting function, a script to interactively demonstrate the function, and unit tests to verify its correctness.
The app.py
file serves as the main entry point for the project. It prompts the user to input a number and then calls the count_digits function from lab.py
to count the total number of digits in that number. The result is then displayed to the user.
The lab.py
file contains the implementation of the count_digits function. This function takes a number as input and returns the total number of digits in that number using a while loop.
The lab_test.py
file contains unit tests for the count_digits function. It ensures that the function behaves as expected by testing it with various input cases, including positive numbers, negative numbers, zero, and large numbers.
- src/
- main/
- app.py
- lab.py
- test/
- lab_test.py
- main/
- Open the
src/main/app.py
file. - Run the
app.py
file to interactively test the count_digits function. - Modify the
lab.py
file to handle negative numbers gracefully if needed. - Run the test cases in
lab_test.py
to verify the correctness of the count_digits function. - Explore additional test cases or edge cases to ensure robustness.
This project demonstrates how to count the total number of digits in a number using a while loop in Python. By completing the implementation and running the provided test cases, you can gain a better understanding of while loops and number manipulation in Python.
Happy Coding!