0:00
Hey guys, welcome back to another Python
0:02
beginner challenge. If you have been
0:04
following along, awesome because you are
0:06
building real programming muscles
0:08
already. And if you're new here, don't
0:11
worry. You're going to love this. And
0:12
today's exercise is super practical. We
0:15
are going to write a small Python
0:17
program that converts Fahrenheit to
0:20
Celsius. Yeah, just like what weather
0:22
apps do. So we'll follow a simple
0:25
flowchart using Python's you know input
0:28
function and apply a little math magic
0:31
to make it all work. So let's dive right
0:36
So here is what our flowchart says. You
0:39
have to start and read the values f
0:42
which stands for Fahrenheit and use the
0:45
formula five and 5 by 9 and then
0:49
multiply it with F - 32 and display the
0:51
Celsius value and that's the end. So
0:55
it's literally three lines of code but
0:57
don't let that fool you. There's a lot
1:03
All right. First we need to ask user to
1:07
enter the temperature in foreign heat.
1:14
So now remember when we use input in
1:17
Python it returns the value as a string
1:19
right? So first let's take
1:54
So whenever we use input in Python, it
1:57
returns the value as a string
2:00
and we can't subtract numbers from
2:02
strings. So Python will yell at us when
2:05
we do that. So we need to convert that
2:07
string to float like this. You just have
2:12
and it's a method kind of just give it.
2:16
Now the other user can type something
2:18
like 98.6 or 32 or even minus 40 and we
2:23
are good to go. It will take it as a
2:26
And now let's work on applying the
2:29
conversion formula. So this is the cool
2:31
part because it's the formula and here
2:34
is the standard formula to convert
2:36
Fahrenheit to Celsius which is
2:50
5 by 9. So this is the actual formula
2:54
but we have to give foreign heat here
2:57
because that's what we declared as a
3:02
So instead of let's give a variable name
3:09
So this is the standard formula and
3:12
remember to use parentheses here because
3:15
just like in real math Python needs to
3:17
subtract you know minus 32 from
3:19
Fahrenheit before multiplying it by 5 by
3:22
9. So order always matters.
3:27
So now let's display the output. You
3:29
just have to do print.
3:36
foreign heat foreign heat
3:46
but I just copied it from the web. So
3:48
you can do the same thing.
4:10
We are going to give Celsius and we need
4:12
this in decimal. So point colon.2F
4:20
and again we need this symbol.
4:32
So this little point tof inside the f
4:36
string that tells Python to round this
4:38
LCS value to two decimal places. So
4:41
instead of showing 36.6666,
4:44
it will just show 36.67.
4:51
All right. Here is the final working
4:54
program. Let me just close all these
4:59
So far and heat and we have given input
5:03
here and we convert to float and we have
5:05
applied formula here and we just printed
5:10
So let's run this first.
5:15
Like for example, if you're giving any
5:24
So 40° Fahrenheit heat is equal to
5:28
And I just have to give some space here.
5:31
That's where I mess up. Let's try again.
5:34
This time let's give 80° F. 80° is equal
5:41
So this is how it will work. Let me just
5:44
give you a few bonus tips, especially if
5:46
you're just starting out because always
5:48
convert user input when you're doing
5:53
In all the exercises, we follow the
5:55
same. And also double check the
5:57
formulas. Even one small typo can mess
6:00
up the entire result. Though the program
6:02
works, because of the logic, you might
6:04
not get the expected output. And always
6:08
try to use F strings for cleaner output
6:11
and formatting. And don't overthink
6:14
small problems. Break each and
6:17
everything into steps like we did here.
6:21
And honestly, this is how real
6:22
programmers work every day.
6:26
And that's it for exercise four, which
6:28
is short, useful, and a perfect way to
6:31
practice your Python skills. And if you
6:33
have found this helpful, give this video
6:35
a like, hit that subscribe button, and
6:37
turn on the notification bell so you
6:40
don't miss any upcoming episodes. In the
6:42
next one, we'll take things a step
6:44
further with new logic and challenges.
6:46
And can't wait to see you there. Thanks
6:48
for learning with me. Happy coding.