Minor Project Merged
Minor Project Merged
Minor Project Merged
BIHAR, 846005
SESSION:2020-23
A PROJECT REPORT
ON
FANTASY CRICKET GAME
USING PYTHON
We are really thankful to our course the Principal Dr. KK PATHAK and
the HOD D.N SINGH, Computer Science and Engineering
Department, Government Polytechnic Darbhanga for his invaluable
guidance and assistance, without which the accomplishment of the
task would have never been possible.
World and realize the interrelation without which a Project can never
progress. In our present project we have chosen the topic- “FANTASY
CRICKET GAME USING PYTHON”.
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(900, 675)
MainWindow.move(100,10)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
MainWindow.setAutoFillBackground(False)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
spacerItem = QtWidgets.QSpacerItem(250, 20, QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem)
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setEnabled(False)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.horizontalLayout_5.addWidget(self.label_4)
self.e1 = QtWidgets.QLineEdit(self.centralwidget)
self.e1.setEnabled(False)
self.e1.setObjectName("e1")
self.horizontalLayout_5.addWidget(self.e1)
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setEnabled(False)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.horizontalLayout_5.addWidget(self.label_6)
self.e2 = QtWidgets.QLineEdit(self.centralwidget)
self.e2.setEnabled(False)
self.e2.setObjectName("e2")
self.horizontalLayout_5.addWidget(self.e2)
self.label_7 = QtWidgets.QLabel(self.centralwidget)
self.label_7.setEnabled(False)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_7.setFont(font)
self.label_7.setObjectName("label_7")
self.horizontalLayout_5.addWidget(self.label_7)
self.e3 = QtWidgets.QLineEdit(self.centralwidget)
self.e3.setEnabled(False)
self.e3.setObjectName("e3")
self.horizontalLayout_5.addWidget(self.e3)
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setEnabled(False)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_8.setFont(font)
self.label_8.setObjectName("label_8")
self.horizontalLayout_5.addWidget(self.label_8)
self.e4 = QtWidgets.QLineEdit(self.centralwidget)
self.e4.setEnabled(False)
self.e4.setObjectName("e4")
self.horizontalLayout_5.addWidget(self.e4)
spacerItem1 = QtWidgets.QSpacerItem(250, 20, QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem1)
self.horizontalLayout.addLayout(self.horizontalLayout_5)
self.verticalLayout.addLayout(self.horizontalLayout)
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.verticalLayout.addWidget(self.line)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem2)
self.verticalLayout_8 = QtWidgets.QVBoxLayout()
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.label = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.verticalLayout_8.addWidget(self.label, 0, QtCore.Qt.AlignHCenter)
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setTitle("")
self.groupBox.setFlat(False)
self.groupBox.setCheckable(False)
self.groupBox.setObjectName("groupBox")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.groupBox)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.rb1 = QtWidgets.QRadioButton(self.groupBox)
self.rb1.setObjectName("rb1")
self.horizontalLayout_4.addWidget(self.rb1)
self.rb2 = QtWidgets.QRadioButton(self.groupBox)
self.rb2.setObjectName("rb2")
self.horizontalLayout_4.addWidget(self.rb2)
self.rb3 = QtWidgets.QRadioButton(self.groupBox)
self.rb3.setObjectName("rb3")
self.horizontalLayout_4.addWidget(self.rb3)
self.rb4 = QtWidgets.QRadioButton(self.groupBox)
self.rb4.setObjectName("rb4")
self.horizontalLayout_4.addWidget(self.rb4)
self.rb1.toggled.connect(self.ctg)
self.rb2.toggled.connect(self.ctg)
self.rb3.toggled.connect(self.ctg)
self.rb4.toggled.connect(self.ctg)
self.verticalLayout_8.addWidget(self.groupBox)
self.list1 = QtWidgets.QListWidget(self.centralwidget)
self.list1.setAutoFillBackground(True)
self.list1.setStyleSheet("color: rgb(0, 0, 127);\n"
"font: 75 12pt \"MS Shell Dlg 2\";")
self.list1.setAutoScroll(True)
self.list1.setObjectName("list1")
self.list1.itemDoubleClicked.connect(self.removelist1)
self.verticalLayout_8.addWidget(self.list1)
self.btn1 = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.btn1.setFont(font)
self.btn1.setObjectName("btn1")
self.verticalLayout_8.addWidget(self.btn1)
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setText("")
self.label_5.setAlignment(QtCore.Qt.AlignCenter)
self.label_5.setObjectName("label_5")
self.verticalLayout_8.addWidget(self.label_5)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout_2.addLayout(self.verticalLayout_2)
self.verticalLayout_8.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3.addLayout(self.verticalLayout_8)
spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem3)
self.verticalLayout_9 = QtWidgets.QVBoxLayout()
self.verticalLayout_9.setObjectName("verticalLayout_9")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.verticalLayout_9.addWidget(self.label_2)
self.l1 = QtWidgets.QLabel(self.centralwidget)
self.l1.setEnabled(True)
font = QtGui.QFont()
font.setFamily("MS Shell Dlg 2")
font.setPointSize(12)
font.setBold(False)
font.setItalic(False)
font.setWeight(9)
self.l1.setFont(font)
self.l1.setAlignment(QtCore.Qt.AlignCenter)
self.l1.setObjectName("l1")
self.verticalLayout_9.addWidget(self.l1)
self.line_2 = QtWidgets.QFrame(self.centralwidget)
self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_2.setObjectName("line_2")
self.verticalLayout_9.addWidget(self.line_2)
spacerItem4 = QtWidgets.QSpacerItem(20, 3, QtWidgets.QSizePolicy.Minimum,
QtWidgets.QSizePolicy.Minimum)
self.verticalLayout_9.addItem(spacerItem4)
self.list2 = QtWidgets.QListWidget(self.centralwidget)
self.list2.setStyleSheet("color: rgb(0, 0, 127);\n"
"font: 75 12pt \"MS Shell Dlg 2\";")
self.list2.setObjectName("list2")
self.list2.itemDoubleClicked.connect(self.removelist2)
self.verticalLayout_9.addWidget(self.list2)
self.btn2 = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.btn2.setFont(font)
self.btn2.setObjectName("btn2")
self.verticalLayout_9.addWidget(self.btn2)
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setText("")
self.label_3.setPixmap(QtGui.QPixmap("dream1.png"))
self.label_3.setObjectName("label_3")
self.verticalLayout_9.addWidget(self.label_3)
self.horizontalLayout_3.addLayout(self.verticalLayout_9)
spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem5)
self.verticalLayout.addLayout(self.horizontalLayout_3)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 900, 21))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionNew = QtWidgets.QAction(MainWindow)
self.actionNew.setObjectName("actionNew")
self.actionOpen = QtWidgets.QAction(MainWindow)
self.actionOpen.setObjectName("actionOpen")
self.actionSave_Team = QtWidgets.QAction(MainWindow)
self.actionSave_Team.setObjectName("actionSave_Team")
self.actionRules = QtWidgets.QAction(MainWindow)
self.actionRules.setObjectName("actionRules")
self.actionInstructions = QtWidgets.QAction(MainWindow)
self.actionInstructions.setObjectName("actionInstructions")
self.actionQuit = QtWidgets.QAction(MainWindow)
self.actionQuit.setObjectName("actionQuit")
self.menuFile.addAction(self.actionNew)
self.menuFile.addAction(self.actionOpen)
self.menuFile.addAction(self.actionSave_Team)
self.menuFile.addAction(self.actionQuit)
self.menuFile.triggered[QtWidgets.QAction].connect(self.menufunction)
self.menubar.addAction(self.menuFile.menuAction())
self.bat=0
self.bwl=0
self.ar=0
self.wk=0
self.avl=1000
self.used=0
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.customContextMenuRequested.connect(self.context_menu)
def save_Team(self,nm,string,val):
if self.bat+self.bwl+self.ar+self.wk!=11:
self.showdlg("Insufficient players")
return
sql="INSERT INTO teams (name, players, value) VALUES
('"+nm+"','"+string+"','"+str(val)+"');"
try:
cur=conn.execute(sql)
conn.commit()
self.showdlg ("Team Saved successfully")
except:
self.showdlg ("error in operation")
conn.rollback()
def open_Team(self):
sql="select name from teams"
cur=conn.execute(sql)
teams=[]
for row in cur:
teams.append(row[0])
team, ok = QtWidgets.QInputDialog.getItem(MainWindow, "Fantasy Cricket Game",
"Choose a team", teams, 0, False)
if ok and team:
self.l1.setText(team)
sql1="select players, value from teams where name='"+team+"'"
cur=conn.execute(sql1)
row=cur.fetchone()
selected=row[0].split(',')
self.list2.addItems(selected)
self.used=row[1]
self.avl=1000-row[1]
count=self.list2.count()
for i in range(count):
player=self.list2.item(i).text()
sql="select ctg from stats where player='"+player+"'"
cur=conn.execute(sql)
row=cur.fetchone()
ctgr=row[0]
if ctgr=="BAT":self.bat+=1
if ctgr=="BWL":self.bwl+=1
if ctgr=="AR":self.ar+=1
if ctgr=="WK":self.wk+=1
self.showstatus()
def context_menu(MainWindow):
MainWindow.menu = QtWidgets.QMenu()
def fillList(self,ctgr):
if self.l1.text()=='Team_name':
self.showdlg("Enter name of team")
return
self.list1.clear()
cursor = conn.execute("SELECT player from stats where ctg='"+ctgr+"'")
for row in cursor:
selected=[]
for i in range(self.list2.count()):
selected.append(self.list2.item(i).text())
if row[0] not in selected:self.list1.addItem(row[0])
def ctg(self):
ctgr=''
if self.rb1.isChecked()==True:ctgr='BAT'
if self.rb2.isChecked()==True:ctgr='BWL'
if self.rb3.isChecked()==True:ctgr='AR'
if self.rb4.isChecked()==True:ctgr='WK'
self.fillList(ctgr)
def showstatus(self):
self.e1.setText(str(self.bat))
self.e2.setText(str(self.bwl))
self.e3.setText(str(self.ar))
self.e4.setText(str(self.wk))
self.btn1.setText("Available Points : {}".format(self.avl))
self.btn2.setText("Points used : {}".format(self.used))
if __name__ == "__main__":
import sqlite3
conn = sqlite3.connect('fantasy.db')
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
conn.close()
GOVERMENT POLYTECHIC
DARBHANGA
DARBHANGA, (846004)
SUBMITTED BY:-
SUBMITTED TO
SBTE , PATNA
Date :-
Module 2 Assignment Solution
Sample Solution
There is no single correct solution for this assignment. This is a sample solution.
Data field Data type Example Your reason for using this
identifier data type
Solution
Functions for the module
def batscore(d):
name=d.get('name')
runs=d.get('runs')
balls=d.get('balls')
batscore=int(runs/2)
four=d.get('4')
six=d.get('6')
batscore=int(runs/2)
if batscore>=50: batscore+=5
if batscore>=100: batscore+=10
if runs>0:
sr=runs*100/balls
if sr>=80 and sr<100: batscore+=2
if sr>=100:batscore+=4
batscore=batscore+four
batscore=batscore+2*six
return {'name':name,'batscore':batscore}
def bowlscore(d):
name=d.get('name')
wkt=d.get('wkts')
balls=d.get('overs')
runs=d.get('runs')
bowlscore=wkt*10
if wkt>=3: bowlscore=bowlscore+5
if wkt>=5: bowlscore=bowlscore=bowlscore+10
if balls>0:
er=runs/overs
#print ("eco:",er)
if er<=2: bowlscore=bowlscore+10
if er>2 and er<=3.5: bowlscore=bowlscore+7
if er>3.5 and er<=4.5: bowlscore=bowlscore+4
return {'name':name,'bowlscore':bowlscore}
Script for importing the functions to calculate batting or bowling score assuming the functions
are stored in a file called functions.py. (You can also execute these statements in the
interpreter.)
for i in l1:
print (batscore(i))
for i in l2:
print (bowlscore(i))
def get_royalty(self):
if self.copies<=500:
self._royalty=self.copies*self.price*10/100
elif self.copies<=1000:
self._royalty=500*self.price*10/100+ \
(self.copies-500)*self.price*12.5/100
else:
self._royalty=500*self.price*10/100 + \
500*self.price*12.5/100 + \
(self.copies-1000)*self.price*15/100
return self._royalty
class ebook(book):
def __init__(self, aut, pub, p, cp=0, form=None):
super().__init__(aut,pub,p,cp)
self.format=form
def get_format(self):
return self._format
def set_format(self, form):
self._format=form
return
format=property(get_format, set_format)
def get_royalty(self):
ryl=super().get_royalty()
ryl=ryl-ryl*12/100
self._royalty=ryl
return self._royalty
if __name__== "__main__":
print ('print book example')
b1=book('aa','ss',100,600)
print ("Royalty earned : ", b1.get_royalty())
print ('ebook example')
e1=ebook('aa','ss',100, 3, 'PDF')
print ('Royalty earned' , e1.get_royalty())
Module 5 Assignment
Solution
Part 1: To create the required database and add data programmatically by using the Insert
query
import sqlite3
db=sqlite3.connect("m5assignment.db")
cur=db.cursor()
cur.execute('''CREATE TABLE books (
BookID INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT (50) NOT NULL,
author TET(20),
price REAL);''')
for x in range(5):
try:
cur=db.cursor()
cur.execute(sql)
db.commit()
print ("one record added successfully")
except:
print ("error in operation")
db.rollback()
db.close()
Part 2: To enter the title and number of copies and see the total cost
import sqlite3
db=sqlite3.connect("m5assignment.db")
cur=db.cursor()
total=0
while True:
else:
print ("Title Not Found")
choice=input("add more books[Y/N]?")
if choice=='N': break
print ("Total cost of Purchased Books",total)
db.close()
Introduction
For this assignment, read the scenario below and then respond to the problem statement
described.
Scenario
You are required to design the data structure to display the individual player stats for cricket
players. A player may have represented more than one team and may have played in more
than one format such as Test, ODI and T20.
Problem Statement
Create a list of different data fields and use appropriate Python data types to represent each
of them.
Assignment Submission
You can use the table format displayed below for your response. You can add additional
columns of information if you want. Create a document/pdf of your response and upload a zip
file using the Progress Tracker.
Data field Data type Example Your reason for using this data
identifier type
Introduction
For this assignment, read the scenario below and then respond to the problem statement
described.
Scenario
The 'Man of the Match' award of a 50-over cricket match is decided by computing points
earned by players. The points are calculated on the basis of the following rules:
Batting
● 1 point for 2 runs scored
● Additional 5 points for a half-century
● Additional 10 points for a century
● 2 points for strike rate (runs/balls faced) of 80-100
● Additional 4 points for strike rate>100
● 1 point for hitting a boundary (four) and 2 points for over boundary (six)
Bowling
● 10 points for each wicket
● Additional 5 points for three wickets in innings
● Additional 10 points for 5 wickets or more in innings
● 4 points for economy rate (runs given per over) between 3.5 and 4.5
● 7 points for an economy rate between 2 and 3.5
● 10 points for an economy rate less than 2
Fielding
● 10 points each for catch/stumping/run out
The performance of each player is stored in a dictionary object. Displayed below is data for 5
players.
Problem Statement
Assuming that these are the top 5 performers, write a Python program to decide the player
with the highest points. Develop separate functions to compute batting and bowling points
and save them in a module. These functions should be imported into the main code.
Assignment Submission
Your submission should have a fully functional code with:
When your script is run, it should generate a result which might look like this:
Hint
The calculation of points will require conditional logic to be applied. Since this is to be
performed for 5 players, there’s looping involved. Defining and calling functions from a
module is also required.
Then design a new ‘ebook’ class inherited from ‘book’ class. Add ebook format (EPUB, PDF,
MOBI etc) as additional instance variable in inherited class.
Override royalty() method to deduct GST @12% on ebooks
Module 5 Assignment
Introduction
In this assignment, you are required to apply your knowledge of connecting a SQLite
database to a Python program. Read the scenario below and then respond to the problem
statement described.
Scenario
In a bookstore, somewhere in India.
Pi: Hi, do you have Think Python?
Store Assistant: Let me check, Sir.
(The assistant checks on his computer. This is what his screen looks like.)
Store Assistant: Yes Sir, we have it in stock. It costs Rs. 475. Would you like to take it?
Pi: Yes please. And give me two copies.
Store Assistant: Sure. Anything else, Sir?
Pi: Nope thanks. What's the total?
(The assistant now enters the number of copies on his computer. This is what his screen looks like.)
Problem Statement
Assume that you have to create such an application for maintaining a database of book titles
and their costs.
Part 1: Write the script to create the required database and add data programmatically by
using the Insert query.
Part 2: Write a Python script connecting to the database created that has the following
features:
Assignment Submission
Your submission should have fully functional code with:
1. One script file containing the code for create the required database and add data
programmatically by using the Insert query.
2. One script file with the main code which takes the book title (of a book you have
already entered into the database) and number of copies as input and displays the
output.
3. One database file containing data for the book id, title, author and price.
It is an online game where you create a virtual team of real cricket players
and score points depending on how your chosen players perform in real
life matches. To win a tournament, you must try and get the maximum
points and the No. 1 rank amongst other participants. Here's how a
Fantasy Cricket game may look like
Technology used:
1. Python (language)
. Basic knowledge (loops ,functions , connections
etc..)
. PYQT5 (install)
. QT designer (To make GUI- use of icons, boxes
etc…)
2. SQL or Excel Sheet for Database ( for connecting
data )
Data Base design: