# kargupy / euc-cli / euc-cli_0.7.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``` ```#============================ # Energy Usage Calculator # Program Code # Version: 0.7 | Functional #============================ import os title = "Energy Usage Calculator" ver = 0.7 L1 = "==================================================" L2 = "--------------------------------------------------" def BUG(n): return "".format(n) def euc(): global name, VA, KVA, NEA print L1 print title, ver print L2 name = raw_input("Name : ") VA = input("Household Power (VA) : ") KVA = VA / float(1000) def askNEA(): global NEA, dataW, dataH NEA = input("Number of electronic appliances : ") if NEA > 1000: print "[Impossible!]" askNEA() dataW = []; dataH = [] print "[Input your data based on maximum/day]" for n in range(1,NEA+1): def askEA(): global W,H ansW = "EA {}\t| Power (Watt) : ".format(n) ansH = "\t| Usage (Hour) : " # ask W W = input(ansW) if W > 100000 or W <= 0: print "[Impossible power!]" askEA() # ask H H = input(ansH) if H > 24 or H <= 0: print "[Impossible usage in a day!]" askEA() else: dataW.append(W) dataH.append(H) askEA() askNEA() countDaily(dataW,dataH) def countDaily(dataW,dataH): global dataWHn, dataWH, HW, DWH, DKWH HW = 0; DWH = 0; DKWH = 0 # append dataW & dataH to dataWHn dataWHn = [] for x in range(len(dataW)): W = dataW[x] H = dataH[x] dataWHn.append([W,H]) # count HW for W in dataW: HW += W # append W * H to dataWH dataWH = [] for W,H in dataWHn: WH = W * H dataWH.append(WH) # check W <= VA if HW <= VA: for WH in dataWH: DWH += WH DKWH = DWH / float(1000) countMonthly(DKWH) else: print "[Usage exceeded!]" reportFail() def countMonthly(DKWH): global MKWH, BC, MPKWH, TAX, MB1, MB2 MKWH = DKWH * 30 if VA <= 450: BC = KVA * 5000 MPKWH = 360 elif VA <= 900: BC = KVA * 10000 MPKWH = 360 elif VA <= 1300: BC = KVA * 15000 MPKWH = 360 elif VA <= 2200: BC = KVA * 25000 MPKWH = 405 elif VA <= 3500: BC = KVA * 27000 MPKWH = 420 elif VA <= 6600 or VA <= 200000: BC = KVA * 30500 MPKWH = 430 else: BC = 0; MPKWH = 0 if VA <= 1300: TAX = 0.03 elif VA <= 5500: TAX = 0.05 elif VA <= 200000: TAX = 0.06 else: TAX = 0 MB1 = (MKWH * MPKWH) + BC MT = MB1*TAX MB2 = MB1 + MT report() def report(): print L2 print "Your Name\t\t= {}".format(name) print "Household Power\t\t= {} VA".format(VA) print L2 print "[Result based on maximum estimation]" for n in range(1,NEA+1): print "Electronic Appliance {}\t= {} W * {} H = {} Wh".format( n,dataW[n-1],dataH[n-1],dataWH[n-1]) print "Hourly Watt\t\t= {} Wh".format(HW) print "Daily Watt Hour\t= {} Wh".format(DWH) print "Daily kWh\t\t= {} kWh".format(DKWH) print "Monthly kWh\t\t= {} kWh".format(MKWH) print "Burden Cost/kW\t\t= Rp {}".format(BC) print "Monthly Price/kWh\t= Rp {}".format(MPKWH) print "Monthly Bills w/o Tax\t= Rp {}".format(MB1) print "Monthly Tax\t\t= {} % = Rp {}".format((TAX*100),(MB1*TAX)) print L2 print "Monthly Bills\t\t= Rp {}".format(MB2) print L1 again() def reportFail(): print L2 print "Name\t\t= {}".format(name) print "Household Power\t\t= {} VA".format(VA) print L2 print "[Result based on maximum estimation]" for n in range(1,NEA+1): print "Electronic Appliance {}\t= {} W * {} H = {} Wh".format( n,dataW[n-1],dataH[n-1],dataWH[n-1]) print "Hourly Watt\t\t= {} W".format(HW) print """ Your usage is over from maximum possible capability in an hour/day. You need to calculate again or disable some appliances. """ print L1 again() def again(): a = raw_input("Calculate again [Y/N]? ") if a == "Y" or a == "y": clear() run() elif a == "N" or a == "n": clear() exit() else: print "[Wrong choice. Please answer Y or N]" again() def clear(): os.system(['clear','cls'][os.name == 'nt']) def run(): try: euc() except: print "[Exited!]" clear() exit() run() # euc() ```