Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. def addItem(self, name=None, count=None, unit=None):
  2.  
  3. add = True
  4.  
  5. while add == True:
  6. os.system("cls")
  7. print("What is the item name?")
  8. name = input()
  9.  
  10. os.system("cls")
  11.  
  12.  
  13. if name in self.invDict:
  14. unit = self.invDict[name].unit
  15. print("You already have {} {} of {}, how many {} would you like to add?".format(self.invDict[name].count, self.invDict[name].unit, self.invDict[name].name, self.invDict[name].unit))
  16. while unit == None:
  17. try:
  18. print("What are the units?")
  19. for i in Inventory.units:
  20. print(i,Inventory.units.index(i))
  21. #inputUnit = int(input())
  22. #unit = Inventory.units[inputUnit]
  23. unit = Inventory.units[int(input())]
  24. except:
  25. os.system("cls")
  26. print("That unit is invalid, please type a number displayed:")
  27. print(i,Inventory.units.index(i))
  28. else:
  29. os.system("cls")
  30. print("You selected", unit+".")
  31.  
  32. print("How many {} of {}?".format(unit, name))
  33. while count == None:
  34. try:
  35. count = float(input())
  36. except:
  37. print("Whoops, that's not a number! Please input a valid amount")
  38. else:
  39. os.system("cls")
  40.  
  41. x = InvItem(name, count, unit)
  42. #print(x,x.name)
  43. #self.invDict[x.name]=x
  44. if x.name in self.invDict:
  45. self.invDict[x.name].count += x.count
  46. else:
  47. self.invDict[x.name] = x
  48. finally:
  49. pickle.dump(self.invDict, open("Inventory.db","wb"))
  50.  
  51. for k,v in self.invDict.items():
  52. print("You have {} {} of {}!".format(v.count, v.unit, k))
  53. #print(self.invDict)
  54. choice = input("Would you like to add another item? (y/n)")
  55. if choice.lower() == "n" or choice.lower() == "no":
  56.  
  57. add = False
  58. else:
  59. name=None
  60. count=None
  61. unit=None
  62.  
  63. ___________________________________________________
  64.  
  65. def remItem(self):
  66. remove=True
  67.  
  68. while remove==True:
  69. os.system("cls")
  70. print("Here is the current inventory, which selection would you like to remove from?")
  71. for k,v in self.invDict.items():
  72. print("{} {} of {}".format(v.count, v.unit, k))
  73. name=input()
  74.  
  75. if name in self.invDict:
  76. print("Out of {} {}, how many {} would you like to remove?".format(self.invDict[name].count, self.invDict[name].unit, self.invDict[name].name))
  77. self.invDict[name].count - float(input())
  78. else:
  79. os.system("cls")
  80. choice = input("That's not currently in your inventory, would you like to add an item instead? (y/n)")
  81. if choice.lower() == "n" or choice.lower() == "N":
  82. remove=True
  83. else:
  84. Inventory.addItem()
  85. finally:
  86. os.system("cls")
  87. print("Now there are only {} {} of {}")
  88.  
  89. choice = input("Would you like to remove another item? (y/n)")
  90. if choice.lower() == "n" or choice.lower() == "no":
  91.  
  92. remove=False
  93. else:
  94. remove=True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement