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")
Showing error
Showing error
|
Mar-31-2020, 12:01 PM
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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs 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()
Mar-31-2020, 01:03 PM
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
xlwings UDF showing name error | pwt | 9 | 7,262 |
May-29-2020, 07:09 AM Last Post: pwt |
Users browsing this thread: 1 Guest(s)