Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def createOrder():
- while True:
- customerID = input("Please enter your customer ID: ")
- with open('customers.txt') as f:
- if customerID in f.read():
- print("\nThe customer ID is valid")
- break
- else:
- print("\nThat Customer ID does not exist. Please try again")
- while True:
- orderID = input("\nPlease enter a unique ID for your order (5 numbers): ")
- if orderID.isdigit()==False:
- print("\nYou can only use numbers for your unique ID")
- elif len(orderID) != 5:
- print("\nYou must use exactly 5 digits")
- else:
- print("\nYour unique ID is OR" + orderID)
- break
- while True:
- item_name = input("\nPlease type the name of the item you wish to purchase: ")
- with open('products.txt') as f:
- if item_name in f.read():
- print("\nProduct Added")
- break
- elif item_name not in f.read():
- print("\nProduct does not exist. Please try again")
- while True:
- readStock = open('products.txt','r')
- location = readStock.readline()
- price = float(location[350:354].strip())
- quantity = int(input("\nHow much of this product would you like to purchase?: "))
- if quantity >100:
- print("\nYou can only buy up to 100 items")
- elif quantity <1:
- print("\nYou must buy a minimum of 1 item!")
- finalPrice = float(price*quantity)
- if finalPrice >=50:
- finalPrice *=0.95
- finalPrice +=5.99
- else:
- finalPrice <=50
- finalPrice +=5.99
- readStock.close()
- break
- orderID = ("OR")+ orderID
- orderID=orderID.strip()
- orderID=orderID.lower()
- orderIDStore=orderID.ljust(60)
- customerID=customerID.strip()
- customerID=customerID.lower()
- customerIDStore=customerID.ljust(13)
- finalPrice=str(finalPrice)
- finalPrice=finalPrice.ljust(7)
- today = date.today()
- today = str(today)
- today = today.ljust(15)
- quantity = str(quantity)
- quantityStore = quantity.ljust(55)
- unpaid = str(0)
- order_file = open('orders.txt', 'a')
- stock_file = open('products.txt', 'r')
- for line in stock_file.readlines():
- if item_name in line:
- line = line.ljust(12)
- order_store = finalPrice + today + customerIDStore + quantityStore + orderIDStore + unpaid + line + "\n"
- order_file.write(order_store)
- print("\nThank you! Your chosen item(s) have been added to your order! ")
- order_file.close()
- stock_file.close()
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement