With the help of the flowchart, create a Python program to read two numbers and find their sum.
Python Exercise #01: Create a Python Program to Add Two Numbers
š Python Exercises for Beginners ā Practice and improve your skills!
š Access here: https://buymeacoffee.com/usandopython/e/396802
Support The Channel š
š You can support me directly with a donation on Buy Me a Coffee.
https://buymeacoffee.com/pybeginners
Every contribution, no matter how small, makes a difference! š
ā”ļø Connect with me on:
š Website: https://www.usandopy.com/en/
šø Instagram: https://www.instagram.com/pybeginners/
š¦ Twitter: https://x.com/joaofuti_
š¢ Threads: https://www.threads.net/@pybeginners
š LinkedIn: https://www.linkedin.com/in/joao-futi-muanda-16b980175/
Show More Show Less View Video Transcript
0:02
hello guys welcome back to the channel
0:04
here So today we are going to start
0:05
solving some Python program okay for
0:07
beginners So the first question that we
0:09
have is this one Okay with the help of
0:11
the flowchart create a Python program to
0:12
read two numbers and find their sum So
0:15
we have here one flowchart that can help
0:17
us how we can create this same program
0:18
that allow us to read two numbers and
0:21
find their sum Okay apart of this we
0:23
have also some tips that can we can use
0:26
to help us in solving this same problem
0:29
So these programs okay this Python
0:31
exercise for beginners okay is
0:33
especially for those who are start to
0:35
learn in Python and still having some
0:37
kind of doubt okay so this you can use
0:39
this uh exercise so that you can
0:41
practice Python more okay and you can be
0:44
more familiar with Python and this also
0:46
good also can help you okay to build
0:48
your logical thinking okay by solving
0:50
this exercise so that's why we have this
0:53
flowchart flowchart can will help us to
0:55
follow okay the flow the program how the
0:57
program must be built how the program
0:58
must be created Okay so that's why we
1:00
have a flowchart and we have some tips
1:02
that can help us okay to use some kind
1:05
of Python stuff that will help us to
1:08
solve this same exercise Okay so without
1:11
talking too much let's jump into our VS
1:13
code so that we can start solving our
1:15
first exercise
1:19
See if you are someone who started
1:21
learning Python and want to practice
1:23
Python code This ebook that I create
1:24
okay will help you to practice Python
1:27
with a visual flowcharts So I create
1:29
this book so that you can create Python
1:31
You can practice Python Okay So there
1:32
are a lot of topics that this ebook
1:34
cover Okay But this is more recommended
1:37
for beginners in Python or for those who
1:39
starting learning Python itself So there
1:42
are a lot of exercise that you can uh
1:44
solve You can go through this Okay the
1:46
most of exercise they it has some of
1:49
flow chart So that will help you to
1:51
understand the program and to build your
1:52
logical thinking So apart of that this
1:55
same ebook okay there are kind of tips
1:57
that will help you okay to remember
1:59
about some Python topics that you can
2:01
use while solving this same problem uh
2:04
the same exercise So there are a lot of
2:06
exercise okay more than 30 exercise as
2:08
you can see most of them it has kind of
2:11
different problem different of challenge
2:13
okay so you can solve you can practice
2:16
Python by solving this same exercise so
2:19
I'll keep the link of this ebook okay in
2:22
the description in the description of
2:23
this video so that you can go grab it
2:26
and enjoy solving problems so very now I
2:29
am in my VS code okay as we you can see
2:31
uh this is our first exercise and this
2:33
is my VS code so you You can use any
2:36
code interpreter that you wish Okay But
2:38
I'm going to use VS code because it is
2:40
very easy and very simple to work with
2:42
it So as we said okay the first our
2:44
first problem is the following With the
2:46
help of the flow create a Python program
2:48
to read two numbers Okay But the first
2:49
thing that I need to do first is to
2:51
create my a new Python script So I'm
2:53
going to create a new Python script Let
2:54
me I'll call it as
2:59
exercise one Okay
3:01
01 dot pi Perfect So now we have it our
3:06
script I'm going to minimize this so
3:08
that I can concentrate more in the
3:09
solution So Ctrl + B Boom Like this So
3:12
this is our equation and this is the
3:14
flowchart that I can use to help me and
3:16
the tips that also can use to help me
3:18
solving this same problem So the first
3:21
thing that we need to do as we can say
3:22
start the problem first we need to read
3:25
the inputs okay or the values from the
3:28
user So see when you are solving any
3:31
type of problem okay first try to solve
3:33
it the simplest way possible okay the
3:37
most simple way don't try to put like a
3:39
complicate things in the beginning
3:40
itself okay first try to solve it in the
3:42
simple way okay then after that you'll
3:46
start like making some change so that it
3:48
can look more better so how can I do
3:51
this in the simple way so the program
3:53
says okay a program to read the two
3:56
numbers and find their sum okay so the
3:58
first thing that we are going to Okay
4:00
let's create kind of program Okay just
4:02
to read two numbers So let me follow
4:04
this Okay read AB So I'm just going to
4:06
create a variable called like a Okay
4:09
this A would be for example I'm going to
4:12
just give a number Okay for now A will
4:14
be equal
4:15
10 Then I'm going to create another
4:18
variable will be B Uh B will be equal 20
4:21
Okay then what is it okay sum equal A +
4:24
B So sum equal A + B So I'm going to
4:27
create a variable called sum So this sum
4:30
will be equal a + b Then what is it okay
4:35
print sum So now I need to print sum Let
4:37
me say print open and close What I'm
4:39
going to print i'm going Oh I did a
4:41
mistake Print What I'm going to print
4:44
i'm going to print some Okay let's print
4:48
some
4:50
So let me increase
4:55
some I'm going to print some Let me say
4:58
sum Okay R some Perfect Then stop Okay
5:02
So this is a simple Python program Okay
5:04
Without anything Okay So this is the
5:06
simplest way that you can solve this
5:08
program So let me save and let me run to
5:10
see what we have Okay So if I run this
5:12
program this is where we can see the
5:14
output As you can see is equal 30
5:16
because 10 + 20 is equal 30 Okay So now
5:20
let's try to make this program better
5:22
Okay Because it said okay create a
5:24
Python program to read two numbers and
5:27
find their sum Okay So if if it is
5:29
saying about read okay we need to get
5:31
the input from the user Okay Because uh
5:34
the program cannot be like this like
5:36
this is kind of simple way okay of
5:38
solving the things So now as you said
5:40
okay we can use input and output Okay
5:43
Consider input and output because
5:44
they're using input function to get the
5:45
values entered by the user So for that
5:48
let's say okay let me use
5:50
input input open and close So what we
5:53
I'm going to say let me say like
5:57
enter the first number enter the first
6:00
number the first enter the first number
6:03
okay dot and give me the space then the
6:06
second one will be also the same thing
6:08
just let me copy this guy okay I'm going
6:10
to copy it and boom paste it okay as you
6:12
can say uh input enter the first number
6:15
here enter the second number
6:18
second enter the second number okay
6:21
perfect so now If I run this Okay let me
6:24
run this now again
6:27
Run As you can see let me Oh first let
6:30
me close this Let me clear this
6:33
Clear And if I run the program what you
6:35
say enter the first number So to enter
6:39
the first number I'm going to give like
6:40
for example uh again 10 Enter the second
6:44
number 20 Boom What this gave equal 10
6:49
uh 10 20 Okay So it's not summing it's
6:53
not uh how can I say it's not doing
6:55
addition okay it's just it's just
6:56
concatenating the value So as we know in
6:59
Python whatever numbers that uh we give
7:03
okay by input or we get by input is
7:06
considered as a string okay so that's
7:09
why there is a need for us to convert
7:10
these values that we are getting from
7:12
the input So in order to do that we can
7:15
do something like this Okay So this here
7:17
where we have entered the first numbers
7:19
we can do something like this Okay let
7:20
me close this We can come here and do
7:22
convert this numbers Okay so let me
7:24
convert it into float float open and
7:29
close it Okay so this way whatever
7:31
number that it will get from this input
7:33
Okay it will be converted into float
7:36
Okay so that's why we have here some
7:37
tips that they said Okay tip for
7:39
converter Okay explore how to convert
7:41
input which is usually string Okay to
7:43
numeric data types for for example using
7:46
float to convert string input to
7:48
floating point Okay so that's what I did
7:50
here I'm I'm going to use this to
7:53
convert this value into float number So
7:56
I'm going to do the same for this guy
7:57
Okay float open And let me come here and
8:01
close Perfect So now I can try again
8:04
Okay let me run again the program Enter
8:07
the first number Okay we have again
8:10
enter the first number So what the first
8:11
number can I do uh I'm going to give 10
8:15
and 20 Boom As you can see now it's
8:17
going 30.0 Okay So now the program is
8:20
writing perfectly Okay But the way that
8:22
is giving okay the let's try to make it
8:25
better Okay Like change this result not
8:28
just giving by 30 Okay It says let's at
8:31
least say okay the sum of uh blah blah
8:34
blah blah it's equal to blah Let's do
8:36
something like this Okay So here okay
8:39
and let's also change the variable name
8:41
Okay Because when we are creating those
8:43
things okay we need to start organizing
8:45
our code because like giving name of the
8:47
variable like a and b is not a good okay
8:49
so let's change this to something like
8:52
okay first
8:55
number
8:57
first number okay so now we need to give
9:01
uh now we need need we need to kind of
9:05
okay making our program looking better
9:06
okay more readable so that anyone can
9:08
understand the thing what's going on for
9:10
which purposes the program Okay So
9:12
that's why I said when you are creating
9:13
those program when you're solving any
9:15
problem okay first start simple okay
9:18
solve it in the simplest way possible
9:21
then when you get the result okay then
9:22
start making some change okay so that so
9:24
that the program can be a good program a
9:26
good program okay like changing the
9:29
variables name changing the input output
9:31
like start making small change so that
9:33
it can start looking good okay and more
9:36
easy to understand so now let's change
9:38
here okay this will be the second number
9:42
second number So now this will be okay
9:48
uh first number
9:50
plus second number Perfect Okay Now this
9:54
way is more easy for us to understand
9:55
Okay And uh here also in the top let's
9:58
do some kind of comment Okay Something
10:00
like this Okay
10:02
Program
10:04
program to program to sum two numbers
10:07
Okay Or to add two numbers program to
10:10
add two numbers Program to add two
10:13
numbers Okay So like this we are
10:15
starting changing our things Okay So now
10:18
after that okay let's come here again
10:20
also for them sum equal first plus
10:22
second Okay Here where we have
10:25
uh first plus second we can keep it but
10:28
let's change this name name here Okay
10:30
like sum is not a good name itself Okay
10:33
let's call it for example at least like
10:35
a result I think is the better name
10:38
Result Result Okay So then after this
10:41
okay let's change here also Let's remove
10:42
this guy and put here like
10:45
results Results Okay Save Perfect Okay
10:49
Now that we change the variable name so
10:51
it's more readable this way And let me
10:54
save this So uh then after this we need
10:59
to do something more Let me see First
11:01
number second number result first number
11:03
plus second number Perfect
11:05
Okay And uh the next thing that we need
11:08
to change now is the output Okay The
11:11
output message Let's say something like
11:13
this Okay So here result Okay I'm just
11:15
going to remove this guy But I'm going
11:17
to keep print Let's I'm going to use f
11:19
string Okay To do something like this
11:21
Now let's me do something like
11:23
okay let's say the
11:27
sum of
11:30
uh here I'm going to open and close will
11:32
be the first number Okay
11:35
plus then open and close again will be
11:38
the second number okay it's equal okay
11:42
equal then here I'm going to put the
11:44
last number okay the result itself now
11:46
here I'm going to say result okay now
11:50
for this I'm going to put second
11:53
number then here I'm going to give like
11:58
first first number okay so there are a
12:02
lot of way that you can solve this same
12:03
problem Okay So this is one of way that
12:05
I found Okay But you for sure when you
12:08
try you will find another better way
12:09
that you can solve this same problem
12:11
Okay So the way that I'm doing doesn't
12:13
mean is the correct way No because the
12:15
way that I'm thinking is completely the
12:18
different that the way that you'll be
12:20
thinking Okay For solving this same
12:22
problem So that's why we have some tips
12:24
So from these tips you can make a lot of
12:26
change in this same problem Okay For the
12:28
way that I'm solving this I don't know
12:29
if it's correct I don't know if it's the
12:31
better way or not but it's kind of okay
12:34
normal way okay we can understand what
12:35
the program does for we have some
12:37
comments to make us understand and we
12:39
have kind of good variable names and
12:41
also okay a good print message okay so
12:45
now let's try our results save this and
12:47
if I run this
12:49
guy come here on top and let's see he
12:51
said enter the first number so the first
12:53
number what's the first number let's
12:54
give 10 the second number let's give 20
12:56
boom said the sum of 10 + 20 equal 30 So
13:01
this is how we can solve this problem
13:03
Okay So as I said okay there is there is
13:05
a lot of way that you can solve this
13:06
same problem But this is the way that I
13:08
found how to solve this problem Go So
13:11
guys this way we just solve our first
13:13
Python exercise Okay so if you want to
13:15
get this same ebook that I'm using to
13:16
solve this same exercise Okay there
13:18
there are lot of uh exercise problems
13:21
here in this same ebook Okay so you can
13:24
find the link in the description of this
13:26
same video Okay I'll keep it there So
13:28
you can go and grab the same ebook and
13:30
start solving your exercise Okay So I'm
13:32
stay here My name is J See you in the
13:34
next video Bye-bye
#Puzzles & Brainteasers
#Scripting Languages
#Computer Education

