Hello everyone, the last two months I have been learning the fundamentals of Python in effort to complete Codecademy's Computer Science Career Path. As I neared the end of the first section, I was sent off-platform to create my first Python project in which I chose a weight loss tracker. I used my new knowledge along with some help from the internet. The weight loss tracker seemed like a good idea to me, because it encompasses all of the things I learned without going too crazy.
Let me explain some of the code below:
The first thing I did was create a class called weightLoss which I knew would carry a bulk of the code.
I then used a constructor method and passed two parameters.
Through that, I was able to make classes for initial_weight, target_weight, and weight_log.
The target_weight was equal to None, which you will see why in an upcoming method. The weight_log was set to be an empty list so that we can append the user's entries later on.
Next, I created a method to record a weight entry. I passed in self, date, and weight. Through this I was able to define a record variable and then append it to the empty list before. I also added current_weight as a class.
The following method was for the user to set their target weight where I defined it as a class.
Then, there is a method to calculate weight where I defined weight_loss as a variable and subtracted the initial_weight from the target_weight. The method returns weight_loss as long as there is a target weight.
The biggest method of this class is the get_progress method. Here, I referred to the calculate_weight method to get the weight loss number, and then depending on how it came back, returned a string to the user using conditional statements.
I then defined a main function to put it all together. By defining initial_weight and target_weight as variables with print statements using input(), the user can fire back with their numbers.
Defining program as a variable made it easy to call an instance of the weightLoss class and pass those parameters in.
Finally, while True: is filled with the instructions and responses the user will input and see when they interact with the code.
This was only my first project and I really enjoyed making it, I watched a lot of videos and spent a lot of time just understanding what I was doing with some guidance. I will keep posting my progress here, next time something even cooler.
Here is a link to my project on GitHub:
https://github.com/zachmusiakiewicz/ZachFirstProject/blob/main/CodeProject2.py
Top comments (0)