In: Computer Science
In Python Create customer information system as follows:
Ask the user to enter name, phonenumber, email. Create a file by his name and save it in the hard disk. Do this repeatedly until all the users are entered. (for example, if the user enters 10 customers’s information, there should be 10 different files created.)
Now build the customer value for a retail company as follows:
Ask the customer to enter his name. If you have his information already stored, then showing him his stored number and email. If not, ask his phone and email and save on his name.
Ask him to enter what he buying (itemname, quantity, unit price.) repeatedly until he enters all the items. Calculate the total including the tax (0.0825). Append the total price to his file.
Save below code in file ending with .py extension import os def create_file(): """ function to create file with user name if existing file with name it will replace :return: """ while 1: name = input("Enter name: ") phone_number = input("Enter phone number: ") email = input("Enter email: ") with open(name, 'w') as f: f.write("Name: %s\n" % name) f.write("Phone: %s\n" % phone_number) f.write("Email: %s\n" % email) another_entry = input("do you want to add another entry[y/n]: ").lower() if another_entry not in ('y', 'yes'): break def build_info(): """ function to build info :return: """ # getting all files files = os.listdir() name = input("Enter name: ") # if name file not found if name not in files: # creating new one print("%s not found" % name) phone_number = input("Enter phone number: ") email = input("Enter email: ") with open(name, 'w') as f: f.write("Name: %s\n" % name) f.write("Phone: %s\n" % phone_number) f.write("Email: %s\n" % email) with open(name) as f: for line in f.readlines(): print(line.strip()) # asking item details and adding with open(name, 'a') as f: print("\n{:<20s}{:<20s}{:<20}{:<20}".format("Item", "Quantity", "Per Unit", "Price"), file=f) total = 0 tax = 0.0825 while 1: item_name = input("Item name: ") quantity = int(input("Enter the quantity: ")) per_unit_price = float(input("Enter per unit price: ")) price = quantity * per_unit_price total += price print("{:<20s}{:<20s}{:<20}{:<20}".format(item_name, str(quantity), str(per_unit_price), str(price)), file=f) another_entry = input("do you want to add another item[y/n]: ").lower() if another_entry not in ('y', 'yes'): break total += tax print("-" * 70, file=f) print(" " * 55 + " Total %.2f" % total, file=f) # calling both functions create_file() build_info()
# OUT
# File
Please do let me know if u have any concern...