Temperature (Use of conditionals)

This program is intented to be an intruction to conditionals statements if and else. 

The program consist in asking the Temperature in Farenheit to the user, transform it into Celcius, print it in the screen and then letting the user know if water would be boiling or not. 

The source code is this:

temp=float(input(“What is the temperature in Fahrenheit? “))

 

temp=5*(temp-32)/9

print(temp,”ºC”)

 

if(temp<100):

    print(“Water is not boiling”)

else:

    print(“Water is boiling”)

Where we can see how we ask for the temperature to the user and then store it in the variable temp, wich in this case I have declared it as a float, just to get decimals nothing more. 

Then we apply the formula to convert Farenheit into Celcius and store it in the same variable we have created before. If we wanted to recieve an integer answer we could use a floor division // instead of the /.

Then comes the conditionals, the if statement evaluates the expression inside the parenthesis and if the expression returns a true value it execute the code below. The else statement is used to have an alternative when the if statemen expresion returns a false, if it does it executes the block of code below that has the appropiate identation.

Here you can have more information and examples to the use of conditional statements.

This is for my of my course.

CC BY 4.0 Temperature (Use of conditionals) by Nuel is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.