Stationary Shop

Stationary Shop

A new stationary shop has been opened in the city. The owner asks his accountant to take the list of items sold in the store. The list should contain the details of the items and their costs. Help the accountant to generate the prince list by writing a Python program.  Generate list with just 4 products –  A4sheets, pen, pencil and eraser and get the price of the items from the user.  Please refer the sample input and output statements for more clarifications.

Note:

  • The amount must be displayed with 2 decimal places. 
  • On entering the product price to be a negative number, the program should display the message ” Invalid input” and stop the program. 

Sample input 1 :

Cost of A4sheet:

40

Cost of pen:

20

Cost of pencil:

10

Cost of eraser:

5

Sample output 1 :

Items Details

A4sheet:40.00

Pen:20.00

Pencil:10.00

Eraser:5.00

Sample input 2 :

Cost of A4sheet:

40

Cost of pen:

20

Cost of pencil:

10

Cost of eraser:

-5

Sample output 2 :

Invalid input

Sample input 3 :

Cost of A4sheet:

86

Cost of pen:

10

Cost of pencil:

-34

Sample output 3 :

Invalid input

Code :-

s=float(input("Cost of A4sheet:"+"\n"))
f=False
if s>=0:
    p=float(input("Cost of pen:"+"\n"))
    if p>=0:
        c=float(input("Cost of pencil:"+"\n"))
        if c>=0:
            e=float(input("Cost of eraser:"+"\n"))
            if e>=0:
                f=True
                print("Items Details")
                print("A4sheet:%0.2f" % s)
                print("Pen:%0.2f" % p)
                print("Pencil:%0.2f" % c)
                print("Eraser:%0.2f" % e)

if f==False:
    print("Invalid input")
    exit()
            

Leave a Comment

Your email address will not be published. Required fields are marked *

x