Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

while doing the bill of the 2nd peron the bill of 1st person get in this 2nd bill..what am i doing wrong?????

+2 votes
asked Aug 9, 2024 by Jan mulanthuruthy (150 points)
s={'football':800,'bat':890,'ball':560,'shoes':480,'boots':630,'jersey':470}
det={}
cust={}
def cus():
    nm=input('name:')
    ph=int(input('ph_no:'))
    det[nm]=ph
def buy():
    a=input('name:')
    if a in det:
        print('MENU:')
        for i in s:
            print(i,s[i],sep='=>')
        b=int(input('how many items needed:'))
        sum=0
        for i in range(b):
            c=input('what do you want:')
            d=int(input('quantity:'))
            cust[c]=d
            e=s.get(c,0)
            f=e*d
            sum=f+sum
def bill():
    g=input('name:')
    if g in det:
        j=f'''
                              BILL:
                            ---------
            name:{g}
            phn no:{det.get(g)}
            items:          quantity:        u_price:        price:
        ----------------------------------------------------------------'''
        print(j)
        if g in det:
            j=0
            for i in cust:
                t=s[i]*cust[i]
                j=t+j
                print(i,cust[i],s[i],t,sep='\t       \t')
            print('total amount:',j,'/-')
            
shop='''
        1.new customer
        2.buy product
        3.billing
        4.exit
        '''
while True:
    op=int(input(f'{shop}\nChoose your option:'))
    if op==1:
        cus()
    if op==2:
        buy()
    if op==3:
        bill()
    if op==4:
        break

1 Answer

0 votes
answered Aug 12, 2024 by Peter Minarik (101,340 points)
  1. Your variable names do not help to identify what you store in them. Use longer, more talkative names (e.g. customers, customer, total, etc)
  2. Even worse, you reuse the same variable name to store different things in them (e.g. j is used to store what to print on the screen then it's used to store the total amount.
I think the main problem is that you put all the purchases into cust, regardless of which customer purchased it:
cust[c]=d
Separate purchases per customer then you should be fine.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...