Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. def createOrder():
  2.  
  3.  
  4. while True:
  5. customerID = input("Please enter your customer ID: ")
  6. with open('customers.txt') as f:
  7. if customerID in f.read():
  8. print("\nThe customer ID is valid")
  9. break
  10. else:
  11. print("\nThat Customer ID does not exist. Please try again")
  12.  
  13. while True:
  14. orderID = input("\nPlease enter a unique ID for your order (5 numbers): ")
  15. if orderID.isdigit()==False:
  16. print("\nYou can only use numbers for your unique ID")
  17. elif len(orderID) != 5:
  18. print("\nYou must use exactly 5 digits")
  19. else:
  20. print("\nYour unique ID is OR" + orderID)
  21. break
  22.  
  23.  
  24. while True:
  25. item_name = input("\nPlease type the name of the item you wish to purchase: ")
  26. with open('products.txt') as f:
  27. if item_name in f.read():
  28. print("\nProduct Added")
  29. break
  30. elif item_name not in f.read():
  31. print("\nProduct does not exist. Please try again")
  32.  
  33.  
  34. while True:
  35. readStock = open('products.txt','r')
  36. location = readStock.readline()
  37. price = float(location[350:354].strip())
  38. quantity = int(input("\nHow much of this product would you like to purchase?: "))
  39. if quantity >100:
  40. print("\nYou can only buy up to 100 items")
  41. elif quantity <1:
  42. print("\nYou must buy a minimum of 1 item!")
  43. finalPrice = float(price*quantity)
  44. if finalPrice >=50:
  45. finalPrice *=0.95
  46. finalPrice +=5.99
  47. else:
  48. finalPrice <=50
  49. finalPrice +=5.99
  50. readStock.close()
  51. break
  52.  
  53. orderID = ("OR")+ orderID
  54. orderID=orderID.strip()
  55. orderID=orderID.lower()
  56. orderIDStore=orderID.ljust(60)
  57. customerID=customerID.strip()
  58. customerID=customerID.lower()
  59. customerIDStore=customerID.ljust(13)
  60. finalPrice=str(finalPrice)
  61. finalPrice=finalPrice.ljust(7)
  62. today = date.today()
  63. today = str(today)
  64. today = today.ljust(15)
  65. quantity = str(quantity)
  66. quantityStore = quantity.ljust(55)
  67. unpaid = str(0)
  68. order_file = open('orders.txt', 'a')
  69. stock_file = open('products.txt', 'r')
  70. for line in stock_file.readlines():
  71. if item_name in line:
  72. line = line.ljust(12)
  73. order_store = finalPrice + today + customerIDStore + quantityStore + orderIDStore + unpaid + line + "\n"
  74. order_file.write(order_store)
  75. print("\nThank you! Your chosen item(s) have been added to your order! ")
  76. order_file.close()
  77. stock_file.close()
  78. mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement