In this hands-on video, you’ll learn how to calculate simple interest in Python using user input, float conversion, and a basic formula used in real-world banking. This is the second exercise in our Python Flowchart Series — perfect for beginners who want to learn by doing.
🔍 What You'll Learn:
✅ How to take multiple inputs from the user (amount, years, rate)
✅ Why we use float() instead of int()
✅ How to apply the formula: Interest = (Amount × Years × Rate) / 100
✅ How to format the output using Python f-strings
✅ Tips on writing clean, beginner-friendly code
How to Calculate a Simple Interest in Python - Python Beginner Exercise #02
📚 Check out more learning resources:
📝 Blogs: https://www.pybeginners.com/
💼 LinkedIn: https://www.linkedin.com/newsletters/pybeginners-7267881715929415681/
📌 New videos every week — covering Python basics, hands-on exercises, projects, and career tips!
👉 Subscribe, join the PyBeginners family, and let's make Python simple together 💻💬
#LearnPython #PyBeginners #PythonForBeginners #PythonMadeEasy
Show More Show Less View Video Transcript
0:00
Hey friends, welcome back to our Python
0:02
exercise series. In the last video, we
0:05
wrote a simple program to add two
0:07
numbers using input and float. But
0:10
today, we are going to level up just a
0:13
little bit. We are going to calculate
0:15
interest on a bank deposit just like
0:18
they do at banks. And don't worry, it's
0:21
still beginner friendly. I definitely
0:23
promise. We are just going to follow the
0:26
flowchart and build it step by step.
0:29
Nice and easy. Let's dive in.
0:33
So here what we are trying to do. So
0:37
here what the flowchart actually says
0:41
for this exercise. We are going to start
0:43
we are going to take the values like
0:45
amount years and rate and we use this
0:48
formula which is interest equal to
0:50
amount into years into rate by 100 and
0:54
then we will show the interest and then
0:56
that's the end. So that is how we'll
0:59
stop.
1:00
Super simple. Basically we are writing a
1:03
program that take input from the user
1:06
uses a formula to calculate the interest
1:09
and then displays the result. So let's
1:12
break that down. So step one is asking
1:15
the user for the three key pieces of
1:18
data which is amount the amount they are
1:20
depositing and the number of years and
1:23
the interest rate. So here's the code
1:26
for that.
1:27
So just give amount equal to
1:34
input.
1:38
Enter the deposit amount.
1:48
And now we need years
1:52
input.
1:57
Enter the number of years
2:05
and then we need
2:10
rate
2:13
input.
2:17
Enter the
2:20
interest rate
2:24
in
2:26
percentage.
2:29
Okay. But we need all these inputs in
2:33
flo float, right? You I think you have
2:35
that in mind that it will take input in
2:38
string. So we need that in float because
2:41
float is more flexible compared to
2:43
integer. So I'm just converting
2:45
everything to float.
2:48
So float.
2:59
Okay.
3:02
Because the amounts can be in decimals
3:05
and interest rate also often like 7.5%
3:09
and even time might be 1.5 years in some
3:12
cases. So using float makes our program
3:15
more flexible.
3:18
So now that we have our input and now we
3:21
can plug it into the simple interest
3:23
formula, right? The formula which we
3:25
have already seen this one. Interest
3:28
equal to amount into years into rate by
3:30
100.
3:32
So I'm going to do the same interest
3:37
equal to amount
3:41
into
3:43
years
3:45
into
3:47
rate
3:49
by 100.
3:51
Let's say someone enters amount 1,000
3:54
and years maybe 2 years and rate may be
3:57
five. So the calculation will be
3:59
something like 1,000 into 2 into 5 by
4:02
100. So which can be equal to 100. And
4:07
just like that we've got the result. If
4:09
you want me to print
4:12
interest
4:20
and amount can be 1,000
4:24
years two rate 5%. It's 100.0.
4:31
Okay. Now we have seen the final output
4:35
and now that's how we'll show the final
4:37
output to the user. But this is not the
4:39
right way to show the user. Let's make
4:41
it you know simple
4:43
just a little bit formal so that user
4:46
can feel like okay this is the interest.
4:49
We the developers know that it is the
4:51
interest but how user will understand
4:53
that it's the interest. So just give
4:56
some space and just give the interest
4:59
earned ease.
5:01
So if you rerun this
5:03
and just give them 202
5:09
I gave something just like that. So the
5:12
interest earned is 200.0.
5:18
So now
5:21
that's the actual exercise. We have
5:23
completed the exercise but let's make it
5:25
little nicer using an F string because
5:27
we have learned F string and we also
5:30
must understand how to implement and use
5:32
that F string in our exercises not just
5:35
in our exercises when we are building
5:37
something bigger then at the time you
5:39
know keeping everything well organized
5:41
by using these F strings and brackets
5:44
here and there can make you know look
5:46
your program little bit nicer to even to
5:49
the other developers as well. It's kind
5:50
of like an impression as well I could
5:52
say because that's also a part of your
5:55
you know the way you organize the things
5:57
especially when you're coding. So if you
6:00
guys don't know what an F string is I
6:02
have already made video on F strings.
6:05
I'm going to keep that in the
6:06
description. You can just go there and
6:07
you can just you know go through it and
6:10
just come back here and try to use it as
6:12
an exercise to implement that particular
6:15
F string that you have learned.
6:18
Okay. So I'm just going to give F and
6:21
then the interest earned is
6:25
here just give
6:29
amount
6:32
or interest
6:36
or maybe we can give something like the
6:39
interest earned on
6:50
amount
7:00
over
7:04
years
7:07
at
7:10
rate
7:13
which is percentage is
7:25
interest
7:28
r
7:31
and we need this interest to show up to
7:33
two decimals. So colon
7:37
2 F
7:40
and you can just clear this.
7:48
So the interest earned on,000 rupees
7:52
over 5 years at 5% is something.
7:57
Okay, let's see.
8:09
So the interest earned on,000
8:12
rupees 1,000 over 2.0
8:15
years at 5.0%
8:19
is 100 rupees something like this. So
8:23
that gives you cleaner formatting with
8:25
two decimal places which is perfect for
8:28
money. If you want you can also give
8:30
some space here if you feel it a bit
8:34
awkward. And
8:38
if you want you can also give ears
8:41
and
8:45
rate. So it'll be easy for you to you
8:47
know even read.
9:00
Sorry.
9:13
So the interest earned on rupees 1,000
9:15
over 2 years at rate 6% is 120 rupees.
9:19
Now it's I feel it's more meaningful
9:21
than before. So this is how you can give
9:25
good formatting especially when dealing
9:27
with two decimals which is 2F
9:31
which is you know really perfect for the
9:33
money. And let me show you uh the full
9:35
program al together.
9:39
So here we are actually asking the input
9:43
from the user which is amount years and
9:46
rate and we need everything in float. So
9:48
we converted everything to float and we
9:50
just calculated the interest rate by
9:52
this formula which is already there. So
9:55
amount into years into rate by 100.
9:58
Okay. Now go ahead and try it yourself
10:00
and try entering 5,000 for amount and
10:03
years 3 years and 6.5% interest. So,
10:07
Python will calculate the total interest
10:09
you earn and show you the exact amount.
10:14
So, here are a few tips. If you're just
10:15
starting out, always use float when
10:18
there's a chance like your user might
10:21
enter decimals. You don't need to worry
10:24
about declaring variables and its type
10:28
in Python because it's dynamically
10:30
typed. You don't have to worry about
10:33
declaring variable types, especially in
10:35
Python. And always try to use f strings
10:39
to keep your print statements clean and
10:42
more readable. When you are unsure about
10:44
a calculation, try doing it on paper
10:46
first and then compare the result in
10:49
Python. This is my particular method
10:51
whenever I'm trying to solve a
10:53
particular problem in you know using
10:55
Python or any other programming
10:57
language. So I would suggest you to take
10:59
a pen and paper and
11:02
write amount and what amount you're
11:03
giving years you know rate everything
11:06
I'll write I'll you know have a table in
11:08
front of me and I'll keep that you know
11:11
formula in my mind and I will check
11:13
whether it is you know working
11:15
accordingly or not for this particular
11:18
thing because you already have formula
11:20
sometimes in some cases you don't even
11:22
know the formula and you have to figure
11:24
it out yourself then at the time parent
11:27
fee is the best way to solve the
11:29
particular problem whatever the problem.
11:31
So that will make more you know
11:34
understand how the code is working like
11:36
how each and every line is going through
11:39
and that's a wrap. So with this exercise
11:42
and you have just written a real world
11:43
Python program that calculates simple
11:45
interest and trust me these little
11:48
exercises are building your muscle
11:50
especially for bigger and cooler
11:52
projects later. Don't take it light. If
11:55
you found this video helpful, give it a
11:57
thumbs up, subscribe, and hit the bell
11:59
icon so you don't miss the next
12:01
exercise. And drop a comment if you have
12:03
any doubts or if you'd like, you know, a
12:06
challenge version of this with compound
12:08
interest, then you can do that. Thanks
12:11
for coding with me. See you in the next
12:13
one.

