Coding Python - Menghitung Belanjaan
class Belanjaan():
#atribut
Beras = 0
Daging = 0
Sayuran = 0
Kentang = 0
Total_Harga = 0
Total_Berat = 0
#konstanta
HBeras = 7000
HDaging = 12000
HSayuran = 5000
HKentang = 4500
#constructur
def _init_ (self, Beras, Daging, Sayuran, Kentang, Total_Harga, Total_Berat):
self.Beras = Beras
self.Daging = Daging
self.Saturan = Sayuran
self.Kentang = Kentang
#method
def hitungHarga(self):
Total_Harga = ((self.Beras * self.HBeras)+(self.Daging * self.HDaging)+(self.Sayuran * self.HSayuran)+(self.Kentang * self.HKentang))
return Total_Harga
#method
def hitungBerat(self):
Total_Berat = (self.Beras + self.Daging + self.Kentang)
return Total_Berat
def main():
#instance
b = Belanjaan()
#input
b.Beras = int(raw_input(" Jumlah Beras : "))
b.Daging = float(raw_input(" Jumlah Daging : "))
b.Sayuran = int(raw_input(" Jumlah Sayuran : "))
b.Kentang = float(raw_input(" Jumlah Kentang : "))
#output
print "Penghitungan Total Belanja"
print " Author : Frika Da Cintia"
print "===================================="
print "Jumlah Beras (kg): ",b.Beras
print "Jumlah Daging (kg): ",b.Daging
print "Jumlah Sayuran (kg): ",b.Sayuran
print "Jumlah Kentang (kg): ",b.Kentang
print "==================================="
print "Harga Satuan untuk setiap item"
print "Harga Beras : ",b.HBeras
print "Harga Daging : ",b.HDaging
print "Harga Sayuran : ",b.HSayuran
print "Harga Kentang : ",b.HKentang
print "==================================="
print "Total Harga Belanjaan : ",b.hitungHarga()
print "Total Berat Belanjaan : ",b.hitungBerat()
if __name__ == '__main__':
main()
erroe bang
BalasHapus