0% found this document useful (0 votes)
21 views31 pages

21bec001-internship-pdf

Uploaded by

Nayan Slathia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views31 pages

21bec001-internship-pdf

Uploaded by

Nayan Slathia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Programming with Python

An Internship Report

Submitted to
Dr. Vijay Kumar Sharma
Faculty of Engineering

in fulfilment of the requirements for the award of the degree of


Bachelors in Technology
in
School of Electronics & Communication Engineering

Submitted by
AARSH SAXENA
(21BEC001)

SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING


SHRI MATA VAISHNO DEVI UNIVERSITY
KATRA-182320, JAMMU AND KASHMIR (INDIA)
December 05, 2022
SHRI MATA VAISHNO DEVI UNIVERSITY
SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING

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.

Student’s Name and Signature

ii
SHRI MATA VAISHNO DEVI UNIVERSITY
SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING

COPY OF CERTIFICATE

Signature of the student

Name of the student

School of Electronics & Communication Engineering


Shri Mata Vaishno Devi University, Katra- 182320, Jammu & Kashmir (India)

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

Python Language Introduction


Python is a widely used general-purpose, high level programming language. It was initially
designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was
mainly developed for emphasis on code readability, and its syntax allows programmers to
express concepts in fewer lines of code. Python is a programming language that lets you work
quickly and integrate systems more efficiently.
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python
is designed to be highly readable. It uses English keywords frequently where as other languages
use punctuation, and it has fewer syntactical constructions than other languages.

• Python is Interpreted − Python is processed at runtime by the interpreter. You do not


need to compile your program before executing it. This is similar to PERL and PHP.
• Python is Interactive − You can actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
• Python is Object-Oriented − Python supports Object-Oriented style or technique of
programming that encapsulates code within objects.
• Python is a Beginner's Language − Python is a great language for the beginner-level
programmers and supports the development of a wide range of applications from simple
text processing to WWW browsers to games.

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, EXPRESSIONS AND STATEMENTS

Ⅰ.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.

• A loop statement allows us to execute a statement or group of statements multiple


times.

OPERATORS AND OPERANDS

Operators are special symbols that represent computations like addition and multiplication.
The values the operator is applied to are called operands.

The operators +, -, *, /, and ** perform addition, subtraction, multiplication, division, and


exponentiation

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

(assuming that the variable x has been assigned a value)

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

The others are:

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 greater than or equal to y

# x is less than or equal to y

# x is the same as y

# x is not 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:

print('x is less than y')

elif x > y:

print('x is greater than y')

else:

print('x and y are equal')

PYTHON LOOP

Sr.No. Loop Type & Description

While loop

1. Repeats a statement or group of statements while a given condition is TRUE. It

tests the condition before executing the loop body.

8
For loop

2. Executes a sequence of statements multiple times and abbreviates the code that

manages the loop variable.

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:

In Python a function is defined using the def keyword:

def my_function():

print("Hello from a function")

Calling a Function:

To call a function, use the function name followed by parenthesis:

def my_function():

print(“function”)

my_function()

PROFILE OF THE PROBLEM


Create a Fantasy Cricket game in Python. The game should have all the features displayed in
the mock-up screens in the scenario. To calculate the points for each player, we can use
rules similar to the sample rules displayed below.

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.

FEASIBILITY ANALYSIS:- I am building an software for gaming purposes using an


specific technology named python. It is a game software where you can create virtual team
according to your choice and score points to win an tournament.
This software is created for motivating street cricket and adding more fun and entertainment
to cricket. The components that are used in this demo can be integrated to a high extent to
provide statics to different components of cricket. This project helps in providing real time on
field actions there by helping its user of the current actions happening on field.

11
CODE

# -*- coding: utf-8 -*- font.setPointSize(10)


# Form implementation generated from reading ui self.cb0.setFont(font)
file 'dlgscore.ui' self.cb0.setObjectName("cb0")
# Created by: PyQt5 UI code generator 5.9 import sqlite3
# WARNING! All changes made in this file will conn = sqlite3.connect('fantasy.db')
be lost! self.horizontalLayout.addWidget(self.cb0)
from PyQt5 import QtCore, QtGui, QtWidgets sql="select name from teams"
class Ui_Dialog(object): cur=conn.execute(sql)
def setupUi(self, Dialog): teams=[]
Dialog.setObjectName("Dialog") for row in cur:
Dialog.resize(500, 400) self.cb0.addItem(row[0])
self.verticalLayout = conn.close()
QtWidgets.QVBoxLayout(Dialog) self.label = QtWidgets.QLabel(Dialog)
self.verticalLayout.setContentsMargins(25, - font = QtGui.QFont()
1, 25, -1) font = QtGui.QFont()
self.verticalLayout.setObjectName("verticalLayou font.setFamily("Gill Sans MT")
t") font.setBold(True)
self.horizontalLayout = font.setPointSize(12)
QtWidgets.QHBoxLayout() self.label.setFont(font)
self.horizontalLayout.setObjectName("horizontal self.label.setObjectName("label")
Layout") self.horizontalLayout.addWidget(self.label)
self.label_2 = QtWidgets.QLabel(Dialog) self.cb1 = QtWidgets.QComboBox(Dialog)
font = QtGui.QFont() font = QtGui.QFont()
font.setFamily("Gill Sans MT") font.setFamily("Eras Demi ITC")
font.setBold(True) font.setPointSize(10)
font.setPointSize(12) self.cb1.setFont(font)
self.label_2.setFont(font) self.cb1.setObjectName("cb1")
self.label_2.setObjectName("label_2") self.cb1.addItem("")
self.horizontalLayout.addWidget(self.label_2) self.cb1.addItem("")
self.cb0 = QtWidgets.QComboBox(Dialog) self.cb1.addItem("")
font = QtGui.QFont() self.cb1.addItem("")
font.setFamily("Eras Demi ITC") self.cb1.addItem("")
12
self.horizontalLayout.addWidget(self.cb1) self.label_4.setFont(font)
self.verticalLayout.addLayout(self.horizontalLayo
ut) self.label_4.setAlignment(QtCore.Qt.AlignCenter
self.line = QtWidgets.QFrame(Dialog) )
font = QtGui.QFont() self.label_4.setObjectName("label_4")
font.setFamily("Gill Sans MT") self.horizontalLayout_4.addWidget(self.label_4)
font.setBold(True) self.verticalLayout.addLayout(self.horizontalLayo
font.setPointSize(12) ut_4)
self.line.setFont(font) self.line_2 = QtWidgets.QFrame(Dialog)
self.line.setFrameShape(QtWidgets.QFrame.HLin font = QtGui.QFont()
e) font.setFamily("Gill Sans MT")
self.line.setFrameShadow(QtWidgets.QFrame.Su font.setBold(True)
nken) font.setPointSize(12)
self.line.setObjectName("line") self.line_2.setFont(font)
self.verticalLayout.addWidget(self.line) self.line_2.setFrameShape(QtWidgets.QFrame.H
self.horizontalLayout_4 = Line)
QtWidgets.QHBoxLayout() self.line_2.setFrameShadow(QtWidgets.QFrame.
self.horizontalLayout_4.setObjectName("horizont Sunken)
alLayout_4") self.line_2.setObjectName("line_2")
self.label_5 = QtWidgets.QLabel(Dialog) self.verticalLayout.addWidget(self.line_2)
font = QtGui.QFont() self.horizontalLayout_2 =
font.setFamily("Gill Sans MT") QtWidgets.QHBoxLayout()
font.setBold(True) self.horizontalLayout_2.setObjectName("horizont
font.setPointSize(12) alLayout_2")
font.setWeight(75) self.lw1 = QtWidgets.QListWidget(Dialog)
self.label_5.setFont(font) font = QtGui.QFont()
self.label_5.setAlignment(QtCore.Qt.AlignCenter font.setFamily("Tahoma")
) font.setPointSize(10)
self.label_5.setObjectName("label_5") font.setBold(True)
self.horizontalLayout_4.addWidget(self.label_5) font.setWeight(75)
self.label_4 = QtWidgets.QLabel(Dialog) self.lw1.setFont(font)
font = QtGui.QFont() self.lw1.setObjectName("lw1")
font.setFamily("Gill Sans MT") self.horizontalLayout_2.addWidget(self.lw1)
font.setBold(True) spacerItem = QtWidgets.QSpacerItem(200,
font.setPointSize(12) 20, QtWidgets.QSizePolicy.Expanding,
font.setWeight(75) QtWidgets.QSizePolicy.Minimum)
13
self.horizontalLayout_2.addItem(spacerItem)
self.lw2 = QtWidgets.QListWidget(Dialog) self.pushButton.clicked.connect(self.calculate)
font = QtGui.QFont() self.horizontalLayout_3.addWidget(self.pushButt
font.setFamily("Tahoma") on)
font.setPointSize(10) spacerItem1 = QtWidgets.QSpacerItem(150,
font.setBold(True) 20, QtWidgets.QSizePolicy.Fixed,
font.setWeight(75) QtWidgets.QSizePolicy.Minimum)
self.lw2.setFont(font) self.horizontalLayout_3.addItem(spacerItem1)
self.lw2.setObjectName("lw2") #self.scorelabel = QtWidgets.QLabel(Dialog)
self.horizontalLayout_2.addWidget(self.lw2) self.scoreline =
self.verticalLayout.addLayout(self.horizontalLayo QtWidgets.QLineEdit(Dialog)
ut_2) font = QtGui.QFont()
self.line_3 = QtWidgets.QFrame(Dialog) font.setFamily("Gill Sans MT")
font = QtGui.QFont() font.setBold(True)
font.setFamily("Gill Sans MT") font.setPointSize(12)
font.setBold(True) font.setWeight(75)
font.setPointSize(12) #self.scorelabel.setFont(font)
self.line_3.setFont(font) self.scoreline.setFont(font)
self.line_3.setFrameShape(QtWidgets.QFrame.H #self.scorelabel.setObjectName("scorelabel")
Line) self.scoreline.setObjectName("scoreline")
self.line_3.setFrameShadow(QtWidgets.QFrame.
Sunken) #self.horizontalLayout_3.addWidget(self.scorelab
self.line_3.setObjectName("line_3") el)
self.verticalLayout.addWidget(self.line_3)
self.horizontalLayout_3 = self.horizontalLayout_3.addWidget(self.scoreline)
QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizont
alLayout_3")
self.pushButton = self.verticalLayout.addLayout(self.horizontalLayo
QtWidgets.QPushButton(Dialog) ut_3)
font = QtGui.QFont()
font.setFamily("Gill Sans MT") self.retranslateUi(Dialog)
font.setBold(True)
font.setPointSize(12) QtCore.QMetaObject.connectSlotsByName(Dialo
self.pushButton.setFont(font) g)
self.pushButton.setObjectName("pushButton") def calculate(self):
14
import sqlite3 if row[8]>=5:
conn = sqlite3.connect('fantasy.db') bowlscore=bowlscore=bowlscore+10
team=self.cb0.currentText() if row[7]>0:
self.lw1.clear() er=6*row[7]/row[5]
sql1="select players, value from teams where #print ("eco:")
name='"+team+"'" if er<=2: bowlscore=bowlscore+10
cur=conn.execute(sql1) if er>2 and er<=3.5:
row=cur.fetchone() bowlscore=bowlscore+7
#print (row[0]) if er>3.5 and er<=4.5:
selected=row[0].split(',') bowlscore=bowlscore+4
#print (selected) fieldscore=(row[9]+row[10]+row[11])*10
self.lw1.addItems(selected) ttl=batscore+bowlscore+fieldscore
teamttl=0 #print("frfm")
#print("ded") self.lw2.addItem(str(ttl))
self.lw2.clear() #print("rb")
match=self.cb1.currentText() teamttl=teamttl+ttl
for i in range(self.lw1.count()): #int(teamttl)
ttl, batscore, bowlscore, fieldscore=0,0,0,0
nm=self.lw1.item(i).text() #self.scorelabel.setText(str(teamttl))
cursor=conn.execute("select * from #print("gt")
"+match+" where player='"+nm+"'") self.scoreline.setText(str(teamttl))
row=cursor.fetchone() #print("du")
#print ("fekn") def retranslateUi(self, Dialog):
#print(row) _translate =
batscore=int(row[1]/2) QtCore.QCoreApplication.translate
if batscore>=50: batscore+=5 Dialog.setWindowTitle(_translate("Dialog",
if batscore>=100: batscore+=10 "Dialog"))
if row[1]>0: self.label_2.setText(_translate("Dialog",
sr=row[1]/row[2] "Choose Team"))
if sr>=80 and sr<100: batscore+=2 self.label.setText(_translate("Dialog",
if sr>=100:batscore+=4 "Choose Match"))
batscore=batscore+row[3] self.cb1.setItemText(0, _translate("Dialog",
batscore=batscore+2*row[4] "Match1"))
#print ("batting score=", batscore) self.cb1.setItemText(1, _translate("Dialog",
bowlscore=row[8]*10 "Match2"))
if row[8]>=3: bowlscore=bowlscore+5
15
self.cb1.setItemText(2, _translate("Dialog", #from PyQt5.QtWidgets import QApplication,
"Match3")) QWidget, QInputDialog, QLineEdit
self.cb1.setItemText(3, _translate("Dialog", class Ui_MainWindow(object):
"Match4")) def setupUi(self, MainWindow):
self.cb1.setItemText(4, _translate("Dialog", MainWindow.setObjectName("MainWindow")
"Match5")) MainWindow.resize(800, 649)
self.label_5.setText(_translate("Dialog", self.centralwidget =
"Players")) QtWidgets.QWidget(MainWindow)
self.label_4.setText(_translate("Dialog", self.centralwidget.setObjectName("centralwidget"
"Score")) )
self.pushButton.setText(_translate("Dialog", self.verticalLayout =
"Calculate Score")) QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayou
#self.scorelabel.setText(_translate("Dialog", t")
"00")) self.horizontalLayout =
self.scoreline.setText(_translate("Dialog", QtWidgets.QHBoxLayout()
"00")) self.horizontalLayout.setObjectName("horizontal
Layout")
self.label =
if __name__ == "__main__": QtWidgets.QLabel(self.centralwidget)
import sys self.label.setObjectName("label")
app = QtWidgets.QApplication(sys.argv) font = QtGui.QFont()
Dialog = QtWidgets.QDialog() font.setFamily("Courier New")
ui = Ui_Dialog() font.setBold(True)
ui.setupUi(Dialog) font.setPointSize(12)
Dialog.show() self.label.setFont(font)
sys.exit(app.exec_()) self.horizontalLayout.addWidget(self.label)
----------------------------------------------- spacerItem = QtWidgets.QSpacerItem(40,
# -*- coding: utf-8 -*- 20, QtWidgets.QSizePolicy.Expanding,
# Form implementation generated from reading ui QtWidgets.QSizePolicy.Minimum)
file 'fantasy_cricket.ui' self.horizontalLayout.addItem(spacerItem)
# Created by: PyQt5 UI code generator 5.10.1 self.verticalLayout.addLayout(self.horizontalLayo
# WARNING! All changes made in this file will ut)
be lost! self.horizontalLayout_2 =
from PyQt5 import QtCore, QtGui, QtWidgets QtWidgets.QHBoxLayout()

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

You might also like