You are on page 1of 4

9/1/22, 8:30 AM 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]:

1 newList = ['james', 'jecinta', 'friday', 1000, 'francisca']


2 resultList =[]
3 for var in newList:
4 #print(var)
5 if var != 'friday':
6 resultList.append(var)
7 print(var)

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

localhost:8888/notebooks/Desktop/Leraning Data Analysis/One Campus Academy/Workspace/Sixth Class Hands On.ipynb 1/4


9/1/22, 8:30 AM Sixth Class Hands On - Jupyter Notebook

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

60 print(f'the result of your calculation is: {result}')


61 elif operator == 's':
62 result = minFunc (var1, var2)
63 print(f'the result of your calculation is: {result}')
64 elif operator == 'x':
65 result = multFunc (var1, var2)
66 print(f'the result of your calculation is: {result}')
67 elif operator == 'd':
68 result = divFunc (var1, var2)
69 print(f'the result of your calculation is: {result}')
70 elif operator == '%':
71 result = percFunc (var1, var2)
72 print(f'the result of your calculation is: {result}')
73
74
75

enter value here45

enter second value here100

select your operation from: a(add), s(subtract), d(division), x(multiply), %


(percentage)%

the result of your calculation is: 45.0

In [16]:

1 #fOR ADDING MORE THAN ONE INPUT TO CALCULATE


2
3 vals = input('enter values here, separate your values with a comma:')
4 print(vals)
5 valList = vals.split(',')
6
7 valAdd = 0
8 for val in valList:
9 if int(val) or float(val):
10 valAdd += int(val)
11
12 print(valAdd)
13

enter values here, separate your values with a comma:25,78,92,6,38

25,78,92,6,38

239

In [ ]:

In [ ]:

In [ ]:

In [ ]:

localhost:8888/notebooks/Desktop/Leraning Data Analysis/One Campus Academy/Workspace/Sixth Class Hands On.ipynb 3/4


9/1/22, 8:30 AM Sixth Class Hands On - Jupyter Notebook

In [ ]:

In [ ]:

localhost:8888/notebooks/Desktop/Leraning Data Analysis/One Campus Academy/Workspace/Sixth Class Hands On.ipynb 4/4

You might also like