Showing error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Showing error (/thread-25461.html) |
Showing error - Sakeeb - Mar-31-2020 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") RE: Showing error - buran - Mar-31-2020 what error do you get? Post the full traceback in error tags. Obviously we are not able to run the code as is (just one class method) RE: Showing error - Sakeeb - Mar-31-2020 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() RE: Showing error - buran - Mar-31-2020 You have missing closing bracket on line #114. Please, when have a traceback, post full traceback in error tags: Also post code in python tagsSee BBcode help for more info. |