These are the solutions to the problems for the first homework exam. The list of problems are indexed under Class Notes. Problem 1. n = int(raw_input("Enter first number: ")) m = int(raw_input("Enter second number: ")) print n+m, n-m, n*m, (n+m)/2, abs(n-m), (n + m + abs(n - m)) / 2 Problem 2. n = float(raw_input("Enter distance in meters: ")) print n, "meters is", n * 0.000621371192, "miles" print n, "meters is", n * 3.2808399, "feet" print n, "meters is", n * 39.3700787, "inches" Problem 3. ---------------------------------------------------------- radius = float(raw_input("Enter radius: ")) pi = 3.141592 print "Circumf. of circle", 2 * pi * radius print "Area of circle", pi * radius * radius print "Area of sphere", 4 * pi * pow(radius, 2) print "Volume of sphere", 4 * pi * pow(radius, 3) / 3 print "Wrong volume of sphere", 4 / 3 * pi * pow(radius, 3) --------------------------------------------------------------------- Problem 4. ---------------------------------------------------------- height = float(raw_input("Please enter the height: ")) width = float(raw_input("Please enter the width: ")) area = height * width perimeter = height + width + height + width print "Area", area print "Perimeter", perimeter diagonal = pow( height * height + width * width, 0.5) print "Diagonal", diagonal --------------------------------------------------------------------- Problem 5. ---------------------------------------------------------- price = float(raw_input("Price of purchase:")) amount = float(raw_input("Enter amount paid:")) change = amount - price change = int(change * 100) dollars = change / 100 afterdollars = change % 100 quarters = afterdollars / 25 afterdollarsandquarters = afterdollars % 25 dimes = afterdollarsandquarters / 10 remaining = afterdollarsandquarters % 10 nickels = remaining / 5 cents = remaining % 5 print "Change is" print " ", dollars, "dollars" print " ", quarters, "quarters" print " ", dimes, "dimes" print " ", nickels, "nickels" print " ", cents, "cents" --------------------------------------------------------------------- Problem 6. fuel = float(raw_input("Amount of fuel in gallons:")) efficiency = float(raw_input("Car's efficiency:")) price = float(raw_input("Price of fuel per gallon:")) print "Car's autonomy is:", fuel * efficiency, "miles" print "It costs you", 100 / efficiency * price, "dollars to travel 100 miles" --------------------------------------------------------------------- Problem 7. ---------------------------------------------------------- a = raw_input("Enter the first time:") b = raw_input("Enter the second time:") t1 = int(a[0:2]) * 60 + int(a[2:4]) t2 = int(b[0:2]) * 60 + int(b[2:4]) print (t2 - t1) / 60, "hours and", (t2 - t1) % 60, "minutes" --------------------------------------------------------------------- Problem 8. months = "January February March April May June July August SeptemberOctober November December" input = int(raw_input("Enter month number:")) index = (input - 1) * 9 print months[index:index+9] ---------------------------------------------------------------------