[Tutor] Urgent: Help
Alan Gauld
alan.gauld at btinternet.com
Mon Jan 7 16:17:56 CET 2008
"Shumail Siddiqui" <shumail_siddiqui at yahoo.com> wrote
> I have a question regarding a functions based assignment. The
> assignment is:
> For this project, you will write two small Python programs:
>
OK, Since this is for homework I cannot give you the answers
but I will point out some things you shouild look at and an approach.
> Investment Thresholds
>
> Define a Python function threshold(dailyGains, goal) that
> behaves as follows.
First define the function and test it using the >>> prompt.
> 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
Use a predefined list initially, it's easier!
Only once that works try introducing random elements.
> Word Windows
One problem at a time...
> This is what I have so far:
>
> import random
> dailyGains = int(random.range(6))
> goal = random.choice(range(4)
missing parenthesis, I assume a typo?
> result = []
> def threshold(dailyGains, goal):
> if goal!= result: 0
> else:
> result.reverse()
> result.remove()
you need to investigate the return statement in functions.
However I don;t understand how you think this will
achieve anything like what the original specification
asked for. You need to use the dailyGains list
somewhere... And why you are checking against
result I don't know.
Can you describe in English what the function should
do and how you would go about it manually using
pen and paper? Can you translate that process to
Python?
> As you can see I am having a great problem.
It looks like the normal learning process to me :-)
Just take your time, solve one bit at a time and
build on your previous work. If you get stuck come
back here and ask specific questions and show
us what you have done.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list