On 04/04/17 17:55, Lisa Hasler Waters wrote:

> A middle school student of mine created a program to calculate simple and
> compound interest. He built it in PyCharm EDU using a Mac running 10.11.6.
> 
> He would like to create a GUI to run this program. Please, can you advise
> on how he could build this?

He could use Tkinter, or he could create an HTML screen and
write a small server using a Framework like Flask.

Whatever he does he will need to dsepsarate his UI from his
logic - a good programming skill regardless of UI.

So his first step should be to create a CLI UI on top of
his existing code such that none of hi functions contain
print() or input() statements, they should all be in
new UI code.

The next step is to convert it to event driven style.
For this code that should almost be a done deal.

Finally decide on his GUI/Web framework and do a tutorial
to get up to speed and fit his new event-driven backend
code into that.

> Here is his code:
> 
> def simple(m, t, r):
>     r = r/100
>     print("The interest is {} and the total is {} ".format(r*m*t, m+r*m*t))

Should return a value not print a message

> def compound(m, t, r):
>     morg = m
>     r = r/100
>     for x in range(0, t):
>         m = m*r+m
>     print("The interest is {} and the total is {} if compounded
> yearly.".format(m-morg, m))
>     m = morg
>     r = r/12
>     for x in range(0, t*12):
>         m = m*r+m
>     print("The interest is {} and the total is {} if compounded
> monthly.".format(m-morg, m))
> 

Possiobly should be two separate methods, and definitely
should be returning values not printing stuff.


> choice = str(input("Would you like to use simple or compound interest? "))
> m = int(input("Input the amount of money you would like to deposit
> (don't use the $ symbol): "))
> t = int(input("Input the amount of time you will be keeping your money
> in the bank (in years): "))
> r = int(input("Input the interest rate the bank offers (don't use the
> % symbol): "))
> 
> if choice == 'simple':
>     simple(m, t, r)
> elif choice == 'compound':
>     compound(m, t, r)
> else:
>     print("Your input is invalid")

This needs to turn into a UI event loop which it almost is
but with no loop and no exit option.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to