<div class="gmail_quote">On Tue, Nov 29, 2011 at 2:31 PM, ADRIAN KELLY <span dir="ltr">&lt;<a href="mailto:kellyadrian@hotmail.com">kellyadrian@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">





<div><div dir="ltr">
i am trying to create a program that will allow users to enter items and their prices; should i be looking at a list, tuple or what?</div></div></blockquote><div><br></div><div>The entering part isn&#39;t as important as how you want to display the data. For instance, here&#39;s a program that allows the user to input an unlimited amount of data (using Python 3.x):</div>

<div><span style="background-color: transparent; "><br></span></div><div><span style="background-color: transparent; ">while input(&quot;Enter q to quit, or an item: &quot;).lower() not in (&#39;q&#39;, &#39;quit&#39;, &#39;goodbye&#39;):</span></div>

<div><span style="background-color: transparent; ">     input(&quot;Enter the price: &quot;)</span></div><div><span style="background-color: transparent; "><br></span></div><div><span style="background-color: transparent; ">Of course it doesn&#39;t store the data, so it&#39;s pretty useless. But it does allow the user to input whatever they want.</span></div>

<div><span style="background-color: transparent; "><br></span></div><div><span style="background-color: transparent; ">If you wanted to simply create a collection of items you could do it as a list with alternating values:</span></div>

<div><span style="background-color: transparent; "><br></span></div><div><span style="background-color: transparent; ">    inventory = [&#39;Crunchy Frog&#39;, 4.13, &#39;Anthrax Ripple&#39;, 12.99999999999, &#39;Spring     Surprise&#39;, 0.00]</span></div>

<div><span style="background-color: transparent; ">    for x in range(0, len(inventory)-1, 2):</span></div><div>          print(inventory[x], inventory[x+1])</div><div><br></div><div>Or as a list of tuples:</div><div>  </div>

<div>    inventory = [(&#39;Norwegian Blue&#39;, 500.00), (&#39;Slug&#39;, 500.00), (&#39;Cage&#39;, 50.00)]</div><div>    for item in inventory:</div><div>        print(item[0], item[1])</div><div><br></div><div>Or a dictionary:</div>

<div><br></div><div>    inventory = {&#39;Spam&#39;:5.00, &#39;Spam on eggs&#39;:10.00, &#39;Spam on Spam&#39;:7.50}</div><div>    for item, price in inventory.items():</div><div>        print(item, price)</div><div><br>
</div>
<div>Or if you wanted to get ridiculous, you could go with a list of classes:</div><div><br></div><div>class Item:</div><div>    def __init__(self, desc=&#39;&#39;, price=0.00):</div><div>        self.desc = desc</div><div>

        self.price = price</div><div>    def __repr__(self):</div><div>        return str(self)</div><div>    def __str__(self):</div><div>        return &quot;{0} - {1}&quot;.format(self.desc, self.price)</div><div><br>
</div>
<div>inventory = [Item(&#39;Lumberjack&#39;, 5.5), Item(&#39;Tree&#39;, 50), Item(&#39;Flapjack&#39;, 0.5)]</div><div>for item in inventory:</div><div>    print(item)</div><div><br></div><div><br></div><div>It just depends on how complex you want to get!</div>

<div>HTH,</div><div>Wayne</div></div>