0

I'm creating a shopping system in python for learning purposes.

I'm trying to create an array of items with prices. I am using a pick import for a gui user input. here is my code.

from pick import pick

## shopping system

title = 'What would you like to do: '
options = ['shop', 'increase wallet', 'exit']
option, index = pick(options, title)

def wallet_increase(value):
    wallet = 15.00
    wallet += value
    print("New wallet balance $" + str(wallet)) 

def my_shop():
    title = 'What would you like to purchase: '
    products = ['eggs', 'cheese', 'meat', 'chocolate']
    choice, index = pick(products, title)
    print(choice + " has been selected")

if option == 'increase wallet':
    value = float(input ("Wallet increase amount? $"))
    wallet_increase(value)

if option == 'shop':
    my_shop()

essentially what I am trying to achieve is upon the user picking a product (cheese for example). It will ultimately subtract the product price from the wallet value. I currently only have the products with no prices attached to them. I dont understand how I can achieve an array with prices linked to the products.

2
  • Might be best to use a dict to map prices to products Commented Apr 18, 2020 at 9:59
  • 2
    use dictionary {product_name: price} Commented Apr 18, 2020 at 9:59

1 Answer 1

3

This is only reference code for dict you need to change as per your requirement

from pick import pick

## shopping system

title = 'What would you like to do: '
options = ['shop', 'increase wallet', 'exit']
option, index = pick(options, title)
wallet=15
def wallet_increase(value,wallet):
    wallet += value
    print("New wallet balance $" + str(wallet)) 

def wallet_decrese(value,wallet):
    wallet-=value
    print("New wallet balance $" + str(wallet)) 

def my_shop():
    title = 'What would you like to purchase: '
    products ={'eggs':10,'cheese':20,'meat':5,'chocolate':12}
    choice=pick(list(products.keys()),title)
    wallet_decrese(products[choice[0]],wallet)
    print(choice[0] + " has been selected")

if option == 'increase wallet':
    value = float(input ("Wallet increase amount? $"))
    wallet_increase(value)

if option == 'shop':
    my_shop()
Sign up to request clarification or add additional context in comments.

1 Comment

@patrickGold just give upvote and mark as an answer it will help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.