0

I am trying to find a way to store data based on a user's move (input).

For example, they can pick up a ball multiple times, and that gets added to their inventory (data storage).

Any ideas as to how I could do this and be able to update the data, based on how many times it is picked up?

Thanks

1
  • 1
    What did you try so far? Commented Jan 20, 2016 at 4:01

1 Answer 1

2

Not enough details were provided, and therefore am giving you the best answer possible after interpreting your question.

You can use a dictionary to store all the items as the key, and the number of times the user picked that item up as a value.

data = {"ball": 0, "bat": 0, "helmet":0}

answer = input("What would you like to pick up? (ball, bat, or a helmet?)")
if answer in data:
    data[answer] += 1
else:
    data[answer] = 1        

This was a simple example, and I had pre-popualated the dictionary. In your program you will have to check if the item exists or not, and then increment like I did. Hope this helped.

Sign up to request clarification or add additional context in comments.

Comments

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.