4.9. Exercises

  1. Triangular number n can also be calculated by the formula

    Modify the first triangular number program from this chapter to calculate the triangular number using this formula instead of the repeat with loop.

  2. Rewrite the first triangular number program from this chapter to use the repeat...times form of the repeat statement instead of the repeat with used in the program.

  3. Modify the final version of the triangular number program so that the invalid text entered by the user is displayed. So if the user enters abc in a dialog, you should display the following:

    abc is not a valid integer.
  4. Write a program to find the sum of the squares of the numbers from 1 to n, where the value of n is entered by the user. That is,

  5. Modify the guessing game program to tell the user for each incorrect guess if his guess is too high or too low.

  6. Modify the guessing game program to make some comments based on the number of guesses. For example, you might display "Wow! You got it in only 2 guesses!" or "8 guesses? Better luck next time!"

  7. Modify the guessing game program to let the player play five times. Keep track of the number of guesses taken for each turn. At the end, display the average number of guesses.

  8. Modify the program from the previous exercise to let the user specify how many times he wants ...

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.