The units converter is a python terminal program that takes values from the user and converts it to other units.
In a world of different parameters, languages and ways to measure a converter is a tool that will always come to good use when not knowing the differences by heart.
The program is very straightforward. You will as a user be presented with 5 options. Four of them equals conversion choices.
- Celsius / Fahrenheit
- Meters / feet
- Kilos / pounds
- Liters / gallons
- You are welcomed with a short message and an option menu.
- Choose a number between 1-5, if not correct input you will get an error message in the color red and retry new input.
- After correct choice you will go to that part of the program.
- If you correct input is typed, you go to next phase and add value that will be calculated, else you will get a message about invalid input in red.
- When correct value is typed, 1 or 2, you can type a value and then get an answer message with an option to try new values.
If the answer is yes, you go back to program and choose what parameter you want to have converted. Else you will be sent to the main option menu.
Some methods used in the calculations were the following
- int() - returns an integers number from a string
- float() - returns a floating number from a number or a string
- round() - return a floating number with a specific number of decimals, in my program 2 decimals.
Arithmetic operator used
- Division /
- Multiplication *
- Subtraction -
- Addition +
To make program more user-friendly I imported colorama. The menu is in blue, wrong answers in red and the correct answer is yellow.
I have tested the program for each of the steps and tried to commit as often as I could. This has helped to minimize the amount of bugs and make sure the code is working properly.
Some of the bugs that I have come across wasn't too hard to handle. Foremost it was string input that couldn't be handled since they weren't integers or floats. That was easily handled by using the int() or float()-function in the equations.
When adding colorama to the project I forgot to add it to the requirements.txt, thus creating getting an error message ModuleNotFoundError: No module named 'colorama
in Heroku terminal.
One of the last bugs that I found was that after I ran a program e.g. degrees(), and came back to main-menu and choose the exit-option was that I didn't exit the program. Instead, I was stuck in a loop, with the menu. I then tried to do a separate function just to exit while not being in the while-loop of the choices. Didn't help, removed some while-loop, but still the same result. After some trial and errors, I went for the built-in function exit() that did the trick. I would count this as a bug that was not solved.
I validated my code via the pep8 online check, (http://pep8online.com/) without any error messages. This was possible by continuously reading the 'problems' message that was presented in the Gitpod IDE.
The project was created on Github, by first forking the Code Institute template and since it's a python project, Github does not manage to have it deployed in its pages.
Heroku was the platform the project was deployed to.
- Create an account.
- On the dashboard select
New
andCreate new app
which takes you to right place. - Name the app, select
region
, clickCreate new app
. - Go to
settings
. - Config Vars >> reveal vars >> add key:PORT, value: 8000 and click Add
- Add
buildingpacks
- add nodejs and python - go to
Deploy
and choose method,github
in this case, connect to it. - Search and select/connect to your repository
- Choose
Deploy Branch
method, automatic or manual, I choose manual. - Heroku will do its job connecting, and create a link to page.
- When message
Your app was successfully deployed
is received you canview
the site.
There are possibilities to add more units to the program.
One could also add a random() to generate examples of values within in each function.
Append made calculations to a Google spreadsheet.