How to Create a Calculator of BMI in Python


In this example we will show how to implement a simple calculator of BMI (Body Mass Index) based on the input height and weight with Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# computeOfBMI.py
# Python,Calculator of BMI

def computeBIM():
	name = input('Name:')
	height = input('Height(m): ')
	weight = input('Weight(kg): ')
	BIM = float(float(weight) / (float(height)**2))
	
	print("BIM = ", BIM)
	
	if BIM < 18.5:
		print('Your weight is lower than average!')
	elif BIM <= 25:
		print('You are in good figure!')
	elif BIM <= 32:
		print('Your weight is somewhat higher than average!')
	else:
		print('Your weight is higher than average, need consider to lose weight!')

def main():
	computeBIM()
	for i in range(10):
		choose = input('Continue (y / n):')
		if choose == 'y':
			computeBIM()
		else:
			break

if __name__ == '__main__':
	main()

After running the codes above, we can get these results:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments