Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. """
  2. Title: Home Inventory With Tuples
  3. Dev: Craig Lewin
  4. Date: April 18 2019
  5. ChangeLog (Who, When, What)
  6. - Craig Lewin, April 18 2019: Created Script
  7. - Craig Lewin, April 19 2019: Continued to work on script. Updated ideas about when to convert strings to tuples
  8. """
  9.  
  10. # Start loop asking for item names and values. Exit loop on blank entry.
  11. collectingData = True  # Flag variable for collectingData loop. Set to false when user is done entering items.
  12. tplDataStorage = "Item", "Value in USD",  # Initialize data storage tuple for later use and human readability.
  13.  
  14. while collectingData:
  15.     # Ask user for item name and value.
  16.     itemName = (input("Name an object near you: "))
  17.     itemValue = (input("Guess that object's worth in dollars: "))
  18.  
  19.     # Concatenate item name and value strings into a tuple.
  20.     itemNameAndValue = itemName + " - " + itemValue
  21.  
  22.     # Store each new item/price string in a 2-dimensional tuple.
  23.     tplDataStorage += itemNameAndValue,
  24.     loopCheck = input("\nPress enter to continue. To exit, type 'exit': ")
  25.     if loopCheck.lower() == "exit":
  26.         collectingData = False  # Exit the loop by setting collectingData to false.
  27.  
  28. print(tplDataStorage)
  29.  
  30. # TODO You want to end up with something like 2DTuple = ("Phone", "700") ("Computer", "2000"), ("Rock", "0")
  31.  
  32. # Store both pieces of data in a text file called HomeInventory.txt
  33. #objFile = open("HomeInventory.txt", "a")
  34. #objFile.write(itemNameAndValue)
  35. #objFile.close()
  36.  
  37. # Politely end the script.
  38. #input("Nice. Press enter to exit.")
  39.  
  40. # TODO When the program exits, ask if they would like to save the data to a text file called HomeInventory.txt
  41.  
  42. # TODO If they agree, write the data from the tuple to the text file.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement