Building a BMI Calculator with Python | Python Projects for Beginners
Key Takeaways
The video demonstrates how to build a BMI Calculator using Python, covering the basics of data analytics and Python programming for beginners.
Full Transcript
hello everybody today we'll be working on building a BMI calculator in Python now before we get started I want to show you this BMI calculator that I found online and it shows you the basic calculation that they use and that's the one we're going to use in this video and they also have this calculator right down here and some ranges that we can use for our calculator as well so for reference I weigh about 170 I'm about five nine let's calculate this so I'm about a 25.1 BMI which falls into the overweight category that's unfortunate but we can see exactly how this works and how ours should work when we actually build it so we're going to kind of reference this throughout the video so let's go right over here to our BMI calculator we need to calculate weight and height and then run this calculation right here so let's go ahead and copy this and we're going to put it right down here and so now we have our calculation so what we need is we need input from a user and there is an input function within python that we're going to be using so let's actually give me a few more cells so the first thing that we need to calculate is their weight let's type out weight right here I'll say weight is equal to and this is where we'll use our input function so we'll say input and when we actually run this it's just going to give us this blank Square where a user can input something we'll say Alex so this is our output is what the actual user input and it does save it to this variable so if we say print weight it will still print out Alex now this is where we want the user to just like we did before where they'll input their weight so we want to kind of give them a prompt for this we'll put a string in here so I'll do a double quote and then I'll say enter your weight in and we're using pounds let's say pounds colon space so now when we do this it'll say enter your weight in pounds I'll say 170 and then when we run this it does store that now let's do print I should have saved it wait again oops now it's only storing the value of 170. it's not actually storing this string right here so that's really important for when we do our calculations later um I'm going to I'm going to save this right down here because I'm sure I'm going to use that later um so we have that as working now we need to also do our height so let's copy this and we'll put it right here and we'll do height and enter your height in inches so now for this one if we hit enter it's actually running let's stop it really quick and interrupt it let's try running this so it's going to say enter your weight in pounds that's the first input say 170. and then when I hit enter it's going to prompt me for that second input and so in inches 5 9 is 69 inches and then I can hit enter again and now we have both of our inputs now we need this calculation right down here and just like that so now we have weight in pounds times 703 divided by height in inches by height in inches so we actually have weight and it's already written in there but I'm just going to do it like this we'll do weight times 703 so that's pounds that are weight in pounds times 703 divided by now we have our height in inches times the height in inches so this is our calculation right here so let's do this exact same thing let's run this and this times of course is not going to work we need to do our star for both of these all right now this is our calculation so let's run this so we have 170 and that's pounds and inches was 69. hit enter and it says cannot multiply the sequence of non-integer type of string Ah that's because these are being stored in strings so right down here I do and we'll do type of height we run that this is actually a string so we want to change that because we don't need that anymore go to that so we don't want it to be a string we need those to be integers or Floats or really anything besides a string it just needs to be numerical so integer float really so let's do integer and then we'll wrap that input in it and we'll do the same thing for this one now we have an integer for our weight an integer for our height so now when we're running this calculation it should work properly let's run this again our pounds are 70. our height is 69 inches and it's not giving us our output because we're not printing anything okay so I just need to do print BMI let's try this again 170 69 and there is our BMI 25.1 so it worked the exact same as this one so they input well we input our height we inputted our or we input our weight we input our height and then it calculated rbmi the next thing that we need to do is we need to kind of give the user some context is that good is there BMI in within a good range a bad range we don't know so let's go ahead and I'm going to see if I can copy this I know if this will work or not let's go ahead and copy this right down here perfect so what we now need to do is we need to say okay if the user has given us this input we want to give them or tell them if they are a normal weight overweight obese severely obese anything like that and we have these ranges so that should help us out quite a bit so let's just write our if statement and then we'll include it up here but let's go down here and we'll say if and then we'll do BMI and let's just say BMI is greater than zero so if it's greater than zero if they had any input where the BMI was not zero which should be every time if they do it properly and they don't you know put a string in there or something or type out 40 which maybe we should make a prompt for that if that happens then we can say if we'll do BMI and now we need to give that first range so this range right here so if it's under 18.5 so we need to do a less than so if it's less than 18.5 and it just says under it doesn't say under or equal to so I'll keep it at 18.5 so if it's under 18.5 then let's give kind of the output we'll say print and the output or the basically the prompt is underweight so we'll just say you are under under case underweight and just like that um and then we're going to pass several alif statements through here well let's just say else so I guess this would be like if they are if they don't input something properly or something messes up maybe we could write something like um print oops I'm thinking all this through we can write print enter valid inputs or something like this or we can always change that but let's really quickly let's run this okay so I'm not in that range let's make the next one so then I can be within a certain range oops and we need we should need one more a minimum so we'll say alif and LF these next two are this 24.9 so it's going to check this one first so if it's 18.5 or below 18.5 it's automatically going to print this one so this next one we don't have to do like a range or anything we can just say if it's below if it's between 25 and 29.9 so this one actually should be less than or equal to um this one is normal oh whoops 24.9 so this one is 24.9 this one is going to say you are normal weight so let's run this now let's see BMI was 25.1 oh guys I'm just messing up here I apologize all right this is the one that I was part of so now it's going to be part of the overweight crowd now let's run this and now our prompt is you are overweight because remember the BMI was saved right here as 25.1 down here if we run through this it's saying no you're not an oops get rid of that no you're not in under 18.5 you're not under 24.9 if you're under 29.9 you are overweight so that did work properly so that's really good and I don't think I want this to be our output for the person because we're going to add this up here it's just going to give us the BMI and then the output is going to say you are overweight let's make it a little bit more customized um I'm going to say name is equal to input and then we'll say enter your name um so it'll be into your name we'll do Alex 70. 69 there's our BMI now it's going to run through this logic or it will run through this logic in just a second when we actually finish this so then we have 34.9 and let's do one more oops and then this one's going to be for 39.9 so this one was overweight this one is obese severely obese so we'll say severely severely obese and then anything that's over that 40 and over so if it's not this one anything else should be morbidly obese so actually this else statement right here should say uh you are you are severely obese this is going to say morbidly morbidly obese now I added that name up here because I wanted to add that down below actually so we're going to say name plus and then we'll do like comma you are underweight so I'll be a little bit more personalized uh I think it'll I think it'll be a nice touch I really do do it like this I will say you and let's go back and do that to all of them and let me see how quickly I can do this whoops what I do get rid of that name plus you like that geez you guys have seen me mess up a ton name plus u and then name plus u so now let's run this and now it's a little more personalized it says Alex you are overweight so this is all really good now this is an if statement um what we had done before I think is actually what we should put right down here so we'll say else and then if that doesn't work we'll say what do we say enter valid input we'll just put that and look let me see if I can test this out don't know if this will error out or if this will even work let me just see if I can mess with it and see if I can get it to work actually let's copy this we're going to copy this whole thing we're going to include it right here and now we have basically our entire calculator so um let's run this enter your name we'll say Alex enter your pounds 170 into your inches 69 and then it's going to say 25.1 Alex you are overweight and that's perfect we could even go as far as adding like some feedback we say you are overweight and then it would be a period and we could say um you need to exercise more stop sitting and writing so many python tutorials so now if we run this we'll do Alex 170 69 it says Alex you were overweight you need to exercise more and stop sitting and writing so many python tutorials period and that's it this is the entire project um you can go a ton farther you can include much more complex logic you could even build out a UI to create your own you know app just like this where it has this input and this UI you can build that out with in Jupiter notebooks with python but that's not really what this tutorial is for this is just to kind of help you think through some of the logic of creating something like this so you know I hope that this was helpful I hope that this was fun I like creating stuff like this we have two other projects that we're going to do and maybe I'll include more but we have two right now that I have planned and I hope those are helpful this is probably our easiest one and they'll get a little bit more difficult in the next projects so I hope that this was fun I hope that this was helpful and that you can now kind of utilize those python skills that you've been working on if you like this video be sure to like And subscribe below and I'll see you in the next video foreign [Music]
Original Description
Take my Full Python Course Here: https://bit.ly/48O581R
In this tutorial we will walk through how to create a BMI Calculator in Python!
Project Code in Github:
https://github.com/AlexTheAnalyst/PythonYouTubeSeries/blob/main/Python%20Project%20for%20Beginners%20-%20BMI%20Calculator.ipynb
Favorite Python Courses:
📖Python for Everybody Specialization - https://imp.i384100.net/jWdkA0
📖Data Analysis with Python - https://coursera.pxf.io/BXY3Wy
____________________________________________
SUBSCRIBE!
Do you want to become a Data Analyst? That's what this channel is all about! My goal is to help you learn everything you need in order to start your career or even switch your career into Data Analytics. Be sure to subscribe to not miss out on any content!
____________________________________________
RESOURCES:
Coursera Courses:
📖Google Data Analyst Certification: https://coursera.pxf.io/5bBd62
📖Data Analysis with Python - https://coursera.pxf.io/BXY3Wy
📖IBM Data Analysis Specialization - https://coursera.pxf.io/AoYOdR
📖Tableau Data Visualization - https://coursera.pxf.io/MXYqaN
Udemy Courses:
📖Python for Data Analysis and Visualization- https://bit.ly/3hhX4LX
📖Statistics for Data Science - https://bit.ly/37jqDbq
📖SQL for Data Analysts (SSMS) - https://bit.ly/3fkqEij
📖Tableau A-Z - http://bit.ly/385lYvN
*Please note I may earn a small commission for any purchase through these links - Thanks for supporting the channel!*
____________________________________________
BECOME A MEMBER -
Want to support the channel? Consider becoming a member! I do Monthly Livestreams for Members and you get some awesome Emoji's to use in chat and comments!
https://www.youtube.com/channel/UC7cs8q-gJRlGwj4A8OmCmXg/join
____________________________________________
Websites:
💻Website: AlexTheAnalyst.com
💾GitHub: https://github.com/AlexTheAnalyst
📱Instagram: @Alex_The_Analyst
____________________________________________
*All opinions or statements in this video are my own
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Alex The Analyst · Alex The Analyst · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Top 3 Data Analyst Skills in 2020
Alex The Analyst
Truth About Big Companies | Told by a Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Salary | 100k with No Experience
Alex The Analyst
Working at a Big Company Vs Small Company | Told by a Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Resume | Reviewing My Resume! | Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Resume | Complete Guide To Creating A Data Analyst Resume | Tips + Templates + Examples
Alex The Analyst
Switching Careers to Become a Data Analyst | How I Made the Switch
Alex The Analyst
Working With a Recruiter to Land Your First Job as a Data Analyst | LinkedIn Recruiters
Alex The Analyst
Data Analyst Salary in 2020
Alex The Analyst
Data Analyst Resume | Reviewing YOUR Data Analyst Resumes!
Alex The Analyst
Data Analyst Fact Check | 84k Average Starting Salary?? | The Career Force 2020 Data Analyst Salary
Alex The Analyst
SQL Basics Tutorial For Beginners | Installing SQL Server Management Studio and Create Tables | 1/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Select + From Statements | 2/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Where Statement | 3/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Group By + Order By Statements | 4/4
Alex The Analyst
Day in the Life of a Data Analyst | Fortune 500 Edition
Alex The Analyst
Intermediate SQL Tutorial | Inner/Outer Joins | Use Cases
Alex The Analyst
Intermediate SQL Tutorial | Unions | Union Operator
Alex The Analyst
Intermediate SQL Tutorial | Case Statement | Use Cases
Alex The Analyst
Intermediate SQL Tutorial | Having Clause
Alex The Analyst
Intermediate SQL Tutorial | Updating/Deleting Data
Alex The Analyst
Day in the Life of a Data Analyst | Fortune 500 Edition (During Quarantine)
Alex The Analyst
Data Analyst Interview Questions | Phone + In-Person Interview Questions
Alex The Analyst
SQL Interview Questions and Answers for Beginners | Data Analyst Interview Questions
Alex The Analyst
Data Analyst Interview Questions | What To Say vs What NOT To Say
Alex The Analyst
Data Analyst Interviews | Salary Negotiation
Alex The Analyst
Data Analyst Q&A LIVE
Alex The Analyst
Intermediate SQL Tutorial | Aliasing
Alex The Analyst
Data Scientist vs Data Analyst | Which Is Right For You?
Alex The Analyst
Best Online Courses for Data Analysts
Alex The Analyst
Best Free Online Courses for Data Analysts
Alex The Analyst
Data Analyst vs Business Analyst | Which Is Right For You?
Alex The Analyst
Scraping Data Off Twitter Using Python | Twitterscraper + NLP + Data Visualization
Alex The Analyst
Data Analyst Question and Answer | Answering Your YouTube Questions
Alex The Analyst
What Does a Data Analyst Actually Do?
Alex The Analyst
Data Analyst Bootcamps | Are They Worth It?
Alex The Analyst
Top 5 Reasons Not to Become a Data Analyst
Alex The Analyst
Data Analyst Career Path | How to Become a Data Analyst + What to Do Next
Alex The Analyst
Live Data Analyst Q&A #3
Alex The Analyst
Top 5 Reasons Not to Lie on Your Resume
Alex The Analyst
The Hiring Process from an Interviewer's Perspective | Alex The Analyst Show | Episode 1
Alex The Analyst
Top 5 Reasons Data Analytics is a Good Career Choice
Alex The Analyst
How I Changed Careers to Become a Data Analyst | Alex The Analyst Show | Episode 2
Alex The Analyst
Top 5 Reasons You'll Be a Good Data Analyst
Alex The Analyst
Self Taught vs Boot Camp vs Degree | Alex The Analyst Show | Episode 3
Alex The Analyst
Covid and the Data Analyst Job Market | Alex The Analyst Show | Episode 4
Alex The Analyst
Data Analyst Expectations vs Reality
Alex The Analyst
Imposter Syndrome in Tech | Alex The Analyst Show | Episode 5
Alex The Analyst
Top 10 Coursera Courses for Data Analysts
Alex The Analyst
Working at a Startup vs Fortune 500 Company | Alex The Analyst Show | Episode 6
Alex The Analyst
Data Analyst Certifications | Are They Worth It? | Alex The Analyst Show | Episode 7
Alex The Analyst
Top 10 Udemy Courses for Data Analysts
Alex The Analyst
Asking My Wife Your Questions About Me | Alex The Analyst Show | Episode 8
Alex The Analyst
Data Analyst Q&A LIVE #4
Alex The Analyst
Data Analyst Skills Path | What Skills You NEED to Know
Alex The Analyst
What is Analytics Consulting? With John Ariansen | Alex The Analyst Show | Episode 9
Alex The Analyst
Solving LeetCode SQL Interview Questions | Part 1/3
Alex The Analyst
What is No Code Analytics? | Alex The Analyst Show | Episode 10
Alex The Analyst
Top 3 Tips on Using LinkedIn to Land a Job
Alex The Analyst
Completely Unrealistic Jobs on LinkedIn | Alex The Analyst Show | Episode 11
Alex The Analyst
More on: Python for Data
View skill →
🎓
Tutor Explanation
DeepCamp AI