Retail shop billing

# File handling 
# Retail shop billing 

import sys
import math

stock=None
order=None

try:
stock = open(sys.argv[1],"r")
# create dictionary
PriceList={}
for line in stock:
item,price = line.split()
PriceList[item]=int(price)
# print(PriceList)
billamt=0
for i in range(2,len(sys.argv)):
order = open(sys.argv[i],"r")
print("S.no\tItem\t\tRate\tQuantity\tAmount")
i=1
for line in order:
item,qty=line.split()
price = int(qty)*PriceList[item]
print(i,"\t",item.ljust(10),"\t",PriceList[item],"\t",int(qty),"\t\t",price)
billamt = billamt+price
                        i+=1
print("Total Amount =", billamt)
cgst = round(billamt*.09,2)
sgst = round(billamt*.09,2)
print("cgst =",cgst)
print("sgst =",sgst)
print("Net Amount =",math.floor(billamt+cgst+sgst))
print("**"*30)
except IOError as e:
print("File opening error : ", e)
except:
print("unknown error")
else:
print("\nThank you for shopping with us\n")
print("**"*30)

finally:
if(stock):
stock.close()
if(order):
order.close()
"""
Sample output:
input file: (3)

ShopPricelist.txt 
Walnut 700
Figs 520
Raisins 400
Chashewnut 680
Almond 700
Pistachio 1400
Dates 440
Apricot 650
Kiwi 680
Cardamon 3000
Pepper 480

custorder1.txt 
Walnut 1
Raisins 4
Almond 7
Dates 2

custorder2.txt
Apricot 2
Kiwi 4
Cardamon 5
Pepper 3



>python retailshopbilling.py ShopPricelist.txt custorder1.txt custorder2.txt

S.no    Item                Rate    Quantity        Amount
1        Walnut             700         1                   700
2        Raisins             400         4                   1600
3        Almond            700         7                   4900
4        Dates                440         2                   880

Total Amount = 8080
cgst = 727.2
sgst = 727.2
Net Amount = 9534
************************************************************

S.no    Item                Rate    Quantity        Amount
1        Apricot             650          2                   1300
2        Kiwi                  680         4                   2720
3        Cardamon        3000       5                   15000
4        Pepper              480         3                   1440

Total Amount = 20460
cgst = 1841.4
sgst = 1841.4
Net Amount = 24142
************************************************************

Thank you for shopping with us

************************************************************


"""

Pygame tool

PYGAME

 

Aim: To study about Pygame tool

 

Introduction to Pygame

Python is the most popular programming language and has vast libraries for various fields such as Machine Learning (Numpy, Pandas, Matplotlib), Artificial intelligence (Pytorch, TensorFlow), and Game development (Pygame, Pyglet).

Pygame was officially written by Pete Shinners. Pygame is a cross-platform set of Python modules designed for writing video games. Pygame adds functionality on top of the SDL library. Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. Pygame, together with SDL, allows users to create fully featured games and multimedia programs in the python language. Pygame is highly portable and runs on nearly every platform and operating system.

 

Pygame core modules

Pygame modules provide abstract access to specific hardware on user system, as well as uniform methods to work with that hardware. Important Pygame Modules include

cursors

load cursor images, includes standard cursors

display

control the display window or screen

draw

draw simple shapes onto a Surface

event

manage events and the event queue

font

create and render TrueType fonts

image

save and load images

joystick

manage joystick devices

key

manage the keyboard

mouse

manage the mouse

sndarray

manipulate sounds with numpy

surfarray

manipulate images with numpy

time

control timing

transform

scale, rotate, and flip images

 

 

General steps to creating a Pygame based program

1.    Importing and Initializing PyGame

1.    import the pygame library and initialize all the functions in the pygame modules. This allows pygame to connect its abstractions to user specific hardware.

2.    Setting Up the Display

1.    Create a screen / surface object on which the graphical operations will be performed.

3.    Draw objects / Load images on the surface object

4.    Create a clock and set the framerate

5.    Sound Effects

1.    pygame provides mixer to handle all sound-related activities. classes and methods in mixer provides background music and sound effects for various actions. music sub-module is used to stream individual sound files in a variety of formats.

6.    Using .blit() and .flip()

1.    blit stands for Block Transfer. blit is the process to render the game object onto the surface. The .blit() takes two arguments – The Surface to draw and the location (coordinates) at which to draw it on the source Surface.

2.    flip() updates the entire screen with everything that’s been drawn since the last flip.

7.    Setting Up the Game Loop – The game loop performs four very important functions:

    1. Processing Events.
      1. Process user input (Key presses, mouse movements, joystick movements) using the pygame event system.
      2. All events in pygame are placed in the event queue, which can then be accessed and manipulated.
    2. Updates the state of all game objects in response to the user input
    3. Updates the display and audio output
    4. Maintains the speed of the game
      1. Every cycle of the game loop is called a frame. The number of frames handled each second is called the frame rate.
      2. Frames continue to occur until some condition to exit the game is met. Example – The player closes the window.
  1. Terminate the program.