List comprehension/list creating loop in python 3.x -
i've been trying make loop or list comprension thingy following:
prints "please give me number of bread sold @ ", self.bakeryname[k], ":"
prompts user number of break sold @ given bakery, , stores in list
"please give me number of [breadtype] sold at:" "the hungry baron": [here enter number] "the flying bulgarian": [here enter number]
it's stored in list of integers starts @ first prompted value , ends @ last -||-.
the number of bakeries potentially infinite, there's 3 different types of bread.
i've dug myself hole function:
def soldbread(self): amount = ((len(self.bakeryname))*3) k = 0 j = 0 h = 0 = 0 while j < (len(self.breadtype)): print("please give me number of",self.breadtype[k], "sold at:") while < amount: self.breadsold.append(i) self.breadsold[i] = int(input(self.bakeryname[h])) j += 1 h += 1 += 1 if k == 3: break else: while j >= len(self.bakeryname): k += 1 print("please give me number of",self.breadtype[k], "soldat:") j = 0 h = 0
the function go 15'th type of bread (there's 5 bakeries in self.bakeryname >at moment<, atleast number accurate) complain "indexerror: list index out of range". i've tried bunch of "if"'s , "breaks"'s can't pull off.
the names etc. in code translated native language, eventual typos not in code.
# data bakeries = ['a','b','c'] breadtypes = ['flat','rye','white'] # output data results = {} bakery in bakeries: # line each bakery print('how many of each type of bread %s: ' % bakery) # python3 dict comprehension , generator results[bakery] = { breadtype: breadtypevalue breadtype, breadtypevalue in ((bt, input('%s: ' % bt)) bt in breadtypes) } # wanna print that? bakery in results: print('here different types of breads %s:' % bakery) print(', '.join(['%s: %s' % (breadtype, number) breadtype, number in results[bakery].items()]))
Comments
Post a Comment