diff --git a/pre-session/basic.py b/pre-session/basic.py index 6d9c49e..ada9c74 100644 --- a/pre-session/basic.py +++ b/pre-session/basic.py @@ -1,43 +1,31 @@ -number = 6677 # integer - -number_decimal = 18.6 #cpp or java double or float - -height = 1.8 - -name = ' Rohitash Chandra' # 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 (m)?') 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') \ No newline at end of file +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('Your BMI is ', BMI, ' and you are ', BMI_status,'.') + + +# comments +'''commenting +Oh dear +this is so long +''' \ No newline at end of file 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 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') + + + 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/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/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/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 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 +''' 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))