Professional Documents
Culture Documents
Sixth Class Hands On - Jupyter Notebook
Sixth Class Hands On - Jupyter Notebook
In [1]:
1 #If you want to create a variable without assigning to it a value yet, you can just use
2
3 Niggas = ''
In [2]:
1 Niggas = 'hustlers'
2
3 Niggas
Out[2]:
'hustlers'
In [15]:
james
jecinta
1000
francisca
In [10]:
1 var
Out[10]:
'francisca'
In [20]:
1 #To exclude integers when looping through a list whenever you want to check conditions
2
3 newList = ['james', 'jecinta', 'friday', 1000, 'francisca']
4 resultList =[]
5 for var in newList:
6 if type(var) == int:
7 pass
8 else:
9 if 'e' and 'a' in var:
10 resultList.append(var)
11 print(var)
james
jecinta
friday
francisca
In [13]:
1 #Building a calculator
2
3
4 #Operator list
5 funcList = ['a', 's', 'd', 'x', '%' ]
6
7
8 #Compute Functions
9 def addFunc (var1, var2):
10 result = var1 + var2
11 return result
12
13 def subFunc (var1, var2):
14 result = var1 - var2
15 return result
16
17 def multFunc (var1, var2):
18 result = var1 * var2
19 return result
20
21 def divFunc (var1, var2):
22 result = var1 / var2
23 return result
24
25 def percFunc (var1, var2):
26 result = (var1 /100) * var2
27 return result
28
29 #Get user Input
30 var1 =input('enter value here')
31 var2 =input('enter second value here')
32 operator = input('select your operation from: a(add), s(subtract), d(division), x(multi
33
34 #Preprocess user input
35 if int(var1) or float(var1):
36 var1 = int(var1)
37 else:
38 ('please input only numbers')
39
40 if int(var2) or float(var2):
41 var2 = int(var2)
42 else:
43 ('please input only numbers')
44
45
46 #check to be certain that the user specifies the right operation letter
47
48 if operator in funcList:
49 operator = operator
50 else:
51 print('you have not specified a correct operation')
52
53 opIdx = funcList.index(operator)
54 operation = funcList[opIdx]
55
56 #Process calculation and output results
57
58 if operator == 'a':
59 result = addFunc (var1, var2)
localhost:8888/notebooks/Desktop/Leraning Data Analysis/One Campus Academy/Workspace/Sixth Class Hands On.ipynb 2/4
9/1/22, 8:30 AM Sixth Class Hands On - Jupyter Notebook
In [16]:
25,78,92,6,38
239
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: