Mini Project
Mini Project
A Project Report on
“BMI Calculator in Python Programming Language”
Bachelor of Engineering in
Computer Science and Engineering
Submitted by:
Dhanush K - 1GG22CS016
2nd Semester
Under the Guidance of
Dr. Chethan K C
vhkjbh
7 Bibliography 19
ChapTEr : 01 INTrODUCTION
1
ChapTEr : 01 INTrODUCTION
programming skills while also gaining insights into the significance of
weight assessment and its impact on overall health.
Overall, the purpose of this project is to combine the power of Python
programming with the health assessment domain, providing individuals
with a practical tool to calculate their BMI and make informed decisions
about their weight and well-being.
2
ChapTEr : 02 prOblEm STaTEmENT
The problem at hand is to create a BMI (Body Mass Index) calculator
using the Python programming language. The goal is to develop a program
that allows users to input their weight and height values, calculates their
BMI using a specific formula, and provides them with their weight status
category based on the calculated BMI.
The BMI calculator should deliver clear and concise results, displaying
the calculated BMI value and the corresponding weight status category to
the user. The program should be designed in a way that promotes ease of
use, readability, and accuracy.
3
ChapTEr : 03 alGOrIThm aND STrUCTUrE
4
ChapTEr : 04 ImplEmENTaTION
def calculate_bmi(weight, height):
"""
Calculates the Body Mass Index (BMI) given weight in kilograms (kg)
and height in meters (m).
"""
bmi = weight / (height ** 2)
return bmi
# Calculating BMI
bmi = calculate_bmi(weight, height)
5
print("4. Monitor your weight gain progress to stay motivated.")
elif bmi < 24.9:
print("Category: Normal weight")
print("You have a healthy BMI! Keep maintaining a balanced lifestyle.")
elif bmi < 29.9:
print("Category: Overweight")
print("To maintain a healthy BMI, consider losing some weight.")
print("Here are some tips for you!")
print("1. Consume fewer calories than your body needs to create a calorie deficit.")
print("2. Focus on a balanced diet.")
print("3. Eat regular meals to maintain stable blood sugar levels and prevent
excessive hunger.")
print("4. Engage in activities like brisk walking, jogging, cycling, or swimming.")
print("5. Keep track of your weight loss progress to stay motivated.")
else:
print("Category: Obese")
print("To maintain a healthy BMI, consider losing weight and adopting a healthier
lifestyle.")
print("Here are some tips for you!")
print("1. Consume fewer calories than your body needs to create a calorie deficit.")
print("2. Focus on a balanced diet.")
print("3. Eat regular meals to maintain stable blood sugar levels and prevent
excessive hunger.")
print("4. Engage in activities like brisk walking, jogging, cycling, or swimming.")
print("5. Keep track of your weight loss progress to stay motivated.")
6
Once we implement a program in a PyScripter, a free open-source
Python Integrated Development Environment (IDE) is look like as a
following picture:
7
different aspects of our program. This will help organize our code and
make code and make it easier to manage and debug.
Step 03:
By writing code to implement each individual rule based on our defined
specifications. This could involve conditional statements (if-else), loops,
data structures and other relevant programming constructs.
Step 04:
Ensuring that our program validates user inputs to adhere to the specified
rules and produce the expected outputs. We can use techniques such as
input validation, error handling, or exception handling to handle invalid
inputs gracefully.
Step 05:
Finally by debugging our program and refining the implementation if
necessary. Test it again with various inputs to verify its correctness and
make any necessary adjustments.
Step 06:
Also providing clear and concise documentation to explain the purpose of
the program, its functionality, and the rules and regulations it follows. This
will make it easier for others (or our future self) to understand and
maintain the code.
Step 07:
Remembering to adapt the steps to the specific rules and regulations we
want to implement. The process may vary depending on the complexity
and nature of the rules involved.
8
ChapTEr : 05 rESUlT aND aNalYSIS
We utilize library functions in Python because libraries consist of pre-
written code collections that enhance the functionality of our programs.
These libraries contain modules, which are files containing Python code
that can be imported into our programs to access their features. Using
libraries helps save time and effort by leveraging existing code instead of
reinventing the wheel. These libraries encompass a diverse range of areas,
including data analysis, web development, scientific computing, machine
learning, and more.
� Function
However, we use functions in the program because, in Python, they
provide a means to encapsulate a set of instructions that can be reused
multiple times within a program. Functions aid in organizing code, making
it more modular, readable, and maintainable. By defining functions, we can
separate different tasks and logically group related code, enhancing code
reusability and overall program structure.
Following figure shows the use of User defined-function in program:
1. Code Reusability: Functions allow you to define a block of code that can
be called multiple times from different parts of the program. This promotes
code reuse and reduces duplication, as you can write the logic once and
use it whenever needed.
2. Modularity: Functions break down a program into smaller, manageable
chunks of code. Each function can have a specific task or responsibility,
making the overall program more modular. This modularity makes it easier
to understand, test, and maintain the codebase.
9
3. Abstraction: Functions provide an abstraction layer by hiding the
implementation details of a particular functionality. When using a function,
you don't need to know how it works internally; you only need to know
what
inputs it expects and output it produces. This simplifies the usage of
complex operations.
4. Readability: By defining meaningful function names and using proper
parameter names, functions make the code more readable and self-
explanatory. They can act as self-contained units that convey their purpose
and make the code easier to understand.
5. Code Organization: Functions allow you to organize code logically.
Related tasks can be grouped into functions, improving the structure of
your program. This organization helps in locating and modifying specific
parts of the codebase more efficiently.
6. Testing and Debugging: Functions make it easier to test and debug code.
Since functions isolate specific blocks of logic, you can focus on testing and
debugging individual functions independently, ensuring their correctness
before combining them into the complete program.
7. Encapsulation: Functions provide a way to encapsulate code and data,
allowing you to control access to variables within the function. This helps in
maintaining data integrity and avoiding conflicts with other parts of the
program.
� Input ()
Now, if you run this program, it prompts you to enter your weight in
kilograms (Kg) and height in Meters (m) as shown in below figure:
10
Here, when user enter his/her weight in ‘Kg’ and height in ‘m’ it may be in
integer or floating point value. So for safer side we use float datatype to
get a specific data, then weight and height of the user is stored in assigned
variable.
� Return type ()
Next, the data stored in the variable is calculated to determine the BMI
value using the Return Type named “return bmi” in the program as shown
below:
In Python, the return type is used to specify the type of data that a function
will return when it is called. It is optional to specify the return type in
Python function declarations, as Python is dynamically typed and can infer
the return type based on the actual value returned by the function.
However, specifying the return type can be helpful for the following
reasons:
1. Documentation and Readability: Specifying the return type makes the
function's behaviour more explicit and self-documenting. It helps other
developers understand the purpose of the function and the type of value it
is expected to return.
2. Type Checking: By specifying the return type, you can leverage static type
checkers like mypy to analyse your code and catch potential type-related
errors before runtime. This can help improve code quality and prevent
certain types of bugs.
11
3. IDE Support: Some integrated development environments (IDEs) and code
editors can use return type information to provide auto completion
suggestions and perform better code analysis. This can enhance the
development experience and help catch errors early.
In the calling function, the values assigned to the respective variables are
used to calculate the BMI in the called function, utilizing the formula "bmi
= weight / (height ** 2)". The calculated value is then assigned to a
variable and displayed as the first output.
� if-elif statement
Now the second and final execution of the program will be takes place
through the if-elif statement. In python, the ‘if’, ‘elif’, and ‘else’ statement
are used for conditional execution. They allows you to control the flow of
your program based on certain conditions.
12
Here’s the basic syntax:
if condition1:
elif condition2:
Here is an example that demonstrate the usage of ‘if’ , ‘elif’ and ‘else’
statements :
x = 10
if x > 0:
print("x is positive")
elif x < 0:
print("x is negative")
else:
print("x is zero")
13
Similarly in the program we use “if-elif” statement as shown below:
The calculated BMI is utilized to evaluate the conditions within the if-elif
block or statement in the program, as depicted in the figure above. When a
particular condition aligns with the BMI, the corresponding statement is
automatically printed. Thus, this concludes the discussion on the format,
structure, and tools employed to construct the BMI Calculator program.
� Execution
When you run the program the following user interface will appear,
14
Here, the program asks the user to provide their weight as an input. In the
above figure, it is evident that the user has already provided their weight
as an input. The input is then stored in its respective variable, as we
discussed previously. Upon pressing the Enter key, another user interface
will appear, as shown below.
Here, the program asks the user to provide their height as an input. In the
above figure, it is evident that the user has already provided their height as
an input. The input is then stored in its respective variable, as we discussed
previously. Upon pressing the Enter key, the final execution interface of the
output will appear, as shown below.
The final result has been executed above, displaying the user's weight and
height assigned to the respective variables. Additionally, the user's BMI has
been calculated, and their category based on the BMI is shown. The
program provides tips to the user on maintaining a healthy BMI. By
examining the above execution of the program, it reveals that the user falls
into the "Overweight" category based on their weight and height.
Consequently, appropriate tips are given to help the user lose weight.
15
Here, above, the final result of another input given by the user is
calculated based on their weight and height, determining their BMI
category as "Obese." Furthermore, the program provides tips on
maintaining a healthy BMI and adopting a healthier lifestyle.
Here, above, the final result of another input given by the user is
calculated based on their weight and height, determining their BMI
category as “Normal weight.” Furthermore, the program provides tips on
maintaining a healthy BMI and adopting a healthier lifestyle.
The BMI Calculator program successfully performs the calculation of
BMI based on user-provided weight and height inputs. By categorizing the
user's BMI, it provides valuable insights into their current health status.
Additionally, the program offers practical tips and recommendations for
maintaining a healthy BMI and adopting a healthier lifestyle.
16
ChapTEr : 06 CONClUSION
In conclusion, developing a BMI calculator in Python offers a practical
and valuable project that combines programming skills with health
assessment. Through this mini project, we have learned how to calculate
BMI using the weight and height values provided by the user and how to
classify weight status based on the calculated BMI.
17
this project to create more advanced applications or contribute to other
health-related projects.
18
ChapTEr : 07 bIblIOGraphY
ChatGPT
Publisher : chat.openi.com
https://openai.com/chatgpt
GeeksforGeeks
Publisher : Ventura Publisher
GeeksforGeeks | A computer science portal for geeks
GitHub
Publisher : Microsoft
GitHub: Let’s build from here · GitHub
19