Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Showing error
#3
price_list = {
    'internet_connection': {
        'name': 'Internet Connection',
        'price': 200,
        'regularity': 'monthly'
    },
    'phone_line': {
        'name': 'Phone Line',
        'price': 150,
        'regularity': 'monthly'
    },
    'motorola_G99': {
        'name': 'Motorola G99',
        'price': 800,
        'regularity': 'once'
    },
    'iphone_99': {
        'name': 'iPhone 99',
        'price': 6000,
        'regularity': 'once'
    },
    'samsung_galaxy_99': {
        'name': 'Samsung Galaxy 99',
        'price': 1000,
        'regularity': 'once'
    },
    'sony_xperia_99': {
        'name': 'Sony Xperia 99',
        'price': 900,
        'regularity': 'once'
    },
    'huawei_99': {
        'name': 'Huawei 99',
        'price': 900,
        'regularity': 'once'
    },
}


class Purchase():
    internet_connection = False
    phone_lines = 0
    cell_phones = []
    price = 0

    def get_price(self, service_name):
        service = price_list.get(service_name)
        return service['price']

    def get_name(self, service_name):
        service = price_list.get(service_name)
        return service['name']

    def in_ex_internet_conn(self):
        
        if  not self.internet_connection:
            self.price += self.get_price('internet_connection')
            self.internet_connection = True
        else:
            self.price -= self.get_price('internet_connection')
            self.internet_connection = False

        print( "Price: \t {}\n".format(self.price))
        return self.price
        

    def increment_phn_line(self):
        if (self.phone_lines < 8):
            self.phone_lines += 1
            self.price += self.get_price('phone_line')
        else:
            print ("Can not take more than 8 lines!!!!!")

        print( "Price: \t {}\n".format(self.price))
        return self.price

    def decrementing_phn_line(self):
        if (self.phone_lines > 0):
            self.phone_lines -= 1
            self.price -= self.get_price('phone_line')
        else:
            print ("No more decrement!!!!!")

        print( "Price: \t {}\n".format(self.price))
        return self.price        

    def select_cell_phn(self, phn_model):
        #if phn_model not in self.cell_phones:
        self.cell_phones.append(phn_model)
        self.price += self.get_price(phn_model)
        print( "Price: \t {}\n".format(self.price))
        return self.price

    def unselect_cell_phn(self, phn_model):
        if phn_model in self.cell_phones:
            self.cell_phones.remove(phn_model)
            self.price -= self.get_price(phn_model)
        else:
            print ("There is no phone to remove")

        print( "Price: \t {}\n".format(self.price))
        return self.price

    def buying(self):
        while self.price> 0:
            try:
                print ("Items you are buying:\n")
                if self.internet_connection:
                    print ("{} \t {}\n".format(self.get_name('internet_connection'), self.get_price('internet_connection')))   
                if self.phone_lines > 0:
                    print ("{}x{} \t {}\n".format(self.phone_lines, self.get_name('phone_line'),self.get_price('phone_line')*self.phone_lines))
                if len(self.cell_phones) > 0:
                    for cell_phone in self.cell_phones:
                        print ("1x{} \t {}\n".format(self.get_name(cell_phone),self.get_price(cell_phone))
                print("Total price \t: {} DKK\n".format(self.price))  
            except ValueError:
                print("Oops!!!!! You did not select anything")

    

   



pur1 = Purchase()

pur1.buying()

pur1.in_ex_internet_conn()
pur1.increment_phn_line()
pur1.increment_phn_line()
pur1.increment_phn_line()
pur1.increment_phn_line()
pur1.increment_phn_line()
pur1.increment_phn_line()
pur1.increment_phn_line()
pur1.increment_phn_line()
pur1.increment_phn_line()

pur1.decrementing_phn_line()
pur1.decrementing_phn_line()
pur1.decrementing_phn_line()
pur1.decrementing_phn_line()
pur1.decrementing_phn_line()
pur1.decrementing_phn_line()
pur1.decrementing_phn_line()
pur1.decrementing_phn_line()
pur1.decrementing_phn_line()
pur1.decrementing_phn_line()

pur1.select_cell_phn("motorola_G99")
pur1.buying()
Reply


Messages In This Thread
Showing error - by Sakeeb - Mar-31-2020, 11:57 AM
RE: Showing error - by buran - Mar-31-2020, 12:01 PM
RE: Showing error - by Sakeeb - Mar-31-2020, 12:53 PM
RE: Showing error - by buran - Mar-31-2020, 01:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  xlwings UDF showing name error pwt 9 5,148 May-29-2020, 07:09 AM
Last Post: pwt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020