Very good questions indeed. Also familiar ones to me. The first is
Exercise 5.28 and the second is Exercise 5.23 from the text book
"Object-Oriented Programming in Python."
Alan's advice was very sound, but I strongly recommend that you work
with your instructor in guiding you through these problems. He or she
is best qualified to know your current level and the context for such
a homework assignment. Of course, reading the book is also likely to
help.
For everyone else, if you like these exercises there are 300 more
where they came from. ;-)
With regard,
Michael
+-----------------------------------------------
| Michael Goldwasser
| Associate Professor
| Dept. Mathematics and Computer Science
| Saint Louis University
| 220 North Grand Blvd.
| St. Louis, MO 63103-2007
On Sunday January 6, 2008, Shumail Siddiqui wrote:
> Investment Thresholds
>
> Define a Python function threshold(dailyGains, goal) that behaves as
> follows. The first parameter is a list of integers that represent the daily
> gains in the value of a stock. The second paramter is a single positive
> number that is a profit goal. The function should return the minimum number
> of days for which the stock should be owned in order to achieve a profit that
> is equal to or greater than the stated goal. If the goal is unreachable, the
> function should return 0.
> For example,
> threshold ([5, 3, 8, 2, 9, 1], 17)
> should return 4 because the goal (17) can be reached after the first four
> days (e.g., 5 + 3 + 8 + 2).
>
> Write a small Python program that uses your threshold() function to
> demonstrate that it works correctly. Your program may use a pre-defined list
> of stock gains or it may generate one randomly (see the "Helpful Hints"
> section below for tips on how to do this). Your program should display this
> list, prompt the user to enter a profit goal, and then print out the total
> number of days required to reach that goal (or a message stating that the
> goal is impossible).
> Word Windows
>
> Define a Python function sliding(word, num) that behaves as follows.
> It should print out each num-length slice of the original word , aligned
> vertically as shown below.
> For example, a call to sliding("examples", 4) should produce the output
>
> exam xamp ampl mple ples
>
>
> Write a small Python program to demonstrate that your sliding()
> function works correctly. Your program should prompt the user to enter a word
> and a window size, and then call sliding() with those values.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor