top of page

If Operations

Checkpoint #1

Whitespace

Elif

Checkpoint #2

Nested If

Summary

Lesson 3 Summary

In Lesson 3 we have covered the following:

  • If Statements

  • Whitespace Issues

  • Elif Statements

  • Nested If Statements

 

Let's put together everything that we learned and try a real world example.

​

Review the table below - it shows the freezing and boiling temperatures for a few common substances. It is often important in science to know at what temperature certain substances change states of matter. Let's create a program that will tell us whether our substance is freezing, boiling or neither.

Substances

Water

Carbon Dioxide

Mercury

Ethanol

Gold

Freezing Point (ËšC)

0Ëš

-78Ëš

-39Ëš

-114Ëš

1064Ëš

Boiling Point (ËšC)

100Ëš

-57Ëš

357Ëš

78Ëš

2856Ëš

1. Start by creating two variables, one to contain our substance and one to contain our temperature.

2. Create a series of If Statements to check which substance we're dealing with (you can select two for simplicity)

3. Then within each If Statement, we should check to see if the temperature is above the boiling point, lower than the freezing point, or neither

4. The result should be a printed statement that says: [Substance] is [a solid, a liquid, or a gas]

​

Hint: Your first two lines of code might look something like this below

1 substance = "mercury"

2 temperature = 16

bottom of page