Please help if you can!

Mitya Sirenef msirenef at lightbird.net
Thu Dec 27 01:53:41 CET 2012


On 12/26/2012 07:04 PM, bobflipperdoodle at gmail.com wrote:
> First, sorry for starting a new post - I didn't want anyone to have to read through the whole first one when the questions were completely different :/
>
> Second, I honestly have no idea how to answer your questions.  I am a sophomore in high school and I am trying to learn this on my own because my teacher is not very good at explaining things.
>
> i just cant figure out how to get the total when an order is placed without the customer ordering at least one of each item.  I also can't figure out how to get the shipping to calculate correctly. It is an intro class and we are using just the basics. Most of what Mitya said is stuff I've never seen before, although I am very grateful for her response, I am supposed to use only what the teacher "taught".


I'm sorry to hear that, I just want to clarify - the teacher did not yet 
cover
the use of lists, dictionaries and functions?

If that's the case, I have to agree with you that he's probably not a very
good teacher because this task can be done much easier and better
with those 3 concepts, all of which are very easy. If you are barred from
using them, Joshua's post will be most helpful.

If you are curious about the 3 concepts I mentioned, they are covered
in the official python tutorial, but the quick rundown is:

list: a list of items, e.g. a shopping list:

shoplist = ["tea", "cake", "blueberries"]

dictionary: a collection of keys/values, like words/definitions in a 
dictionary:

shopping_cart = {"yoda": 3, "dvd": 5}      # 3 of yoda figures, 5 dvds


function: a way to group a bunch of code together:

def main():
   # do something
   # do something else
   # la la la

main()

The nice thing about functions is that if you need to repeat
something, let's say, two thousand times, you just call the
function two thousand times, e.g.:

for x in range(2000): main()

Which is much easier than typing in two thousand copies of the same code
  (don't ask me how I know!)

  - mitya


-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/




More information about the Python-list mailing list