Icge Python 2-23-2018 0
Icge Python 2-23-2018 0
https://xkcd.com/353/
Why Python?
• Freely available for all types of computers
• Widely used grade schools to universities to industry
• Powerful object-oriented language, with great built-in types
• Easy to create GUIs and interface to internet
https://spectrum.ieee.org/computing/software/the-2017-top-programming-languages
• Fun! Python does a lot of the hard work for you (unlike C++)
My toolkit
for i in range(1,11):
y = i*i
print y
A key strength of Python is the power and
completeness of its built-in data types (objects)
Lists are a general data container:
alist=[1, 9, 3, 7, "a"]
alist.count(3)
alist.pop()
alist.sort()
alist.reverse()
ipd.py
2dmd.py
lights_out.py
Monte Carlo simulations use random numbers
to statistically sample different outcomes
A simple use of Monte Carlo simulation is to
calculate the relative area of a region:
inside=0
trials=1000
for i in range(trials):
x=random.random() Indentation matters!
y=random.random()
if (x*x+y*y)<1.0:
inside+=1
pi=4.*float(inside)/float(trials)
print "N=%d Error=%8.5f "%(trials,pi-math.pi)
Barriers
1.0
Size
0.8
51
0.6
0.4
0.2
0.0
Barriers density
Walker
Simulating percolation is different from random
walks because we have to store the barrier locations
The 2D list object we saw previously is a good data
structure for storing the barrier locations