Each of the previous exercises can be rewritten to use
variables instead of expressions using only constants. For example,
if you want to tackle the Fahrenheit to Celsius problem, you might
write something like this:
# Convert 8 C to F
You'll want to rewrite these exercises using variables to get
ready to add input functions.
State Change. Is it true that all programs simply establish a
It can argued that a controller for a device (like a toaster
or a cruise control) simply maintains a steady
state. The notion of state change as a program moves toward
completion doesn't apply because the software is always on. Is this
the case, or does the software controlling a device have internal
For example, consider a toaster with a thermostat, a
“browness” sensor and a single heating element. What
are the inputs? What are the outputs? Are there internal states
while the toaster is making toast?
Input Function Exercises
Refer back to the exercises in the section called “Numeric Types and Expressions” for formulas and other details. Each
of these can be rewritten to use variables and an input conversion. For
example, if you want to tackle the Fahrenheit to Celsius problem, you
might write something like this:
C = input('Celsius: ')
F = 32+C*float(9/5)
Stock Value. Input the number of shares, dollar price and number of
8th's. From these three inputs, compute the total dollar value of
the block of stock.
Convert from °C to °F. Write a short program that will input °C and output °F. A
second program will input °F and output °C.
Periodic Payment. Input the principal, annual percentage rate and number of
payments. Compute the monthly payment. Be sure to divide rate by
12 and multiple payments by 12.
Surface Air Consumption Rate. Write a short program will input the starting pressure,
final pressure, time and maximum depth. Compute and print the
A second program will input a SACR, starting pressure, final
pressure and depth. It will print the time at that depth, and the
time at 10 feet more depth.
Wind Chill. Input a temperature and a wind speed. Output the wind
Force from a Sail. Input the height of the sail and the length. The surface
area is 1/2×h×l. For a wind speed of 25 MPH, compute the force on
the sail. Small boat sails are 25-35 feet high and 6-10 feet
Interactive Mode Revisited
Variables and Assignment Style Notes
Published under the terms of the Open Publication License