Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 30 additions & 42 deletions pre-session/basic.py
Original file line number Diff line number Diff line change
@@ -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')
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
'''
35 changes: 5 additions & 30 deletions pre-session/basic_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
46 changes: 46 additions & 0 deletions pre-session/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -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')



16 changes: 14 additions & 2 deletions session1/loops/basic_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# while loop

print(' basic while loop ')
'''print(' basic while loop ')

i = 1
while i < 6:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)'''
8 changes: 8 additions & 0 deletions session1/loops/give_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
31 changes: 31 additions & 0 deletions session1/loops/nested_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
'''


3 changes: 2 additions & 1 deletion session1/loops/nestedloops_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
for i in range(side):
print('*', end = ' ')
print()

'''
i = 0
print("Square Star Pattern - Nested While Loops")

Expand All @@ -35,3 +35,4 @@
print('*' if i in [j, m-1] or j == 0 else ' ', end='')
print()

'''
32 changes: 32 additions & 0 deletions session1/numpy/numpy_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
28 changes: 11 additions & 17 deletions session1/numpy/numpy_loadsave.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand All @@ -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')

'''
14 changes: 10 additions & 4 deletions session1/recursion/factorial_recursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
'''
Loading