With this program I learned the basics of the conditionals in python.
The if, elif and else are functions that evaluate certain conditions and if such condition is true, the program executes a certain code, that code would be the statement of the condition. There can be multiple if, elif and else in your code.
This page is helpful for understandig this concept- https://docs.python.org/3.5/tutorial/controlflow.html
For this program we have to ask the user for a temperature in Farenheit. Then the program has to convert that value to a temperature in Celsius. Also we have to tell the user if water boils or doesn´t at that temperature
The formula for converting Celsius to Farenheit is:
Cº= 5*(Fº-32)/9
Doing that is the first part of the code, and probably the easiest part.
print (“What is the temperature in Farenheit?”)
temp=input()
deg=”degrees”
cel= 5*(int(temp)-32)//9
print (“The temperature in Celsius is:”, cel, deg)
The next part requires the use of the if and else functions.
if cel < 100 and cel > 0:
print (“Water does not boil at this temperature (under typical conditions).”)
if cel > 100:
print (“Water boils at this temperature (under typical conditions).”)
if cel<0:
print (“Water freezes at this temperature”)
The complete code would look like this:
And the program running, like this:
#WSQ05 by alextenablog is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.