@TristinKeenan/

WindySnowKeyboard

Python

No description

fork
loading
Files
  • main.py
  • awesome_panda.csv
  • data_csv.csv
  • my_first_module.py
  • my_processed_data.csv
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
#a = 5
#b = 3
#c =-3
#d = (a+b) * c**2
#e = 6
#f = float (e)
#print(a+b)
#print(a-b)
#print(a*b)
#print(a/b)
#print(a//b) #floor divide
#print(a/b)
#print(a%b)
#print(a**b)
#print(abs(c))
#print(d)
#print(type(f))
#cc = 3.14
#dd = int(c)
#print(dd)
#aa = 1+1j
#bb = 1-1j
#print(type(aa))
#print(aa*bb)

#Pi = 3.14
#R = 5
#area = Pi * R**2
#print(area)

#s = 'hello coding girls'
#print(type(s))
#print(s)

#p = "python is awesome"
#print(p)

#h = 'Ocean says "Python is awesome"'
#print(h)

#g = 'Ocean says \"Python is flexible\"'
#print(g)

#s = 'hello coding girls'
#print(len(s)) # counting character
#print(s[3]) #index character 3
#print(s[0:5]) #index character 0 to 5
#print(s[-4:]) #index character 4 from the end

#s2 = 'welcome to python'
#s3 = s + s2
#print(s3)
#s4 = s*3
#print(s4)

#s = 'hello coding girls'
#print(dir(s)) #showing other functions available

#s = ' hello coding girls'
#print(help(s.title)) #guideline for what function means
#print(s.strip()) #eliminate the space
#print(s.replace('hello', 'hey')) #replacing words

#s = 'hello'
#name = "ocean"
#greeting = 'welcome to coding girls'
#o = '''{}, {} {}!'''.format(s, name, greeting)
#print(o) #formatting the line 

#n = 123
#s = str(n)
#print(s, type(s)) #converting to string

#x = int('34')
#print(x, type(x)) #converting to int

#y = float('34.235')
#print(y, type(y)) #converting to float

#my_string = 'CodingGirls'
#s1 = my_string[:2]
#s2 = my_string[-2:]
#s3 = s1 + s2
#print(s3)

#name = "Ocean"
#age = 30
#current_year = 2018 
#s = "{} you are going to turn 100 in {}".format(name, 100-age + current_year)
#print(s)
#target=2018+(100-age)
#s1 = "{} you are going to turn 100 in {}".format(name, target)
#print(s1)

#a = True
#b = False
#c = True
#print(a and b and c)
#print((a and b) and c)

#d = 235
#e = 6
#print(d<e)
#print(d==e)
#print(e<=d)

#s1 = 'hello'
#s2 = 'coding'
#print(len(s1)==len(s2))

#l = [[1,2],2,3]
#print(l)
#print(type(l))
#l2 = ['hello', 'coding', 'girls']
#print(l2)
#l3 = ['hello',30,True,l]
#print(l3)
#print(l3[-1][0]) #displaying 1 value as tracing follow list order:[-1] of l3 which is l - then [0] of l
#print(l3[-1][0][0]) #displaying 1 value as tracing follow list order:[-1] of l3 which is l - then [0] of l - then [0] of first bracket [1,2] in l

#x =[ 2, 4, 6]
#y =[ 1, 2]
#print(x*3) #repeat 3 time of x
#print(max(x)) #show max value in x
#print(min(x)) #show min value in x
#print(sum(x)) #show sum of all values in x
#print(max(x)+min(x))

#x = [10,2,5,6]
#x.sort()
#print(x) 

#x1 = [10,2,5,6]
#y = x1.copy()
#print(y)
#result = y.sort(reverse=True)
#print(result)

#x=[10,2,5,4,23]
#x[0]=3 #use to replace item to new value
#print(x)
#x[3]='hello' #use to replace item to new value
#print(x)
#x.append('hungry') #use to add new item to the list
#print(x)
#x.append('lunch time')
#print(x)
#x.pop(2) #use to remove item from the list
#print(x) 
#x.remove(2)
#print(x) #use to remove value=2 in this list

#x = [1,2,3,4,5]
#y = [6,7,8]
#x.extend(y)
#print(x) #add all elements of y to x list
#x.append(y)
#print(x) #add all y as 1 element to x

#x = [1,2,3,4,5,6]
#y = 100
#x.insert (3,y)
#print(x)

#x = '1,2,3,4,5'
#y = x.split(',')
#print(y)
#y = [int(item) for item in x.split(',')]
#print(y) #convert whole list into int

#l = ['1', '2', '3', '4']
#s = '*'.join(l)
#print(s) #to connect whole list with * in between

#t = (1,2,3,4)
#print(t,type(t))

#t = (1,2,3,4)
#l = list(t)
#l.append(100)
#t = tuple(l)
#print(t) #converting between tuple and list

#s1 = set([1,2,3,4,2,1])
#s2 =set([3,4,5,6])
#print(s1,type(s1))
#print(len(s1))
#print(s1.union(s2))

#s3 =set([1,2,3,4,2,1])
#s4 =set([3,4,5,6])
#x=s3.union(s4)
#print(x)
#y=s3.difference(s4)
#print(y)
#z = s3.symmetric_difference(s4)
#print(z)

#s1 =set([1,2,3,4,2,1])
#s2 =set([3,4])
#s = s1.superset(s2)
#print(s)

#d = {'name':['ocean','little'], 'age':30, 'married':True, 'salary':10}
#print(d['name'])
#print(d['age'])
#print(d['married'])
#print(d)

#d = {'name':['ocean','little'], 'age':30, 'married':True, 'salary':10}
#d['name'] = 'Peter'
#d['age']=d['age']+2
#print(d)
#print(d.keys())
#print(d.values())
#print(d.items())
#print(d.get('school', 'Unknown')) #go to dictionary to find "school value", if not find then return result as "Unknown"

#d = {'name':['ocean','little'], 'age':30, 'married':True, 'salary':10, 'school':'NUS'}
#d2 = {'company':'IBM', 'title':'VP'}
#d.update(d2)
#print(d) #adding the value in dictionary d2 to d

#d = {'name':['ocean','little'], 'age':30, 'married':True, 'salary':10, 'school':'NUS'}
#d2 = {'company':'IBM', 'title':'VP', 'salary':50}
#d.update(d2)
#print(d) #updating the common key to new value from d2 to d

#d1 ={'a':100, 'b':200}
#d2 ={'x':300, 'y':400}
#new_dict= d1.copy()
#new_dict.update(d2)
#print(new_dict) #creating new dictionary w/o changing d1 or d2 - make copy of data first from d1 and then apply change to create new_dict

#saving = 100
#while saving<10000:
#    print('work harder')
#    saving = saving + 1333
#    print('current saving is{}'.format(saving))
#print('financial freedom achieved') #while condition loop

#my_friends = ['Lily', 'Lucy','Jessica']
#while len(my_friends)>0:
#    friend = my_friends.pop(0)
#    print('hello {}'.format(friend))
#    print(my_friends)
#if list is not emptry, then say hello

#age = 19
#if age>=21:
#    print('Welcome In')
#else:
#    print('Bye Bye')
#if..else.. condition

#number = 0
#if number>15:
#    print('Positive')
#elif number==0:
#    print('Zero')
#else:
#    print('Negative')
#for multiple condition of if..else..

#year = 2012
#if year%400==0:
#    print('{} is a Leap Year'.format(year))
#elif year%4==0 and year%100 !=0:
#    print('{} is a Leap Year'.format(year))
#else:
#    print('{} is not a Leap Year'.format(year))
#for multiple condition of if smth true (2 layers of conditions for true) then or else smth false then

#limit = 20
#num = 1
#while num<20:
#    if num%2==0:
#     print( num )
#    num = num + 1   
#to list out all even number 

#my_friends = ['lily', 'lucy', 'jean']
#for friend in my_friends:
#    print('Hello {}'.format(friend))
#for case that goes as loop but with sequence or number of times

#d = {'name':'ocean', 'age':30, 'language':'python'}
#for k in d.values():
#    print(k)
#for k,v in d.items():
#    print(k,v)
    
#d = [[1,2,3],[4,5,6],[7,8,9]]
#for a,b,c in d:
#    print(a,b,c)
#for x in d:
#    print(x)

#
#num =[2,7,11,15]
#target = 9
#for x in num:
#    for y in num:
#        if x+y == target:
#            print(num.index(x),num.index(y))

#num =[2,7,11,15]
#target = 9
#result = set()
#for x in num:
#    for y in num:
#        if x+y == target:
#            result=result.union(set([num.index(x),num.index(y)]))
#print(result)

#import random
#pool = list(range(1,50))
#print(pool)
#picked_number = random.choice(pool)
#print(picked_number)

#l = [1,2,3,4,5,6]
#for num in l:
#    try:
#        print(6/num)
#    except:
#        print('skipping{} and goes on'.format(num))
#    finally:
#        print('finishing processing{}'.format(num))
        
    
#l1 = [1,2,0,5,6]
#l1.sort()
#print(l1) #this way you sorting the original line
#p = sort(l1)
#print (p) #this way, you make a new list and it is in sorted order

#Find the sum of all the multiples of 3 or 5 below 1000.
#limit = 1000
#total = 0
#for num in range(1,1000):
#    if num%3==0 or num%5==0:
#        total=total+num
#print(total) 

#def sayHello():
#    '''print greeting message'''
#    print('Hey there')
#    return True
#result = sayHello()
#print(result)

#def sayHello(friend=None):
#    '''print greeting message'''
#    print('Hey there, {}'.format(friend))
#    return True
#result = sayHello('Ocean')
#print(result)

#def addThings (input1,input2):
#    return input1+input2
#result = addThings([1,2], [5,6])
#print(result)

#def addThings(input1, input2=0): #when putting value input2=0, the function understands this is as optional input - if there is no input 2, value is 0
#    print('input1 {}'.format(input1))
#    print('input2 {}'.format(input2))
#    return input1+input2
#addThings(input2=10, input1=5)
#addThings(10,5) #following the sequence as define - input 1 first and input 2
#addThings(10) #if there is no input 2, value is 0

#limit = 1000
#total = 0
#for num in range(1,1000):
#    if num%3==0 or num%5==0:
#        total=total+num
#print(total) 

#def isPalindrome(num):
#    numStr = str(num)
#    numStrReverse = numStr[::-1]
#    if numStr == numStrReverse:
#        return True
#    else:
#        return False
#print (isPalindrome(12213))

#Exercise: Find largest pelindrome number made from the product of two 3-digit numbers
#def isPalindrome(num):
#    numStr = str(num)
#    numStrReverse = numStr[::-1]
#    if numStr == numStrReverse:
#        return True
#    else:
#        return False

#def findLargest():
#    large=0
#    for num1 in range (100,1000):
#        for num2 in range (100,1000):
#            product = num1 * num2
#            if isPalindrome(product):
#                large = max (large,product)
#    print (large)

#findLargest()

#Exercise: Find largest pelindrome number made from the product of two 3-digit numbers - Method 2
#def isPalindrome(num):
#    numStr = str(num)
#    numStrReverse = numStr[::-1]
#    if numStr == numStrReverse:
#        return True
#    else:
#        return False

#def calculateBounds(nDigits)


#def hellokitty():
#    for num1 in'abcd':
#        for num2 in 'abcd':
#            print(num1,num2)
#hellokitty()

#Exercise: Find the nth number of Fabonnaci
#def f(n):
#    '''return the n-th number of fabonnaci'''
#    if n == 1:
#        return 1
#    elif n == 2:
#        return 1
#    else:
#        return f(n-1) + f(n-2)
#def f2(n):
#    for i in range(1,n):
#        print(f(i))
#f2(11)

#Exercise: build calculator that support function of n*(n-1)*(n-2)..1
#def f(n):
#    if n==1:
#        return 1
#    elif n==2:
#        return 2
#    else:
#        return n*f(n-1)
#print(f(5))

#Exercise: how many blocks needed to build triangle knowing 1st level - 1 block, 2nd level - 2 blocks, ..
#def f(n):
#    if n==1:
#        return 1
#    else: 
#        return n + f(n-1)
#print(f(20))

#def isSureWin(n):
#    if n in [1,2,3]:
#        return True
#    elif n==4:
#        return False
#    else:
#        if isSureWin(n-1) and isSureWin(n-2) and isSureWin(n-3):
#            return False
#        else:
#            return True
#def play():
#     for n in range (1,51):
#         print(n, isSureWin(n))
#play()

        
#import datetime
#print(dir(datetime))
#dt = datetime.date.today()
#print(dt)
#tm = datetime.datetime.now()
#print(tm)
#print(dt,type(dt))
#print(dir(dt))
#print(dt.weekday())
#print(dt.isoformat())

#import calendar
#print (calendar.isleap(2204))

#from calendar import isleap
#print(isleap(2004))
#this method presents overwriting problem if there are other import function in the code

#Using module to generalize functions that are used across the platform - example, log-in, sign-up
#import my_first_module as mfm
#def f():
#    for friend in ['lily', 'lucy']:
#        mfm.greeting(friend)
#f()

#Standard way to reading csv file
#import csv
#with open('data_csv.csv') as file:
#    my_reader = csv.reader(file)
#    for row in my_reader:
#        print(row)


#from my_first_module import getInput
#def doWork(filename='data_csv.csv'):
#    input=getInput(filename)
#    print (input, type(input))
#doWork()
#this function change csv input to python input > allow processing of info in python


#Exercise: insert the 3rd data = value of price difference
'''from my_first_module import *
def processedData(rawData):
    processedData =[]
    
    #add the header
    header = rawData[0].copy()
    header.append('diff')
    processedData.append(header)
   
    #indicate NA for first data row's diff - because in 2nd row where data starts, there is no previous year data to calculate price difference 
    firstRow = rawData[1].copy()
    firstRow.append('NA')
    processedData.append(firstRow)
    
    #handle everything from row 2 onwards - indicate formula for row 'diff'
    for i in range(2,len(rawData)):
        currentPrice = float(rawData[i][1])
        previousPrice = float(rawData[i-1][1])
        diff = currentPrice - previousPrice
        processedData.append([rawData[i][0],rawData[i][1], diff])

    return processedData
    
def doWork(filename ='data_csv.csv'):
    input= getInput(filename)
    data= processedData(input)
    print(data)

doWork()'''

#moving the input and output function to my_first_module.py >
#from my_first_module import *

#def doWork(filename ='data_csv.csv'):
#    inputData= getInput(filename)
#    data= processedData(inputData)
#    writeToOutput(data)
#doWork()



#Reading data in csv using Library "pandas" function  - pandas is for processing / manifulating large data (faster and cleaner)
'''import pandas

data = pandas.read_csv('https://datahub.io/core/gold-prices/r/data.csv')
print(data)

data['diff'] = data.price
x = data.price.shift(1)
data['diff'] = data.price-x
print(data)
data.to_csv('awesome_panda.csv')'''

'''import urllib.request

url='http://www.asiaone.com/lottery'
response = urllib.request.urlopen(url)
print(response.read()) #apply to extract all raw data from website'''


import urllib.request
'''BeautifulSoup is a library to process html - bs4 is where library is stored'''
from bs4 import BeautifulSoup

url='http://www.asiaone.com/lottery'
response = urllib.request.urlopen(url)
data = response.read()
soup = BeautifulSoup(data)
for x in soup.findALL('div'{'class':"box-padding col-xs -12"}):
    print(x)