Programming Exercises

1. Recursive Printing

Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n.

2. Recursive Multiplication

Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows:

(To keep the function simple, assume that x and y will always hold positive nonzero integers.)

3. Recursive Lines

Write a recursive function that accepts an integer argument, n. The function should display n lines of asterisks on the screen, with the first line showing 1 asterisk, the second line showing 2 asterisks, up to the nth line which shows n asterisks.

4. Largest List Item

Design a function that accepts a list as an argument, and returns the largest value in the list. The function should use recursion to find the largest item.

5. Recursive List Sum

Design a function that accepts a list of numbers as an argument. The function should recursively calculate the sum of all the numbers in the list and return that value.

6. Sum of Numbers

Design a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will return rhe sum of 1, 2, 3, 4, . . . 50. Use recursion to calculate the sum.

7. Recursive Power Method

Design a function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer.

8. Ackermann's Function

Ackermann's Function is a recursive mathematical algorithm that can be used to test how well a system optimizes its performance of recursion. Design a function ackermann (m, n), which solves Ackermann's function. Use the following logic in your function:

If m = 0 then return n + 1 If n = 0 then return ackermann (m — I, 1) Otherwise, return ackermannfm — I > ackennann(m, n — 1)) Once you've designed your function, test it by calling it with small values for m and n.

12.1 Graphical User Interfaces

12.2 Using the Tkinter Module

12.3 Display Text with Label Widgets

12.4 Organizing Widgets with Frames

12.5 Button Widgets and Info Dialog Boxes

12.6 Getting Input with the Entry Widget

12.7 Using Labels as Output Fields

12.8 Radio Buttons and Check Buttons

12.1 Graphical User Interfaces

12.2 Using the Tkinter Module

12.3 Display Text with Label Widgets

12.4 Organizing Widgets with Frames

12.5 Button Widgets and Info Dialog Boxes

12.6 Getting Input with the Entry Widget

12.7 Using Labels as Output Fields

12.8 Radio Buttons and Check Buttons

0 0

Post a comment