21bec001-internship-pdf
21bec001-internship-pdf
An Internship Report
Submitted to
Dr. Vijay Kumar Sharma
Faculty of Engineering
Submitted by
AARSH SAXENA
(21BEC001)
STUDENT’S DECLARATION
I hereby certify that the work which is being presented in the report, entitled “Programming
with Python” for the award of the degree of “Bachelors of Technology” submitted in the
School of Electronics & Communication, Faculty of Engineering & Technology, Shri Mata
Vaishno Devi University, Katra is an authentic record of my own work carried out under the
supervision of Sarvesh Agarwal (Founder and CEO Internshala), at Internshala.
The matter presented in this report has not been submitted by me for the award of any
degree/diploma of this or any other University/Institute.
ii
SHRI MATA VAISHNO DEVI UNIVERSITY
SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING
COPY OF CERTIFICATE
iii
SHRI MATA VAISHNO DEVI UNIVERSITY
SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING
ACKNOWLEDGEMENTS
It is my proud privilege and duty to acknowledge the kind of help and guidance received from
several people in preparation of this report. It would not have been possible to prepare this
report in this form without their valuable help, cooperation and guidance.
First and foremost, I wish to record our sincere gratitude to Internshala Coordinators for their
constant support and encouragement in preparation of this report and for making available
videos and interface facilities needed to prepare this report. The seminar on “Python” was very
helpful to us in giving the necessary background information and inspiration in choosing this
topic for the seminar. Their contributions and technical support in preparing this report are
greatly acknowledged.
Last but not the least, we wish to thank our parents for financing our studies in this college as
well as for constantly encouraging us to learn engineering. Their personal sacrifice in providing
this opportunity to learn engineering is gratefully acknowledged.
iv
SHRI MATA VAISHNO DEVI UNIVERSITY
SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING
ABSTRACT
This report discusses the training program at Internshala. It states the concept of python
programming.
It shows a brief background about the palce of training. It mentions some facts about the
department that was responsible for the learning program. The report describes about the
history, characteristic, features, concepts of python programming with project using these
concepts and SQLite database and PyQt toolkit.
v
TABLE OF CONTENTS
STUDENT’S DECLARATION ii
COPY OF CERTIFICATE iii
ACKNOWLEDGEMENTS iv
ABSTRACT v
TABLE OF CONTENTS vi
INTRODUCTION TO PYTHON 1
HISTORY OF PYTHON 1
PYTHON FEATURES 2
TRAINING CONTENTS 3
VARIABLES, EXPRESSIONS AND STATEMENTS 3
OPERATORS AND OPERANDS 4
EXPRESSIONS 4
COMMENTS 5
BOOLEAN EXPRESSIONS 5
CONDITIONAL EXECUTION 6
ALTERNATIVE EXECUTION 7
CHAINED CONDITIONALS 7
PYTHON LOOP 8
FUNCTIONS 9
PROFILE OF THE PROBLEM 9
DATABASE DESIGN 10
PROBLEM ANALYSIS 11
CODE 12
BIBLIOGRAPHY 25
vi
INTRODUCTION TO PYTHON
History of Python
Python was developed by Guido van Rossum in the late eighties and early nineties at the
National Research Institute for Mathematics and Computer Science in the Netherlands. Python
is derived from many other languages, including ABC, Modula-3, C, C++, Algol-68,
SmallTalk, and Unix shell and other scripting languages. Python is copyrighted. Like Perl,
Python source code is now available under the GNU General Public License (GPL).
Python is now maintained by a core development team at the institute, although Guido van
Rossum still holds a vital role in directing its progress.
vii
PYTHON FEATURES
Python's features include –
• Easy-to-learn − Python has few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.
• Easy-to-read − Python code is more clearly defined and visible to the eyes.
• Easy-to-maintain − Python's source code is fairly easy-to-maintain.
• A broad standard library − Python's bulk of the library is very portable and cross-
platform compatible on UNIX, Windows, and Macintosh.
• Interactive Mode − Python has support for an interactive mode which allows interactive
testing and debugging of snippets of code.
• Portable − Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
• Extendable − You can add low-level modules to the Python interpreter. These modules
enable programmers to add to or customize their tools to be more efficient.
• Databases − Python provides interfaces to all major commercial databases.
• GUI Programming − Python supports GUI applications that can be created and ported
to many system calls, libraries and windows systems, such as Windows MFC, Macintosh,
and the X Window system of Unix.
• Scalable − Python provides a better structure and support for large programs than shell
scripting.
• Apart from the above-mentioned features, Python has a big list of good features, few are
listed below −
• It supports functional and structured programming methods as well as OOP.
• It can be used as a scripting language or can be compiled to byte-code for building large
applications.
• It provides very high-level dynamic data types and supports dynamic type checking.
• IT supports automatic garbage collection.
• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
2
TRAINING CONTENTS
1. Introduction to Python
Learn how to install Python, distinguish between important data types and use basic
features of the Python interpreter, IDLE.
2. Using Variables in Python
Learn about numeric, string, sequence and dictionary data types and relevant operations
while practicing Python syntax.
3. Basics of Programming in Python
Learn how to write programs using conditionals, loops, iterators and generators, functions
and modules and packages.
4. Principles of Object-oriented Programming (OOP)
Learn about the important features of Object-oriented Programming while using Classes
and Objects, two main aspects of the OOP paradigm.
5. Connecting to SQLite Database
Learn about relational databases while learning how to store and retrieve data from an
SQLite database through Python.
6. Developing a GUI with PyQT
Learn how to install PyQt5 toolkit, Qt Designer and create a graphical user interface using
common widgets and menu systems.
7. Application of Python in Various Disciplines
Learn about various resources to extend your learning for the Python programming
language.
Ⅰ.Variables:
One of the most powerful features of a programming language is the ability to manipulate
variables. A variable is a name that refers to a value
>>> pi = 3.1415926535897931
3
Ⅱ.Statements:
In general, statements are executed sequentially: The first statement in a function is executed
first, followed by the second, and so on. There may be a situation when you need to execute a
block of code several number of times.
• Programming languages provide various control structures that allow for more
complicated execution paths.
Operators are special symbols that represent computations like addition and multiplication.
The values the operator is applied to are called operands.
Example:-
20+32
hour-1
hour*60+minute
minute/60
5**2
(5+9)*(15-7)
EXPRESSIONS
4
An expression is a combination of values, variables, and operators. A value all by itself is
considered an expression
17
x + 17
COMMENTS
As programs get bigger and more complicated, they get more difficult to read. Formal
languages are dense, and it is often difficult to look at a piece of code and figure out what it is
doing, or why.
For this reason, it is a good idea to add notes to your programs to explain in natural language
what the program is doing. These notes are called comments, and in Python they start with the
# symbol
#This is a comment
print("Hello, World!")
BOOLEAN EXPRESSIONS
A Boolean Expression is an expression that is either true or false. The following examples use
the operator = =, which compares two operands and produces True if they are equal and False
otherwise
>>> 5
==5
True
5
>>> 5
==6
False
x != y
x>y
x<y
x >= y
x <= y
x is y
x is not y
# x is not equal to y
# x is greater than y
# x is less than y
# x is the same as y
CONDITIONAL EXECUTION
In order to write useful programs, we almost always need the ability to check conditions and
change the behavior of the program accordingly. Conditional statements give us this ability.
The simplest form is the if statement:
6
if x > 0 :
print('x is positive')
ALTERNATIVE EXECUTION
A second form of the if statement is alternative execution, in which there are two possibilities
and the condition determines which one gets executed. The syntax looks like this:
if x%2 == 0 :
print('x is even')
else :
print('x is odd’)
CHAINED CONDITIONALS
7
Sometimes there are more than two possibilities and we need more than two branches. One
way to express a computation like that is a chained conditional:
if x < y:
elif x > y:
else:
PYTHON LOOP
While loop
8
For loop
2. Executes a sequence of statements multiple times and abbreviates the code that
Nested loops
3.
You can use one or more loop inside any another while, for or do. while loop.
FUNCTIONS
A function is a block of code which only runs when it is called. You can pass data, known
as parameters, into a function. A function can return data as a result.
Creating a Function:
def my_function():
Calling a Function:
def my_function():
print(“function”)
my_function()
9
Sample of Rules
Batting
● 1 point for 2 runs scored
● Additional 5 points for half century
● Additional 10 points for 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 per 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 economy rate between 2 and 3.5
● 10 points for economy rate less than 2
Fielding
● 10 points each for catch/stumping/run out
DATABASE DESIGN
For the database, we are required to use three tables – match, stats and teams.
Match 1
Player Scored Faced Four Sixes Bowled Maiden Given Wkts Catches Stumping Run Out
Team
Name Player
Stats
Player Matches Runs 100s 50s Value Ctg
10
The data to enter in the remaining two tables is given below:
PROBLEM ANALYSIS
PRODUCT DEFINATION:-It is an game where you create a 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.
11
CODE
16
self.label_4.setFont(font)
self.horizontalLayout_2.setObjectName("horizont self.t3 =
alLayout_2") QtWidgets.QLineEdit(self.centralwidget)
self.label_2 = self.t3.setObjectName("t3")
QtWidgets.QLabel(self.centralwidget) self.horizontalLayout_2.addWidget(self.t3)
self.label_2.setObjectName("label_2") spacerItem3 = QtWidgets.QSpacerItem(40,
20, QtWidgets.QSizePolicy.Expanding,
self.horizontalLayout_2.addWidget(self.label_2) QtWidgets.QSizePolicy.Minimum)
self.label_2.setFont(font) self.horizontalLayout_2.addItem(spacerItem3)
self.t1 = self.label_5 =
QtWidgets.QLineEdit(self.centralwidget) QtWidgets.QLabel(self.centralwidget)
self.t1.setObjectName("t1") self.label_5.setObjectName("label_5")
self.horizontalLayout_2.addWidget(self.t1) self.horizontalLayout_2.addWidget(self.label_5)
spacerItem1 = QtWidgets.QSpacerItem(40, self.label_5.setFont(font)
20, QtWidgets.QSizePolicy.Expanding, self.t4 =
QtWidgets.QSizePolicy.Minimum) QtWidgets.QLineEdit(self.centralwidget)
self.horizontalLayout_2.addItem(spacerItem1) self.t4.setObjectName("t4")
self.label_3 = self.horizontalLayout_2.addWidget(self.t4)
QtWidgets.QLabel(self.centralwidget) self.verticalLayout.addLayout(self.horizontalLayo
self.label_3.setObjectName("label_3") ut_2)
self.horizontalLayout_3 =
self.horizontalLayout_2.addWidget(self.label_3) QtWidgets.QHBoxLayout()
self.label_3.setFont(font) self.horizontalLayout_3.setObjectName("horizont
self.t2 = alLayout_3")
QtWidgets.QLineEdit(self.centralwidget) self.label_7 =
self.t2.setObjectName("t2") QtWidgets.QLabel(self.centralwidget)
self.horizontalLayout_2.addWidget(self.t2) self.label_7.setObjectName("label_7")
spacerItem2 = QtWidgets.QSpacerItem(40, self.horizontalLayout_3.addWidget(self.label_7)
20, QtWidgets.QSizePolicy.Expanding, self.label_7.setFont(font)
QtWidgets.QSizePolicy.Minimum) self.t5 =
self.horizontalLayout_2.addItem(spacerItem2) QtWidgets.QLineEdit(self.centralwidget)
self.label_4 = self.t5.setObjectName("t5")
QtWidgets.QLabel(self.centralwidget) self.horizontalLayout_3.addWidget(self.t5)
self.label_4.setObjectName("label_4") spacerItem4 = QtWidgets.QSpacerItem(40,
20, QtWidgets.QSizePolicy.Expanding,
self.horizontalLayout_2.addWidget(self.label_4) QtWidgets.QSizePolicy.Minimum)
17
self.horizontalLayout_3.addItem(spacerItem4) self.rbtn4 =
self.label_6 = QtWidgets.QRadioButton(self.centralwidget)
QtWidgets.QLabel(self.centralwidget) self.rbtn4.setObjectName("rbtn4")
self.label_6.setObjectName("label_6") self.horizontalLayout_4.addWidget(self.rbtn4)
self.horizontalLayout_3.addWidget(self.label_6) self.rbtn4.setFont(font)
self.label_6.setFont(font) spacerItem5 = QtWidgets.QSpacerItem(40,
self.t6 = 20, QtWidgets.QSizePolicy.Expanding,
QtWidgets.QLineEdit(self.centralwidget) QtWidgets.QSizePolicy.Minimum)
self.t6.setObjectName("t6") self.horizontalLayout_4.addItem(spacerItem5)
self.horizontalLayout_3.addWidget(self.t6) spacerItem6 = QtWidgets.QSpacerItem(40,
20, QtWidgets.QSizePolicy.Expanding,
self.verticalLayout.addLayout(self.horizontalLayo QtWidgets.QSizePolicy.Minimum)
ut_3) self.horizontalLayout_4.addItem(spacerItem6)
self.horizontalLayout_4 = self.label_8 =
QtWidgets.QHBoxLayout() QtWidgets.QLabel(self.centralwidget)
self.horizontalLayout_4.setObjectName("horizont self.label_8.setObjectName("label_8")
alLayout_4") self.horizontalLayout_4.addWidget(self.label_8)
self.rbtn1 = font = QtGui.QFont()
QtWidgets.QRadioButton(self.centralwidget) font.setFamily("Courier New")
self.rbtn1.setObjectName("rbtn1") font.setBold(True)
self.horizontalLayout_4.addWidget(self.rbtn1) font.setPointSize(12)
font = QtGui.QFont() self.label_8.setFont(font)
font.setFamily("Gill Sans MT") self.t7 =
font.setBold(True) QtWidgets.QLineEdit(self.centralwidget)
font.setPointSize(10) self.t7.setObjectName("t7")
self.rbtn1.setFont(font) self.horizontalLayout_4.addWidget(self.t7)
self.rbtn2 = self.verticalLayout.addLayout(self.horizontalLayo
QtWidgets.QRadioButton(self.centralwidget) ut_4)
self.rbtn2.setObjectName("rbtn2") self.horizontalLayout_5 =
self.rbtn2.setFont(font) QtWidgets.QHBoxLayout()
self.horizontalLayout_4.addWidget(self.rbtn2) self.horizontalLayout_5.setObjectName("horizont
self.rbtn3 = alLayout_5")
QtWidgets.QRadioButton(self.centralwidget) self.list1 =
self.rbtn3.setObjectName("rbtn3") QtWidgets.QListWidget(self.centralwidget)
self.rbtn3.setFont(font) self.list1.setObjectName("list1")
self.horizontalLayout_4.addWidget(self.rbtn3) self.horizontalLayout_5.addWidget(self.list1)
18
font = QtGui.QFont() self.horizontalLayout_6.addWidget(self.pushButt
font.setFamily("Tahoma") on)
font.setPointSize(10) font = QtGui.QFont()
font.setBold(True) font.setFamily("Courier New")
font.setWeight(75) font.setBold(True)
self.list1.setFont(font) font.setPointSize(12)
self.t1.setFont(font) self.pushButton.setFont(font)
self.t2.setFont(font) spacerItem9 = QtWidgets.QSpacerItem(40,
self.t3.setFont(font) 20, QtWidgets.QSizePolicy.Expanding,
self.t4.setFont(font) QtWidgets.QSizePolicy.Minimum)
self.t5.setFont(font) self.horizontalLayout_6.addItem(spacerItem9)
self.t6.setFont(font) self.verticalLayout.addLayout(self.horizontalLayo
self.t7.setFont(font) ut_6)
spacerItem7 = QtWidgets.QSpacerItem(40, MainWindow.setCentralWidget(self.centralwidget
20, QtWidgets.QSizePolicy.Expanding, )
QtWidgets.QSizePolicy.Minimum) self.menubar =
self.horizontalLayout_5.addItem(spacerItem7) QtWidgets.QMenuBar(MainWindow)
self.list2 = self.menubar.setGeometry(QtCore.QRect(0,
QtWidgets.QListWidget(self.centralwidget) 0, 800, 26))
self.list2.setObjectName("list2") self.menubar.setObjectName("menubar")
self.horizontalLayout_5.addWidget(self.list2) self.menuManage_Teams =
self.list2.setFont(font) QtWidgets.QMenu(self.menubar)
self.verticalLayout.addLayout(self.horizontalLayo self.menuManage_Teams.setObjectName("menu
ut_5) Manage_Teams")
self.horizontalLayout_6 = font = QtGui.QFont()
QtWidgets.QHBoxLayout() font.setFamily("Gill Sans MT")
self.horizontalLayout_6.setObjectName("horizont font.setBold(True)
alLayout_6") font.setPointSize(10)
spacerItem8 = QtWidgets.QSpacerItem(40, self.menuManage_Teams.setFont(font)
20, QtWidgets.QSizePolicy.Expanding, self.menubar.setFont(font)
QtWidgets.QSizePolicy.Minimum) MainWindow.setMenuBar(self.menubar)
self.horizontalLayout_6.addItem(spacerItem8) self.statusbar =
self.pushButton = QtWidgets.QStatusBar(MainWindow)
QtWidgets.QPushButton(self.centralwidget) self.statusbar.setObjectName("statusbar")
self.pushButton.setObjectName("pushButton") MainWindow.setStatusBar(self.statusbar)
19
self.actionNEW_Team = self.rbtn2.toggled.connect(self.ctg)
QtWidgets.QAction(MainWindow) self.rbtn3.toggled.connect(self.ctg)
self.actionNEW_Team.setObjectName("actionNE self.rbtn4.toggled.connect(self.ctg)
W_Team") self.menuManage_Teams.triggered[QtWidgets.Q
self.actionOPEN_Team = Action].connect(self.menu)
QtWidgets.QAction(MainWindow) self.pushButton.clicked.connect(self.exit)
self.actionOPEN_Team.setObjectName("actionO self.bat=0
PEN_Team") self.bwl=0
self.actionSAVE_Team = self.ar=0
QtWidgets.QAction(MainWindow) self.wk=0
self.actionSAVE_Team.setObjectName("actionS self.avl=1000
AVE_Team") self.used=0
self.actionEVALUATE_Team = self.retranslateUi(MainWindow)
QtWidgets.QAction(MainWindow) QtCore.QMetaObject.connectSlotsByName(Main
self.actionEVALUATE_Team.setObjectName("ac Window)
tionEVALUATE_Team") def retranslateUi(self, MainWindow):
self.menuManage_Teams.addAction(self.actionN _translate =
EW_Team) QtCore.QCoreApplication.translate
self.menuManage_Teams.addSeparator() MainWindow.setWindowTitle(_translate("MainW
self.menuManage_Teams.addAction(self.actionO indow", "MainWindow"))
PEN_Team) self.label.setText(_translate("MainWindow",
self.menuManage_Teams.addSeparator() "Your Selections"))
self.menuManage_Teams.addAction(self.actionS self.label_2.setText(_translate("MainWindow",
AVE_Team) "Batsmen (BAT)"))
self.menuManage_Teams.addSeparator() self.label_3.setText(_translate("MainWindow",
self.menuManage_Teams.addAction(self.actionE "Bowler (BOW)"))
VALUATE_Team) self.label_4.setText(_translate("MainWindow",
self.menuManage_Teams.addSeparator() "Wicketkeeper (WK)"))
self.label_5.setText(_translate("MainWindow",
self.menubar.addAction(self.menuManage_Teams "All-Rounders (AR)"))
.menuAction()) self.label_7.setText(_translate("MainWindow",
self.list1.itemDoubleClicked.connect(self.removel "Points Available"))
ist1) self.label_6.setText(_translate("MainWindow",
self.list2.itemDoubleClicked.connect(self.removel "Points Used"))
ist2) self.rbtn1.setText(_translate("MainWindow",
self.rbtn1.toggled.connect(self.ctg) "BAT"))
20
self.rbtn2.setText(_translate("MainWindow", #self.t7.setText("???")
"BOW")) #self.dial()
self.rbtn3.setText(_translate("MainWindow", text,
"AR")) ok=QtWidgets.QInputDialog.getText(MainWindo
self.rbtn4.setText(_translate("MainWindow", w, "Team", "Enter name of team:")
"WK")) if ok:
self.label_8.setText(_translate("MainWindow", self.t7.setText(str(text))
"Team Name")) self.show()
self.pushButton.setText(_translate("MainWindow if txt=='SAVE Team':
", "EXIT Application")) count=self.list2.count()
self.menuManage_Teams.setTitle(_translate("Mai selected=""
nWindow", "Manage Teams")) for i in range(count):
self.actionNEW_Team.setText(_translate("Main selected+=self.list2.item(i).text()
Window", "NEW Team")) if i<count:
self.actionOPEN_Team.setText(_translate("Main selected+=","
Window", "OPEN Team")) self.saveteam(self.t7.text(),selected,self.used)
self.actionSAVE_Team.setText(_translate("Main if txt=='OPEN Team':
Window", "SAVE Team")) self.bat=0
self.actionEVALUATE_Team.setText(_translate( self.bwl=0
"MainWindow", "EVALUATE Team")) self.ar=0
def exit(self): self.wk=0
import sys self.avl=1000
self.showdlg("Thank YOU for self.used=0
Visiting....Hope you enjoyed !!") self.list1.clear()
sys.exit() self.list2.clear()
def menu(self,action): self.show()
txt=(action.text()) #print("rgr")
if txt=='NEW Team': self.openteam()
self.bat=0 if txt=='EVALUATE Team':
self.bwl=0 from dlgscore import Ui_Dialog
self.ar=0 Dialog = QtWidgets.QDialog()
self.wk=0 ui = Ui_Dialog()
self.avl=1000 ui.setupUi(Dialog)
self.used=0 #print("effieh")
self.list1.clear() ret=Dialog.exec()
self.list2.clear() def show(self):
21
#print("vvrv") self.avl-=int(row[0])
self.t1.setText(str(self.bat)) self.used+=int(row[0])
self.t2.setText(str(self.bwl)) return True
self.t3.setText(str(self.wk)) def removelist1(self,item):
self.t4.setText(str(self.ar)) ctgr=''
#print("rrrr") if self.rbtn1.isChecked()==True:ctgr='BAT'
self.t5.setText(str(self.avl)) if self.rbtn2.isChecked()==True:ctgr='BWL'
self.t6.setText(str(self.used)) if self.rbtn3.isChecked()==True:ctgr='AR'
#print("efef") if self.rbtn4.isChecked()==True:ctgr='WK'
def criteria(self,ctgr,item): ret=self.criteria(ctgr,item)
msg='' if ret==True:
if ctgr=="BAT" and self.list1.takeItem(self.list1.row(item))
self.bat>=5:msg="Batsmen not more than 5" self.list2.addItem(item.text())
if ctgr=="BWL" and self.show()
self.bwl>=5:msg="bowlers not more than 5" def ctg(self):
if ctgr=="AR" and ctgr=''
self.ar>=3:msg="Allrounders not more than 3" if self.rbtn1.isChecked()==True:ctgr='BAT'
if ctgr=="WK" and if self.rbtn2.isChecked()==True:ctgr='BWL'
self.wk>=1:msg="Wicketkeepers not more than if self.rbtn3.isChecked()==True:ctgr='AR'
1" if self.rbtn4.isChecked()==True:ctgr='WK'
if msg!='':
#msg="You Have Exhausted your Points" self.fillList(ctgr)
self.showdlg(msg)
return False
if self.avl<=0: def removelist2(self,item):
msg="You Have Exhausted your Points" self.list2.takeItem(self.list2.row(item))
self.showdlg(msg)
return False cursor = conn.execute("SELECT
if ctgr=="BAT":self.bat+=1 player,value, ctg from stats where
if ctgr=="BWL":self.bwl+=1 player='"+item.text()+"'")
if ctgr=="AR":self.ar+=1 row=cursor.fetchone()
if ctgr=="WK":self.wk+=1 self.avl=self.avl+int(row[1])
sql="SELECT value from stats where self.used=self.used-int(row[1])
player='"+item.text()+"'" ctgr=row[2]
cur=conn.execute(sql) if ctgr=="BAT":
row=cur.fetchone() self.bat-=1
22
if #mycon = sqlite3.connect('fantasy.db')
self.rbtn1.isChecked()==True:self.list1.addItem(it #mycur=mycon.cursor()
em.text()) sql="select name from teams;"
if ctgr=="BWL": #print("efef")
self.bwl-=1 cur=conn.execute(sql)
if #print("vebjb")
self.rbtn2.isChecked()==True:self.list1.addItem(it teams=[]
em.text()) #print("rrr")
if ctgr=="AR": #cur=mycur.fetchall()
self.ar-=1 for row in cur:
if teams.append(row[0])
self.rbtn3.isChecked()==True:self.list1.addItem(it team,
em.text()) ok=QtWidgets.QInputDialog.getItem(MainWindo
if ctgr=="WK": w,"Dream","Choose A Team",teams,0,False)
self.wk-=1 if ok and team:
if self.t7.setText(team)
self.rbtn4.isChecked()==True:self.list1.addItem(it
em.text()) sql1="SELECT players,value from teams
self.show() where name='"+team+"';"
def fillList(self,ctgr): cur=conn.execute(sql1)
if self.t7.text()=='': row=cur.fetchone()
self.showdlg("Enter name of team") #print("ooo")
return selected=row[0].split(',')
self.list1.clear() #print(selected)
sql="SELECT player from players where self.list2.addItems(selected)
ctg='"+ctgr+"';" self.used=row[1]
cur=conn.execute(sql) self.avl=1000-row[1]
for row in cur: count=self.list2.count()
selected=[] ##iterate to count no. of specific players
for i in range(self.list2.count()): for i in range(count-1):
selected.append(self.list2.item(i).text()) ply=self.list2.item(i).text()
if row[0] not in #print(ply)
selected:self.list1.addItem(row[0]) sql="select ctg from stats where
def openteam(self): player='"+ply+"';"
#print("rvrjbv") cur=conn.execute(sql)
#import sqlite3 row=cur.fetchone()
23
#print(row) #print("dehe")
ctgr=row[0] self.showdlg("Team Saved Succesfully")
#print("ej") conn.commit()
if ctgr=="BAT":self.bat+=1 except:
if ctgr=="BWL":self.bwl+=1 self.showdlg("Error in Operation")
if ctgr=="AR":self.ar+=1 conn.rollback()
if ctgr=="WK":self.wk+=1 def showdlg(self,msg):
#print("vdkn") #print("ecb")
self.show() Dialog=QtWidgets.QMessageBox()
#print("fece") Dialog.setText(msg)
def saveteam(self,nm,ply,val): Dialog.setWindowTitle("Dream Team
#print("rvrv") selector")
ret=Dialog.exec()
if self.bat+self.bwl+self.ar+self.wk!=11: if __name__ == "__main__":
self.showdlg("Insufficient players") import sqlite3
return conn = sqlite3.connect('fantasy.db')
#print("frbfj") import sys
sql="INSERT INTO teams app = QtWidgets.QApplication(sys.argv)
(name,players,value) VALUES MainWindow = QtWidgets.QMainWindow()
('"+nm+"','"+ply+"','"+str(val)+"');" ui = Ui_MainWindow()
#print("f3f4") ui.setupUi(MainWindow)
try: MainWindow.show()
#print("bjr") sys.exit(app.exec_())
cur=conn.execute(sql)
24
BIBLIOGRAPHY
• https://trainings.internshala.com/python-training
• https://www.w3schools.com/python/
• https://wiki.python.org/moin/PyQt/Tutorials
• https://www.quora.com
• https://python.org
25