From bf46b4cb15b1383c8627ff5ae34368867d2660d3 Mon Sep 17 00:00:00 2001 From: HakiimJ Date: Mon, 30 Aug 2021 11:39:46 +0800 Subject: [PATCH 1/8] minor ed --- pre-session/basic.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pre-session/basic.py b/pre-session/basic.py index 6d9c49e..ca8d27b 100644 --- a/pre-session/basic.py +++ b/pre-session/basic.py @@ -1,19 +1,19 @@ -number = 6677 # integer +number = 123 # integer -number_decimal = 18.6 #cpp or java double or float +number_decimal = .123 #cpp or java double or float -height = 1.8 +height = 1.73 -name = ' Rohitash Chandra' # string +name = 'Hakiim Jamaluddin' # string print(number) -print(number, ' is number') +print(number, 'is number') print(number_decimal, ' is decimal ') -print(height,' is height ') +print(height,'is height ') print(name) -print(name, ' is my name') +print(name,'is my name') -print(' lets calculate') +print('lets calculate') radius = 12.25 @@ -40,4 +40,5 @@ area_triangle = 0.5 * int(base) * int(height) -print(area_triangle, ' is the area of the triangle') \ No newline at end of file +print(area_triangle, ' is the area of the triangle') + From 8c8202ee6b659b78d9da2d47b3efe72723fdee7e Mon Sep 17 00:00:00 2001 From: HakiimJ Date: Mon, 30 Aug 2021 21:28:12 +0800 Subject: [PATCH 2/8] edit --- pre-session/basic.py | 50 +++++-------------------------- pre-session/tempCodeRunnerFile.py | 46 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 pre-session/tempCodeRunnerFile.py diff --git a/pre-session/basic.py b/pre-session/basic.py index ca8d27b..15ecbb8 100644 --- a/pre-session/basic.py +++ b/pre-session/basic.py @@ -1,44 +1,10 @@ -number = 123 # integer - -number_decimal = .123 #cpp or java double or float - -height = 1.73 - -name = 'Hakiim Jamaluddin' # string - -print(number) -print(number, 'is number') -print(number_decimal, ' is decimal ') -print(height,'is height ') -print(name) -print(name,'is my name') - -print('lets calculate') - - -radius = 12.25 -pi = 3.14 - -area_circle = pi * radius * radius - -print(area_circle, ' is area of the circle') - - -# triangle (ask the user for input) - - -print('Good day mate. This program claculates area of triangle') - -print('please enter the base: ') -base = input() - -print('please enter the height: ') +print('Your name?') +name = input() +print('Your height?') height = input() +print('Your weight?') +weight = input() -print(base, height, ' are the base and height, respectively') - -area_triangle = 0.5 * int(base) * int(height) - - -print(area_triangle, ' is the area of the triangle') - +print('Hi ',name,'.') +print('Your height is ',height,' and weight is ',weight,'.') +print('You are MF fat!') \ No newline at end of file diff --git a/pre-session/tempCodeRunnerFile.py b/pre-session/tempCodeRunnerFile.py new file mode 100644 index 0000000..c0072eb --- /dev/null +++ b/pre-session/tempCodeRunnerFile.py @@ -0,0 +1,46 @@ +number = 123 # integer + +number_decimal = .123 #cpp or java double or float + +height = 1.73 + +name = 'Hakiim Jamaluddin' # string + +print(number) +print(number, 'is number') +print(number_decimal, ' is decimal ') +print(height,'is height ') +print(name) +print(name,'is my name') + +print('lets calculate') + + +radius = 12.25 +pi = 3.14 + +area_circle = pi * radius * radius + +print(area_circle, ' is area of the circle') + + +# triangle (ask the user for input) + + +print('Good day mate. This program claculates area of triangle') + +print('please enter the base: ') +base = input() + +print('please enter the height: ') +height = input() + +print(base, height, ' are the base and height, respectively') + +area_triangle = 0.5 * int(base) * int(height) + + +print(area_triangle, ' is the area of the triangle') + + + From 6a47d05d7ee9d9cd97afee895cbcbfbbfdf53327 Mon Sep 17 00:00:00 2001 From: HakiimJ Date: Mon, 30 Aug 2021 21:48:15 +0800 Subject: [PATCH 3/8] edit --- pre-session/basic.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pre-session/basic.py b/pre-session/basic.py index 15ecbb8..d9d5e66 100644 --- a/pre-session/basic.py +++ b/pre-session/basic.py @@ -1,10 +1,24 @@ print('Your name?') name = input() -print('Your height?') +print('Your height (m)?') height = input() -print('Your weight?') +print('Your weight (kg)?') weight = input() +def bmi (h,w): + bmi = w/(h*h) + if bmi < 18.5: + bmi_status = 'underweight' + elif bmi >= 18.5 and bmi < 25: + bmi_status = 'normal' + elif bmi >= 25 and bmi < 30: + bmi_status = 'overweight' + elif bmi >= 30: + bmi_status = 'obese' + return(bmi, bmi_status) + +BMI, BMI_status = bmi(float(height), float(weight)) + print('Hi ',name,'.') print('Your height is ',height,' and weight is ',weight,'.') -print('You are MF fat!') \ No newline at end of file +print('Your BMI is ', BMI, ' and you are ', BMI_status,'.') \ No newline at end of file From 5cda1831f99349ae38e994e31ee16c3536d42f01 Mon Sep 17 00:00:00 2001 From: HakiimJ Date: Mon, 30 Aug 2021 21:52:30 +0800 Subject: [PATCH 4/8] edit again --- pre-session/basic.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pre-session/basic.py b/pre-session/basic.py index d9d5e66..ada9c74 100644 --- a/pre-session/basic.py +++ b/pre-session/basic.py @@ -21,4 +21,11 @@ def bmi (h,w): print('Hi ',name,'.') print('Your height is ',height,' and weight is ',weight,'.') -print('Your BMI is ', BMI, ' and you are ', BMI_status,'.') \ No newline at end of file +print('Your BMI is ', BMI, ' and you are ', BMI_status,'.') + + +# comments +'''commenting +Oh dear +this is so long +''' \ No newline at end of file From 0cbaaa8dc506441cb2611fe6e3511114ceb7c5df Mon Sep 17 00:00:00 2001 From: HakiimJ Date: Mon, 30 Aug 2021 22:12:46 +0800 Subject: [PATCH 5/8] edit --- pre-session/basic_calculations.py | 35 +++++-------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/pre-session/basic_calculations.py b/pre-session/basic_calculations.py index 5b7f421..68b86df 100644 --- a/pre-session/basic_calculations.py +++ b/pre-session/basic_calculations.py @@ -6,56 +6,31 @@ def area_circle(radius): - area = pi * radius * radius - - #print(area, ' is print statement in the func') - return area def volume_sphere(radius): - # you can try - return 0 - - def volume_cylinder(radius, height): - area = area_circle (radius) - volume = area * height - return volume, area - - - - #---------------------------------- # now we call the above functions #ask the user (exercise) -radius = 5555 +print('Radius?') +radius = float(input()) area = area_circle (radius) print(area, 'is the area in square meters') - -height = 44 +print('Height?') +height = float(input()) vol, ar = volume_cylinder (radius, height) - print(vol, 'is the volume in cubic meters') - - -print(area, 'is the area of the top of the cylinder') - - - -#warm up exercise. Try implementing different functions for the rest -# of the examples here: https://byjus.com/volume-formulas/ - -# try to ask the user to input information (such as base, height, radius etc) - +print(area, 'is the area of the top of the cylinder') \ No newline at end of file From 969f989772d56b78f46141e52794a01d79b0a275 Mon Sep 17 00:00:00 2001 From: HakiimJ Date: Tue, 31 Aug 2021 23:57:40 +0800 Subject: [PATCH 6/8] edit --- session1/loops/give_change.py | 8 ++++++++ session1/loops/nested_loops.py | 31 +++++++++++++++++++++++++++++++ session1/numpy/numpy_loadsave.py | 28 +++++++++++----------------- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/session1/loops/give_change.py b/session1/loops/give_change.py index ab93ba1..ed07278 100644 --- a/session1/loops/give_change.py +++ b/session1/loops/give_change.py @@ -109,3 +109,11 @@ # Can you use a stack of coins, eg 10 coins of each denomination each ? # Can you simulate an old cashier machine at the supermarket? + + +'''SUMMARY +# rounding +int(1.5) = 1 +# remainder +25%20 = 5 +''' \ No newline at end of file diff --git a/session1/loops/nested_loops.py b/session1/loops/nested_loops.py index f7f43ed..b4c9a4a 100644 --- a/session1/loops/nested_loops.py +++ b/session1/loops/nested_loops.py @@ -100,3 +100,34 @@ def main(): if __name__ == '__main__': main() + + + +#### SUMMARY #### +# python coding convention +''' +import a +import b +import c + +def function1(x,w): + p = x*w + return(p) + +def main(): + write like the main in R + print('p is ',p) + +if__name__=='__main__': + main() + +# extra (indexing) +three_dimen[2,2:4,:] +vector[i] +len(vector) +# pandas data.frame +nrow() = len(dt.index) +ncol() = len(dt.columns) +''' + + diff --git a/session1/numpy/numpy_loadsave.py b/session1/numpy/numpy_loadsave.py index aaf4f9f..af03d16 100644 --- a/session1/numpy/numpy_loadsave.py +++ b/session1/numpy/numpy_loadsave.py @@ -73,19 +73,6 @@ def load_file(filename): plt.savefig('design_magic_traspose.png') plt.clf() # make sure you have this in all plots - - - - - - - - - - - - - def main(): @@ -98,10 +85,17 @@ def main(): plot_examples() load_file(filename) - - - - if __name__ == '__main__': main() + + +'''SUMMARY + x = [1, 2, 3, 4] +#numpy_x = +plt.plot(x) +plt.ylabel('some numbers') +#plt.show() +plt.savefig('x.png') + +''' \ No newline at end of file From 22cdf00b6007532ad1e88101b357c384a6215da8 Mon Sep 17 00:00:00 2001 From: HakiimJ Date: Tue, 31 Aug 2021 23:57:53 +0800 Subject: [PATCH 7/8] edit --- session1/loops/basic_loops.py | 16 ++++++++++-- session1/loops/nestedloops_draw.py | 3 ++- session1/numpy/numpy_advanced.py | 32 +++++++++++++++++++++++ session1/recursion/factorial_recursion.py | 14 +++++++--- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/session1/loops/basic_loops.py b/session1/loops/basic_loops.py index 4f24724..6f8bf50 100644 --- a/session1/loops/basic_loops.py +++ b/session1/loops/basic_loops.py @@ -6,7 +6,7 @@ # while loop -print(' basic while loop ') +'''print(' basic while loop ') i = 1 while i < 6: @@ -60,12 +60,15 @@ for x in fruits: if x == "banana": break - print(x) + print(x)''' # Powers of 2 (for no obvious reason) +from _typeshed import StrPath + + power = 1 for y in range(0 ,21, 4): print("2 to the", y, "is", power) @@ -103,4 +106,13 @@ print(y,end=' ') print() +#### SUMMARY #### + +'''for i in range(start, end_plus_one, increment_if_not_one): + p = x*w + print('p is ',p)''' +'''i = start +while i < end_plus_one: + p = x*w + print('p is ',p)''' \ No newline at end of file diff --git a/session1/loops/nestedloops_draw.py b/session1/loops/nestedloops_draw.py index 4b5329e..02c0d7c 100644 --- a/session1/loops/nestedloops_draw.py +++ b/session1/loops/nestedloops_draw.py @@ -8,7 +8,7 @@ for i in range(side): print('*', end = ' ') print() - +''' i = 0 print("Square Star Pattern - Nested While Loops") @@ -35,3 +35,4 @@ print('*' if i in [j, m-1] or j == 0 else ' ', end='') print() +''' \ No newline at end of file diff --git a/session1/numpy/numpy_advanced.py b/session1/numpy/numpy_advanced.py index 779a07a..da1c097 100644 --- a/session1/numpy/numpy_advanced.py +++ b/session1/numpy/numpy_advanced.py @@ -86,3 +86,35 @@ def main(): if __name__ == '__main__': main() + +'''SUMMARY +#vector +a = np.array([1,2,3]) +b = np.array([1,2,3]) +vertical_stack = np.vstack((a,b)) #cbind() +horizontal_stack = np.hstack((a,b)) #rbind + +#matrix +a = np.array([1,2,3],[1,2,3]) +b = np.array([1,2,3],[1,2,3]) + +ab = np.concatenate((a,b), axis = 0) becomes ([1,2,3], + [1,2,3], + [1,2,3], + [1,2,3]) + +ab = np.concatenate((a,b), axis = None) becomes a vector + +# reshape +object.reshape((nrow,ncol)) + +# matrix change to vector +object.flatten() + +# indexing +object.shape[0] = nrow() +object.shape[1] = ncol() + +# transpose +np.transpose +''' \ No newline at end of file diff --git a/session1/recursion/factorial_recursion.py b/session1/recursion/factorial_recursion.py index 20ba116..493f0e5 100644 --- a/session1/recursion/factorial_recursion.py +++ b/session1/recursion/factorial_recursion.py @@ -16,10 +16,7 @@ def factorial(x): fact = x * factorial(x-1) #print(x, fact, ' is fact') return fact - - - - + def factorial_iteration(num): fac = 1 @@ -61,4 +58,13 @@ def factorial_iteration(num): print('ITERATION took time: ', end - start) +'''SUMMARY +to compute time taken +import time +start = time.time() +OPERATIONS +end = time.time() +time_difference = end - start +# Not sure factorial and recursion are useful in my works +''' From 033c95b14319dd1b46dd211726d36d0f43a84283 Mon Sep 17 00:00:00 2001 From: HakiimJ Date: Wed, 1 Sep 2021 09:51:45 +0800 Subject: [PATCH 8/8] edit --- session3/numerical_integration/numerical_int.py | 1 - 1 file changed, 1 deletion(-) diff --git a/session3/numerical_integration/numerical_int.py b/session3/numerical_integration/numerical_int.py index 314f79b..f29483a 100644 --- a/session3/numerical_integration/numerical_int.py +++ b/session3/numerical_integration/numerical_int.py @@ -9,7 +9,6 @@ def func(x): return x ** 4 * (1 - x) ** 4 / (1 + x ** 2) #define a function to do integration of f(x) btw. 0 and 1: - def trap(func, n): h = 1 / float(n) intgr = 0.5 * h * (func(0) + func(1))