Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Title: Home Inventory With Tuples
- Dev: Craig Lewin
- Date: April 18 2019
- ChangeLog (Who, When, What)
- - Craig Lewin, April 18 2019: Created Script
- - Craig Lewin, April 19 2019: Continued to work on script. Updated ideas about when to convert strings to tuples
- """
- # Start loop asking for item names and values. Exit loop on blank entry.
- collectingData = True # Flag variable for collectingData loop. Set to false when user is done entering items.
- tplDataStorage = "Item", "Value in USD", # Initialize data storage tuple for later use and human readability.
- while collectingData:
- # Ask user for item name and value.
- itemName = (input("Name an object near you: "))
- itemValue = (input("Guess that object's worth in dollars: "))
- # Concatenate item name and value strings into a tuple.
- itemNameAndValue = itemName + " - " + itemValue
- # Store each new item/price string in a 2-dimensional tuple.
- tplDataStorage += itemNameAndValue,
- loopCheck = input("\nPress enter to continue. To exit, type 'exit': ")
- if loopCheck.lower() == "exit":
- collectingData = False # Exit the loop by setting collectingData to false.
- print(tplDataStorage)
- # TODO You want to end up with something like 2DTuple = ("Phone", "700") ("Computer", "2000"), ("Rock", "0")
- # Store both pieces of data in a text file called HomeInventory.txt
- #objFile = open("HomeInventory.txt", "a")
- #objFile.write(itemNameAndValue)
- #objFile.close()
- # Politely end the script.
- #input("Nice. Press enter to exit.")
- # TODO When the program exits, ask if they would like to save the data to a text file called HomeInventory.txt
- # TODO If they agree, write the data from the tuple to the text file.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement