Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Variable and Assignment Exercises

Variable and Assignment Exercises

  1. Extend Previous Exercises. Rework the exercises in the section called “Numeric Types and Expressions”.

    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:

    #!/usr/bib/env python
    # Convert 8 C to F
    C=8
    F=32+C*float(9/5)
    print "celsius",C,"fahrenheit",F
    
    

    You'll want to rewrite these exercises using variables to get ready to add input functions.

  2. State Change. Is it true that all programs simply establish a state?

    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 state changes?

    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)
print "celsius",C,"fahrenheit",F
  1. 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.

  2. 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.

  3. 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.

  4. Surface Air Consumption Rate. Write a short program will input the starting pressure, final pressure, time and maximum depth. Compute and print the SACR.

    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.

  5. Wind Chill. Input a temperature and a wind speed. Output the wind chill.

  6. 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 long.


 
 
  Published under the terms of the Open Publication License Design by Interspire