From c452eb038335e13db0669c7551c6b606b9a74261 Mon Sep 17 00:00:00 2001 From: tsegas Date: Thu, 10 Mar 2016 14:09:53 -0800 Subject: [PATCH 1/2] add trapz rule project --- students/tsegas/session06/trapz_rule.py | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 students/tsegas/session06/trapz_rule.py diff --git a/students/tsegas/session06/trapz_rule.py b/students/tsegas/session06/trapz_rule.py new file mode 100755 index 0000000..a9c244a --- /dev/null +++ b/students/tsegas/session06/trapz_rule.py @@ -0,0 +1,40 @@ +# +# Trapazoid rule project: uses f(x) = x**2 as a function to be passed to the trapz function + +import random +import string +import sys + +# The function that will be passed to trapz +def f(x): + # f(x) = x**2 is used as an equation + y = x ** 2 + return y + +def trapz(func, start, end): + #Compute the area under the curve defined by + #y = fun(x), for x between a and b + + N = 100 #max + x = 0 + first = 0 + for x in range(0, N): + if first ==0: + first = 1 + summ = f(x) + #print('summ at 0....',summ) + #print('x at 0....',x) + else: + #print('x at N0....',x) + summ = summ + (2*f(x)) + #print('x at N0....',x) + #f = f + x + #print('summ...',summ) + area = (((end-start))/2*N)*summ + + return area + +area = trapz(f, 5, 10) +print("The area under the curve from {} to {} is {}: ".format(5,10,area),'\n') + + From d9d94110a3a3eab3911c4db7f74ab3cbb56bd61e Mon Sep 17 00:00:00 2001 From: tsegas Date: Thu, 10 Mar 2016 14:15:31 -0800 Subject: [PATCH 2/2] update dict_lab project --- students/tsegas/session04/dict_lab.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/students/tsegas/session04/dict_lab.py b/students/tsegas/session04/dict_lab.py index ca460d9..20814ac 100755 --- a/students/tsegas/session04/dict_lab.py +++ b/students/tsegas/session04/dict_lab.py @@ -8,5 +8,14 @@ my['fruit'] = 'mango' print("print the dict",my) +print("print the dictionary keys",my.keys()) +print("print the dictionary values",my.values()) + +a = "chocolate" in my +print("is chocolate a key in the dictionary?",a) + +b = "fruit" in my +print("is Mango a value in the dictionary?",b) + cpy_my = my.copy() print("print the dict",cpy_my) \ No newline at end of file