2.8. Exercises

  1. Which of the following are invalid variable names? Why?

    integer
    6_05
    month
    XxX
    a$
    _count
    file extension
    file_extension
    FILENAME
    _100
  2. Which of the following are invalid constants? Why?

    123.456
    +1.23e+02
    0005
    +.00004
    e-02
    -1e-1
    2.44  e −03
  3. Calculate the results and type of each of the following expressions. Then enter them into a program to verify your answers.

    200 mod 7
    100 / 25 * 4
            ((100.5 as integer) - (50.99 as integer) ) ^ 2
            (1.234e+2 + 2.345e+3)
            2 ^ 0.5  -- what does this do?
            (6 ^ 2 + 8 ^ 2) ^ 0.5
            100.25 + 7.5 div 5 - 29 mod 8
  4. Given the following formula for converting degrees Fahrenheit (F) to degrees Celsius (C)

    C = 5 ( (F - 32) / 9

    calculate the equivalent Celsius temperatures for the following Fahrenheit temperatures:

    100° F
            32° F
            0° F
            55° F

    First perform the calculation using the formula. Then use the built-in classes degrees Fahrenheit and degrees Celsius to do the conversions.

  5. Write a program that evaluates the following expression:

    (3.31 ( 10-8 + 2.01 ( 10-7) / (7.16 ( 10-6 + 2.01 ( 10-8)
  6. To round off an integer i to the next largest even multiple of another integer j, the following formula can be used:

    NextMultiple = i + j - i mod j

    For example, to round off 256 days to the next largest number of days evenly divisible by a week, values of i = 256 and j = 7 can be substituted into the preceding formula as follows:

    NextMultiple   =   256 + 7 - 256 mod 7
                   =   256 + 7 - 4
                   =   259

    Write a program to find the next largest even multiple for the following values of i and j:

    i j ...

Get Beginning AppleScript® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.