how to take a dictionary from this list ?

Shop = ["Apple" , "orange", "mangoo" . "Tomato" . "grape"]
Example

$python shop.py

  1. apple
  2. orange
  3. mangoo
  4. tomato
  5. grape

What will u buy? use number (1-5) : 2
You want, "orange", How much do u want it: 10

> {"orange : 10}
  1. apple
  2. orange
  3. mangoo
  4. tomato
  5. grape

What will u buy? use number (1-5) : 1
You want, "apple", How much do u want it ?: 3

 {"apple : 3" , "orange : 10"}
  1. apple
  2. orange
  3. mangoo
  4. tomato
  5. grape

What will u buy? use number (1-5) : 2
You want, "orange", How much do u want it ?: 4

{"apple : 3" , "orange : 14"}
  1. apple
  2. orange
  3. mangoo
  4. tomato
  5. grape
And many more...

If I chose same order, like "Apple" I want to Buy "3", in the next command I want to buy 6 " Apple" .
So equal for the apple is "9"...

Note : python 2.7 , this method using looping.
without using zip, def, return and break option.

Recommended Answers

All 2 Replies

Can you post some code that you already created?
What I can see now that you will have while/for loop that will say what do you want to buy?
And you will have one more array same as this with frutis just with integer values.
Every time when somebody put let say I want to buy 2 mean orange with value 9 you will add that 9 to this second array.
When all buying is done you just print out how many things you want to buy.
Hope this will help you, but if you want more help please post some code.
Regards, Mike.

This my code

s = ["Apple" , "orange", "mangoo" , "Tomato" , "grape"]

dict = {}

x = """

1. apple
2. orange
3. mangoo
4. tomato
5. grape """



print x



while True:

    b = int(raw_input('what du want to buy?" (use number 1-7): '))

    b = s[b-1]

    print "You want" , b

    e = int(raw_input('how much? : '))



    e = {b:e}

    dict.update(e)

    print dict, x         

If I chosen same order , the values will change to newest update values from variable "e"
I want to equal with old values. If repeat same order...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.