15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Why do we get 134L and not 1342 in the example below?<br />

>>> 56l + 78l<br />

134L<br />

5-10. Conversion. Create a pair of functions to convert Fahrenheit to Celsius temperature<br />

values. C = (F - 32) * (5 / 9 ) should help you get started. We recommend you try<br />

true division with this exercise, otherwise take whatever steps are necessary to ensure<br />

accurate results.<br />

5-11. Modulus.<br />

a.<br />

b.<br />

c.<br />

d.<br />

Using loops and numeric operators, output all even numbers from 0 to 20.<br />

Same as part (a), but output all odd numbers up to 20.<br />

From parts (a) and (b), what is an easy way to tell the difference between<br />

even and odd numbers?<br />

Using part (c), write some code to determine if one number divides another. In<br />

your solution, ask the user for both numbers and have your function answer<br />

"yes" or "no" as to whether one number divides another by returning TRue or<br />

False, respectively.<br />

5-12. Limits. Determine the largest and smallest ints, floats, and complex numbers that your<br />

system can handle.<br />

5-13. Conversion. Write a function that will take a time period measured in hours and<br />

minutes and return the total time in minutes only.<br />

5-14. Bank Account Interest. Create a function to take an interest percentage rate for a<br />

bank account, say, a Certificate of Deposit (CD). Calculate and return the Annual<br />

Percentage Yield (APY) if the account balance was compounded daily.<br />

5-15. GCD and LCM. Determine the greatest common divisor and least common multiple of<br />

a pair of integers.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!