[Tutor] Urgent: Help
shumail_siddiqui at yahoo.com
Mon Jan 7 08:08:09 CET 2008
I have a question regarding a functions based assignment. The assignment is:
For this project, you will write two small Python programs:
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.
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).
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.
Python contains a set of facilities to handle random number generation. Full details are available at http://docs.python.org/lib/module-random.html. A quick summary is as follows:
Add the statement
at the beginning of your program source code. This tells Python where to find the code that describes how to generate random values.
Pass your list of values to the random.choice() function. The function will return a single randomly-selected element from that list.
For example, random.choice(range(5)) will return a random value in the range 0-4.
Please note that "random" does not necessarily mean "unique"; sequential calls to this function may return the same answer, because it is randomly chosen each time!
This is what I have so far:
dailyGains = int(random.range(6))
goal = random.choice(range(4)
result = 
def threshold(dailyGains, goal):
if goal!= result: 0
As you can see I am having a great problem.
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor