Note that there are some explanatory texts on larger screens.

plurals
  1. POList comprehension/list creating loop in python 3.x
    primarykey
    data
    text
    <p>I've been trying to make a loop or list comprension thingy that does the following:</p> <p>prints <code>"Please give me the number of bread sold at ", self.bakeryname[k], ":"</code> then prompts the user for the number of break sold at the given bakery, and stores it in a list</p> <pre><code>"Please give me the number of [breadtype] sold at:" "The hungry baron": [here you enter a number] "The flying bulgarian": [here you enter another number] </code></pre> <p>It's to be stored in a list of integers that starts at the first prompted value and ends at the last -||-.</p> <p>The number of bakeries is potentially infinite, there's only 3 different types of bread.</p> <p>I've dug myself into the hole that is this function:</p> <pre><code>def soldbread(self): amount = ((len(self.bakeryname))*3) k = 0 j = 0 h = 0 i = 0 while j &lt; (len(self.breadtype)): print("Please give me the number of",self.breadtype[k], "sold at:") while i &lt; amount: self.breadsold.append(i) self.breadsold[i] = int(input(self.bakeryname[h])) j += 1 h += 1 i += 1 if k == 3: break else: while j &gt;= len(self.bakeryname): k += 1 print("Please give me the number of",self.breadtype[k], "soldat:") j = 0 h = 0 </code></pre> <p>The function will go to the 15'th type of bread (there's 5 bakeries in self.bakeryname >at the moment&lt;, so atleast that number is accurate) then it will complain about "IndexError: list index out of range". I've tried a bunch of "if"'s and "breaks"'s but I can't pull it off.</p> <p>The names etc. in the code is translated from my native language, so eventual typos are likely to not be in the code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload