[Tutor] Issue with Python

Alan Gauld alan.gauld at btinternet.com
Fri Nov 14 01:51:49 CET 2014


On 13/11/14 23:07, Daniel Williams wrote:
> Hi, I'm dw0391
> I have an issue with a class task that my teacher can't seem to fix.

Please explain what the issue is, don;t make us guess.
And don't expect us to run code that you acknowledge
is buggy!

> We were asked to write the code for a 'no interest loan repayment
> calculator'. I tried, but it did not work.

As above. 'did not work' is way too vague. What happens? Does the 
program give an error? If so include the error mesage. Diod it
crash your computer and format your hard drive? If so tell us
(thats why I won't run untrusted buggy code!) Or did it seem
to run and just gove a result you did not expect? Tell us.

In this case its fairly easy to spot the problem in the code but
in future make it easy for us to help you and you will get more
help.

> Attached is the relevant file, 'Prog 6'

Please include the code in the mail message rather than
as an attachment. It makes replying much easier!


 > def payrate(loantotal, timetotal):
 >     rate = loantotal / timetotal
 >     return rate
 >
 > def main():
 >     loantotal = float(input("Total of Loan: $"))
 >     timetotal = float(input("Time Provided (in months):"))
 >
 >     rate = payrate(loantotal, timetotal)

rate is a local variable inside the main() function, it is
not visible outside.

 > print ("You need to pay:"% rate, "each month")

So your print statement needs to be inside the main function
to be able to print rate.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list