from prettytable import PrettyTable

def billing():
    global myTable,a
    products={"PARK AVENUE SOAP: ":45,"DOVE SOAP: ":30,"SURF EXCEL(200gm): ":50,"VIM LIQUID(100ml): ":30,"WILD STONE SCENT: ":100,"PARACHUTE HAIR OIL(100ml): ":20,
    "PONDS POWDER: ":40,"APPLE(1kg): ":120,"ORANGE(1kg): ":150,"POMEGRANATE(1kg): ":160,"CUCUMBER(100g): ":50,"MAitemsListitemsListA(150ml): ":45,"PEPSI(150ml): ":60,"SPRITE(150ml): ":45,
    "OREO CHOCLATE CREAM: ":30,"MILK BIKIS CREAM: ":30,"WAFFLES: ":25,"DARK FANTASY: ":30,"ASHIRVAD ATTA: ":50,"IR 20 RICE(1kg): ":40}

    itemsList = list(products.keys())
    itemsPrice = list(products.values())

    productTable = PrettyTable(["S.No", "Product Name", "Price"])

    for i in range(len(products)):
        productTable.add_row([i+1, itemsList[i], itemsPrice[i]])
    
    print(productTable)
    
    print("\nEnter 0 if purchase is over")
    
    sum = 0
    product_list = []
    product_quantity = []
    price_list = []
    quantity_price = []
    for i in range(len(products)):
        item = int(input("\nEnter S.No: "))

        if 1<= item <= 20:
            print(itemsList[item-1])
            quantity = int(input("Enter the quantity: "))
            if quantity !=0:
                product_list.append(itemsList[item-1])
                product_quantity.append(quantity)
                price_list.append(itemsPrice[item-1])
                quantity_price.append(itemsPrice[item-1]*quantity)
                sum += itemsPrice[item-1]*quantity
            else:
                continue
        elif item == 0:
            break

    myTable = PrettyTable(["Product name", "Price of one quantity", "Product Quantity", "Total Product Price"])

    for i in range(len(product_list)):
        myTable.add_row([product_list[i], price_list[i], product_quantity[i], quantity_price[i] ])

    a=sum
    print("\nCurrent Bill Amount: ",a)
    return a
     

def printBill():
    print(myTable)

def main_member(amt):
    global member
    member={9876346757:["Steve","Silver",100,9],1111111111:["Dustin","Gold",300,7],9874563456:["Millie","Platinum",500,11]}
    phonenumber=int(input("\nEnter Your Phone Number: "))
    for i in member:
        if phonenumber==i:
          print("You are already a member!")
          true_member(i,amt)
          break
    else:
          print("You are not a member!")
          print("\nDo you wish to create a membership?")
          a=input("Enter YES or NO: ").lower()
          if a=="yes":
              create_member()
          elif a=="no":
              regularity(amt)

def create_member():
    global amt
    name=str(input("\nEnter your name:"))
    phoneno=int(input("Enter your phone number again:"))
    value=[]
    print("\nMEMBERSHIP DETAILS\nSilver : Rs.100\nGold : Rs.300\nPlatinum : Rs.500")
    ms=input("\nEnter the type of membership you want: ").title()
    if ms.lower()=="silver":
        amt+=100
    elif ms.lower()=="gold":
        amt+=300
    elif ms.lower()=="platinum":
        amt+=500
        
    value.append(name)
    value.append(ms)
    value.append(0)
    value.append(0)
    member[phoneno]=value
    printMemberdet(phoneno)
    print("\nCirrent Bill Amount: ",amt)

def true_member(number, bill_amt):
    gifts = {200: 'Container', 300: 'Mug', 400: 'Chair', 100: 'Frame'}
    card_type=member[number][1]
    points = 0.1 * bill_amt
    points_new = points
    if card_type.lower() == 'platinum':
        points_new = 3*points                   #3x points for platinum
    elif card_type.lower() == 'gold':
        points_new = 2*points                   #2x points for gold
    elif card_type.lower() == 'silver':
        pass                                    #same for silver
    else:
        print("Card type not stored correctly")
    member[number][2]=member[number][2]+points_new

    '''
    Points can be redeemed only if there is a minimum of 1000
    '''

    if member[number][2] >= 200:
        print(f"\nCurrent points: {member[number][2]}\n\nYou are eligible to redeem your points.\
            \nHowever, gifts are given only using the most of your points.")
        redeem = str(input('\nWould you like to redeem your points? yes/no: '))
        if redeem.lower() == 'yes':
            points_redeemed = member[number][2] - member[number][2]%200
            member[number][2] = member[number][2]%200
            
            print(f"You have redeemed {points_redeemed}\
                \nGift: {gifts[points_redeemed]}")
            
        elif redeem.lower() == 'no':
            print("Make sure to redeem your points on your next visit :)")
        else:
            print("Sorry, invalid response")
        
    
    else:
        print(f"New points, {member[number][2]}, have been added.")

    printMemberdet(number)

def printMemberdet(number):
    print (f"\n{'-'*7} Member's details {'-'*7}\
            \nCustomer's number: {number} \
            \nCustomer's name: {member[number][0]} \
            \nMembership Card: {member[number][1]} \
            \nPoints: {member[number][2]}")
    
def regularity(sum):
    l={"Saran":4,"Anand":6,"Austin":8,"Bilal":7,"Grisha":9,"Rithika":10}
    names = l.keys()
    customer = input("\nYour name :")
    if customer in names:
        if l[customer]>= 7:
            l[customer] = l[customer]+1
            print("\nYou are eligible to get a 5 percent discount!!","\t","Rs.",sum*0.05)
            print("Current Bill Amount: ",sum-(sum*0.05))
      
        else:
            print("Current Bill Amount: ",sum)
            l[customer] = l[customer]+1
        
    else:
        print("Your final bill :",sum)
        print("Thank  you! visit again")
        l[customer] = 1
    
  
def payment(amt):
    print("\nPayment")
    ans = str(input("How would you like to pay (Cash/Card): "))
    if ans.lower() == 'cash':
        printBill()
        print("\nFinal Bill Amount: ",amt)
        print("Thank You For Paying, Visit Again!")
    else:
        printBill()
        cc = amt*.02
        amt += cc
        print("\nCard Tax: ",cc)
        print("Final Bill Amount: ",amt)
        print("Thank You For Paying, Visit Again!")
    
    
amt=billing()
main_member(amt)
payment(amt)

 

Python Online Compiler

Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.

Taking inputs (stdin)

OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.

import sys
name = sys.stdin.readline()
print("Hello "+ name)

About Python

Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.

Tutorial & Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition IF-ELSE is used.

if conditional-expression
    #code
elif conditional-expression
    #code
else:
    #code

Note:

Indentation is very important in Python, make sure the indentation is followed correctly

2. For:

For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.

Example:

mylist=("Iphone","Pixel","Samsung")
for i in mylist:
    print(i)

3. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while condition  
    #code 

Collections

There are four types of collections in Python.

1. List:

List is a collection which is ordered and can be changed. Lists are specified in square brackets.

Example:

mylist=["iPhone","Pixel","Samsung"]
print(mylist)

2. Tuple:

Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.

Example:

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)

Below throws an error if you assign another value to tuple again.

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)

3. Set:

Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.

Example:

myset = {"iPhone","Pixel","Samsung"}
print(myset)

4. Dictionary:

Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.

Example:

mydict = {
    "brand" :"iPhone",
    "model": "iPhone 11"
}
print(mydict)

Supported Libraries

Following are the libraries supported by OneCompiler's Python compiler

NameDescription
NumPyNumPy python library helps users to work on arrays with ease
SciPySciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation
SKLearn/Scikit-learnScikit-learn or Scikit-learn is the most useful library for machine learning in Python
PandasPandas is the most efficient Python library for data manipulation and analysis
DOcplexDOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling