21 Video Views·Apr 22, 2025
Please Like, Subscribe and Check out the rest of our channel for more instructional and useful content like this!
https://www.youtube.com/channel/UCV5Ab39YnXvTZ6Grar9URxQ
In this video you can learn how to create a program that receives user inputs for monthly income and expenses, perform mathematical operations on inputs of varying data types, and then run functions to calculate the margin of either surplus or deficit!
This is a great tutorial for anyone just beginning with python or any object oriented programming as it exposes viewers to a number of rudimentary coding concepts such as data types, inputs and outputs, for and while loops, mathematical operations, string concatenation and more!
Learn to code with practical, real world examples of programs that can prepare you for basic computer science courses, personal software development projects or technical interviews!
If you have any questions or want to see anything in particular on the channel be sure to let us know about it in the comments below! Thanks for watching and good luck with your code!
what's going on you guys welcome back to
the channel uh today we've got a fun
introduction to python practice uh
beginner project where we're gonna build
out a monthly budget calculator tool um
and so before i get started if you find
this or anything else on the channel
useful i really appreciate uh subscribe
to the channel as we're getting started
here helps me know there's some interest
and it really helps me uh get things
going this is a pretty new channel and i
want to keep bringing content like this
to you guys so that's my pitch and now
let's get right into the code
and
so when i say monthly budget calculator
i'm thinking you essentially take the
income that a person expects to get
every month and you prompt them for it
and then you do math and then you
gather info on the expenses and you
return
what we're going to call the margin and
essentially say if they're going to be
above or below next month so it's a
pretty simple formula when you look at
it like this but since income can come
from a variety of different ways and
there's a whole bunch of different
itemized expenses it can be useful to
add together
we're going to go ahead and build out a
tool that gathers the inputs and the
expenses from a user and then does the
math for them
to return that margin so this is a great
intro to python practice project if
you're very familiar with object
oriented programming in python this
might not be the video for you because
it's going to be a little more basic
and just help cover some some
introductory topics
so just to get started
i'll just say print
welcome
to the
budget
estimator
so um i usually just at the beginning of
a
program i like to print out on the
console what's going on so the user
knows exactly what they're doing and why
they're there
and then we'll gather a couple
variables here we'll create a variable
called income
and we'll make it a float
because we don't know they could add
enter a decimal enter an integer and
enter any kind of number so just make it
a float to be safe and then we'll make
an input which is going to prompt the
user to enter a value on the screen
and so we'll say input
enter your monthly and since we want to
not have to calculate tax and everything
we'll just say enter your monthly post
tax
income
and then we'll just tell them us dollars
just so they know what their
uh what units they're entering it in and
then we'll
make another variable and we'll call it
additional and we will make that the
same float input
and we'll just ask for any other revenue
stream so a lot of people
they might have rental properties or a
youtube channel or anything else that's
making money that they don't
necessarily count as primary income and
so it might not be
included in that first variable so we'll
say
enter
any additional income
you expect
next month i mean honestly even maybe
they have a birthday and they think
they're gonna get 200 bucks in there and
they want to include that so
um we'll just uh do the same as before
and then that'll be it for income and so
we'll just do a
uh we'll call it total income
and all you have to do is add those two
together to get this
value and so right here
we're creating an additional variable
after we get these two inputs from the
user
that shows total income
so
now let's go ahead and transition into
the expenses phase of things so let's go
ahead and print out and just say
great your total
income
next month
will be
and let's do so str is going to be the
string conversion of a variable so if
you have something that's numerical
either floats or
integers and you do str and then
parentheses that's going to convert
whatever variable you put in there into
a string and that's the only way that
you can display something with
another string value and have it all
concatenated together like this
so we're going to print out their total
income and we'll say
now
let's
now we will get some expenses
data
okay and now let's enter uh let's go
ahead and do this as a function just
because it can be a great
learning tool here so we'll say
we're going to create a function that's
the def you're defining a function now
and we'll call it
gather expenses
okay and we don't have to pass any
variables in if we did they would have
to go in here and then we just tab one
indentation level inside and now you're
writing
info inside of a function
and so we'll call this first one housing
and we'll use the same float input
format
and we will say
enter your monthly
and instead of post-tax income let's say
enter your monthly housing
expense
so that could be rent or mortgage
and we're gonna just gather a few
expenses here so we'll say that's
housing
then let's do a second one called
utilities and say enter your monthly
utilities
total expense and so this is going to be
like water
electric trash sewer whatever all added
together
and then we'll say
housing utilities let's go ahead and ask
for food
and say enter your monthly
food expenses so that's groceries plus
like meals out and then let's just do a
last one and call it miscellaneous
and that'll be enter your any
let's just say enter any additional
monthly
expenses
okay and so
what we'll do then is we'll make another
one called total expenses just like we
did with income
and we will just do a sum of all those
expenses we just gathered
so housing plus utilities plus food
plus miscellaneous is total expenses
and then let's return
total expenses so that's how you send a
value back out of a function
um and the important thing to know about
python functions is this isn't actually
going to run we've just defined the
function but we haven't called it
anywhere
so the way this program is going to run
when it starts up is line 4 5 6 8 9 10
but it's object oriented programming
meaning it doesn't just go down and
execute every line in order if you have
something like
like this function defined elsewhere you
have to actually call it to get it to
run so it's currently just skipping over
this block
so what we'll do is we'll actually call
we'll go ahead and create another
variable called expense total because
that's the value that we want to get
back
but it's going to be equal to
calling this function so
this is this means that after we say
okay now we'll get some expenses data it
comes down here and expense total is
going to be equal to the value that we
return out of this function that we're
going to run right here
okay
and so if you have any specific
questions about that feel free to let me
know about in the comments i can explain
in a little more depth if you need any
specific additional info but then let's
go ahead and calculate um
well just like before let's say
do print
let's go ahead and say great
your total
expenses next month will be
and then we will put in here
the expense total
very cool
and then let's go ahead and um do
calculate something i called it before i
called it the margin and it's just going
to be the total income
and it's going to be minus the expense
total so this is going to be all the
money you have coming in minus all of
the money you have going out and let's
actually do a conditional if statement
here
to determine what we should display as
the output so let's say if the margin is
greater than zero we'll say greater than
or equal to right so that's at least
breaking even or having some extra money
if that's the case let's go ahead and
print
your total
surplus
next month
will be
and then let's add to that the string
right string conversion of the margin
value
um and then we'll say else you could you
could do another if or you could do an l
if
which is another version of conditional
but basically the only other scenario is
margin is less than zero right because
we handled greater than or equal to in
this first one
so let's just print
you will come up
and let's add the string version of
margin
you will come up
margin dollars and then let's add
another
string
short or we'll say
negative um and i think with these
strings that we're concatenating let's
put a dollar sign in there
um just to make units clear
and let's do that everywhere that'll
look pretty good
okay
so
that's really all we need and then let's
just say
print
and
thanks for
using the monthly
budget tool alright so just good way to
round out our function
so let's go ahead and run this
been a lot of talking a lot of writing
code and let's actually see what it does
all right welcome to the budget
estimator enter your monthly post tax
income
say three thousand dollars we're doing
all right enter any additional income
you expect next month it's my birthday
maybe we're going to get 300 of birthday
money
okay total income will be 3 300. let's
get some ex housing expenses let's say
hundred dollars for rent
all of your utilities added together 300
bucks
food expenses 100 bucks a week let's say
400
and then
50 dollars for fun um so
total expenses next month will be 16.50
your total surplus will be also 16.50 is
that right
i just kind of randomly picked some
numbers let's see here 16.50 yeah these
add together and that's half of 3 300.
okay well that's crazy um so there you
see we had surplus let's go ahead and
run it again um and see if we can get it
to be we're at a negative so 1500 bucks
100 of additional income
but rent is still 900 bucks utilities
are 500 bucks
um 400 for food and some unexpected 1
000 expense next month
well you can see we're going to be 1200
negative so right there that's just a
useful um little tool to help you kind
of see your financials in a pretty clear
way and it's really just a great
introduction to python a way to write an
actual practical function
because so much python can just be like
write an if statement if given two
variables and one is this and the other
is that and you just lose sight of what
could this possibly even apply to in the
real world so
hopefully that was a great little python
practice exercise for you hopefully you
found it useful if you did again i
really appreciate a like and a subscribe
on the channel it helps me out a ton and
if you had any comments on what you saw
here today or you want to see anything
in particular in the future feel free to
drop me a comment below and let me know
about it i will try to get back to you
as soon as possible and as always good
luck with your code and thanks for
watching thanks bye