Re: [Tutor] learning resources

2017-04-04 Thread Alan Gauld via Tutor
On 04/04/17 12:19, brian mituka wrote:
> what are the best learning resources for a beginner in python...

Look on Python.org and you will find a beginners page with
many links. But... it will depend on whether you can
already program in another language which beginners
page you go to.

I am, of coutse, biased, but you could try my tutorial,
linked below.

> I want to be able to write good code in ! month. 

Define "good code". An expert may tell you he is
still struggling to write good code after 20 years
of using Python. A beginner might tell an employer
that he writes good code after only a few days.

In reality, if you already know how to code in any other
language, you should be able to write productive code
within a week.

If you are a complete programming novice then a month
is probably ambitious!

-- 
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


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-04 Thread Marc Tompkins
On Tue, Apr 4, 2017 at 9:55 AM, Lisa Hasler Waters 
wrote:

> Hello Tutor,
>
> 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?
>
> Others have mentioned Tkinter and HTML; I''d like to put in my two cents'
worth for wxPython .  HTML is probably the best
cross-platform solution, and requires the least extra stuff bolted on, but
wxPython lets you create desktop apps that look like they were actually
developed for the computer they run on.

Alan Gauld's comments about separating the GUI from the program logic are,
as usual, spot-on.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Count for loops

2017-04-04 Thread Alan Gauld via Tutor
On 04/04/17 12:04, Rafael Knuth wrote:
> Sarma: thank you so much, I checked your code, it works. However, can
> you enlighten me what it exactly does?

It just iterates over the PI string manually and compares
the birth date with the first 4 PI string characters.

It would probably be more pythonic and easier to read
to use startswith() instead

> count = 0
> b = "3"+b[2:]

I think this is to eliminate the period after the 3 of PI

> n = len(b)
> for i in range(n-3):
> if b[i:i+4] == get_year:
> count += 1

This is the core of it.
It starts with i = 0 and goes up to i = n-4
If b[i] to b[i+3] equals the birthdate you count
a match

You could rewrite it as

for i in range(n-3):
if b.startswith(get_year, i):
   count += 1

HTH
-- 
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


Re: [Tutor] Asking about Run python script at Startup

2017-04-04 Thread Alex Kleider

On 2017-04-02 21:34, Quang nguyen wrote:

Hi guys,

I do not know how to run my python 3 script after my PI2 finished 
startup.


Have you looked here? :
http://raspberrypi.stackexchange.com/questions/8734/execute-script-on-start-up

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


Re: [Tutor] Count for loops

2017-04-04 Thread Rafael Knuth
Sarma: thank you so much, I checked your code, it works. However, can
you enlighten me what it exactly does?
I do not understand it (yet). Thank you in advance.

file_path = "C:/Users/Rafael/PythonCode/PiDigits.txt"

with open (file_path) as a:
b = a.read()

get_year = input("What year were you born? ")

count = 0
b = "3"+b[2:]
n = len(b)
for i in range(n-3):
if b[i:i+4] == get_year:
count += 1
print("Your birth date occurs %s times in PI!" % (count))
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-04 Thread Sri Kavi
On Tue, Apr 4, 2017 at 10:25, Lisa Hasler Waters wrote:

> Hello Tutor,
>
> 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?
>
>
Please take a look at https://wiki.python.org/moin/GuiProgramming and
https://wiki.python.org/moin/TkInter

Hope that helps.

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


[Tutor] learning resources

2017-04-04 Thread brian mituka
what are the best learning resources for a beginner in python... I want to
be able to write good code in ! month. Thanks..
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-04 Thread Alan Gauld via Tutor
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


[Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-04 Thread Lisa Hasler Waters
Hello Tutor,

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?

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))

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))

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")


Many thanks,

Lisa Waters
-- 
Lisa Waters, PhD
Technology Integration
Middle School Coding
Lower School Digital Literacy
Flint Hill School
703.584.2300
*www.flinthill.org* 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Validating String contains IP address

2017-04-04 Thread Ed Manning
Thank you very much 

Sent from my iPhone

> On Apr 3, 2017, at 7:04 PM, Martin A. Brown  wrote:
> 
> 
> Hello there,
> 
>> what am I going wrong here? i need to validate this is an IP or ask 
>> the question again
>> 
>> untrust_ip_address = raw_input('\nEnter the  untrust IP ''"Example 
>> 172.20.2.3/28"'':')
> 
> This is a representation of an IP address along with the mask length for the
> prefix:
> 
>  172.20.2.3/28 
> 
> That is not, strictly speaking an IP, because there is ancillary 
> information included.  This corresponds to:
> 
>  172.20.2.3 IP address
>  172.20.2.0/28  prefix
> 
> The form you are showing is found on some systems, for example in 
> the output from `ip address show` on Linux systems, but it is a 
> commonly understood form.  Look further at the library that I 
> recommended last week, and I think you will find a solution.
> 
>> while not ipaddress.ip_network untrust_ip_address:
>>  untrust_ip_address = raw_input('\nEnter the  untrust IP ''"Example 
>> 172.20.2.3/28"'':')
> 
> You might try using the ipaddress library in the following way:
> 
 i = ipaddress.ip_interface(u'172.20.2.3/28')
 i.ip
>  IPv4Address(u'172.20.2.3')
 i.network
>  IPv4Network(u'172.20.2.0/28')
 i.with_prefixlen
>  u'172.20.2.3/28'
> 
> Good luck,
> 
> -Martin
> 
> -- 
> Martin A. Brown
> http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor