Fahrenheit and Celsius Temperature Converter Python Code! Beginner Programming Tutorial.

LeMaster Tech
183 followers
10 Video Views·Apr 22, 2025
In this video I show you how to choose between Fahrenheit and Celsius for building a temperature conversion, then write the formula for transferring between the two values, and how to display the output to the user and then ask if they want to check another value. This short easy to follow tutorial is great for beginners looking to expand their knowledge.
Be sure to check out the channel for over 100 videos of code tutorials across multiple platforms and different software! New content comes out every week so make sure to subscribe to stay up to date, and if you found the video useful please consider leaving a like or let me know what could be done better in the comments!
Thanks for watching and good luck with your code!
what's going on you guys welcome back to
the channel and today's video is how to
convert between celsius and fahrenheit
or fahrenheit in celsius using python
[Music]
all right so fahrenheit and celsius are
you know the two most common
temperatures used in just regulating or
checking what temperature it is outside
and it can be a useful exercise in
python to just um convert between the
two so let's create a function um
that i'll call convert temp and we'll
handle everything we need to do inside
of here so to make this a really robust
function let's make it to where it could
convert between celsius or fahrenheit
inside of the same function so we'll say
origin meaning which temperature are we
converting from and we'll just get it as
an input from the user so to do that you
type the word input and then you put the
text you want to prompt them so we'll
say convert from
which question mark and then let's tell
them we're expecting a c or an f okay
and we'll say convert from which and
then we'll actually ask them the
temperature input so we will make that
an integer value because the thing is
when you get an input it always comes in
as a string unless you convert it so
that int is converting our string
to a uh
to an integer all right so what
temperature and then we'll ask them to
put that in there and now what we do is
we want to set up some if statements so
if the origin meaning they said that
we're going from celsius
so if it's equal to c
then we're going to do one thing and
then we'll say l if origin is equal to f
we're going to do a separate conversion
for that and we'll handle both of them
inside the same function
so
let's go ahead and print
the
fahrenheit
value
is
and then on the next line whoops
on the next line let's actually do the
math um we're just going to and i'm
going to do it all in a print statement
you could put it in an intermediate
variable
but it's going to be temperature input
times 1.8
and then i'm not making this formula up
you can look it up online to go from
celsius to fahrenheit you multiply by
what's technically nine-fifths or 1.8
and then you add 32 to it okay
and so this should be logical if you
know most people know zero at celsius is
32 at fahrenheit and uh 32 at
fahrenheit's zero at celsius so um this
plus 32 parts probably pretty logical
so what i'm going to do is i'm going to
go ahead and copy those two lines right
into the
fahrenheit statement as well
the celsius statement and so we'll say
the celsius value is and then this one
is kind of the opposite of what we just
did it's temperature
minus 32 and then
divide by 1.8 okay so you're a
programmer you've probably done at least
a little bit of math and you know that
this formula is basically the inverse of
that formula this is how you go back
between the two
and so basically all you have to do to
get this to actually run when you start
your program is call it so this is
writing the function and then this is
actually calling the function right here
so this is going to be good enough to
let us do it once stop and rerun so
let's say we want to go from celsius and
we want to check what a hundred degrees
celsius is that's 212 fahrenheit cool
the temperature water boils at
uh that's useful but what would make it
even better because now if i want to go
and do it a second time so now let's
check what 234
fahrenheit is it's 112 celsius cool
if i want to run it multiple times i
have to keep exiting my program and
re-running it so i propose let's just go
one step further and let's make a little
function that we'll put inside the end
of convert temp and we'll call it go
again
and all we have to do is define our go
again function and it's going to be
super easy all we're going to do
is ask them again equals and then input
want to check another
value
question mark and then just like before
we'll tell them what we're expecting a y
or an n so there's always a little bit
to programming to you can tell the user
exactly what you're expecting from them
and they have to actually give it to you
they have to be willing to follow along
or you can try to make things robust
enough that they can't be broken that
requires a fair bit of extra programming
and i'm not going to go that in depth
into this tutorial but so if again
equals y if they follow along and they
say yes i want to go again all we're
going to do is we're going to call that
convert temp function again from inside
go again so
this may seem a little goofy but
basically at the end of our convert temp
function we call a go again function we
ask them if they want to check another
value
and if they say yes then we're going to
go ahead and run the convert temp thing
again and so technically this could keep
looping forever
and if they enter anything other than
yes no n go f yourself any of that then
it's not going to run again and the the
function will be done running so let's
go ahead and check test that out convert
from which let's go from fahrenheit
let's check what 50 fahrenheit is in
celsius it's 10. do we want check mailer
value yeah and this time let's go from
celsius let's check what 50 celsius is
it's 122 in fahrenheit do i want to
check another value go
aft yourself
all right and it's over so um that's
pretty quick easy tutorial useful little
python practice exercise for you
this kind of plug-in could be super
useful in a weather app or something so
hope you found it useful if you did
consider liking the video subscribe to
the channel it helps me out a ton if you
have any questions or want to see
something specific in a future video let
me know about in the comments below and
as always good luck with your code and
thanks for watching thanks bye
