Code of Python untuk Standar Deviasi dan Output Berupa Tabel

Soal menyusul ya..!

Kode Python 3.2 nya sebagai berikut:

from numpy import*

#Def. Judul
def judul():
    print(“Tabel Tingkat Polusi Udara”)
    print(“Oleh:”)
    print(‘NIM:’)
    return

#Def. Print Tabel
def print_tabel():
    judul()
    print(‘code by @Rizkizhou‘)
    print()
    print(‘t’,’t’,’t’,’t’,’Jam’)
    print(‘t’,’———————————————————–‘)
    print(‘Hari’,’|’,’t’,’00’,’t’,’03’,’t’,’06’,’t’,’09’,’t’,’12’,’t’,’15’,’t’,’18’,’t’,’21’)
    for i in range (0,p):
            print(i+1,’|’,’t’,A[i,0],’t’,A[i,1],’t’,A[i,2],’t’,A[i,3],’t’,A[i,4],’t’,A[i,5],’t’,A[i,6],’t’,A[i,7])
    return

#Def. Rata_rata
def rt2(i):
    jumlah=0
    for j in range (0,p):
        jumlah=jumlah+A[j,i]
    xbar=jumlah/p
    return(xbar)

def print_rt2():
    print(‘rt2′,’|’,’t’,’%.1f’%rt2(0),’t’,’%.1f’%rt2(1),’t’,’%.1f’%rt2(2),’t’,’%.1f’%rt2(3),’t’,’%.1f’%rt2(4),’t’,’%.1f’%rt2(5),’t’,’%.1f’%rt2(6),’t’,’%.1f’%rt2(7))
    return

#Def. Standar Deviasi
def SD(i):
    jmlkuadrat=0
    for j in range (0,p):
        jmlkuadrat=jmlkuadrat+(A[j,i]-rt2(i))**2
    SD=(jmlkuadrat/p)**0.5
    return (SD)

def print_SD():
    print(‘SD’,’|’,’t’,’%.1f’%SD(0),’t’,’%.1f’%SD(1),’t’,’%.1f’%SD(2),’t’,’%.1f’%SD(3),’t’,’%.1f’%SD(4),’t’,’%.1f’%SD(5),’t’,’%.1f’%SD(6),’t’,’%.1f’%SD(7))
    return

#Inisiasi Matriks
A= array([[30,31,32,35,40,43,44,38],
              [32,30,34,40,46,49,45,40],
              [38,35,34,37,44,58,51,45],
              [40,42,47,49,48,46,44,42],
              [50,54,56,65,70,80,77,60],
              [65,66,71,78,74,74,69,59],
              [47,43,43,45,52,49,46,42]])
p=len(A)
q=len(A[0])

#Main Program
print_tabel()
print_rt2()
print_SD()