Code2pdf 6714bd5247d05
Code2pdf 6714bd5247d05
connector as c
import csv
pwd=input("Enter MySQL Password:")
con = c.connect(host="localhost", user="root", password=pwd)#please use your own password#establishing connection with mysql
cursor = con.cursor()
cursor.execute("create database if not exists cricket")#Creating database
cursor.execute("use cricket")#using the database
"""creating the tables"""
cursor.execute("create table if not exists Bat1(name varchar(50),runs int,balls_faced int,strike_rate float)")
cursor.execute("create table if not exists Bat2(name varchar(50),runs int,balls_faced int,strike_rate float)")
cursor.execute("create table if not exists Bowl1(name varchar(50),runs_conceded int,wickets int,overs float,economy float)")
cursor.execute("create table if not exists Bowl2(name varchar(50),runs_conceded int,wickets int,overs float,economy float)")
"""Deleting the data from the database"""
cursor.execute("delete from bat1")
con.commit()
cursor.execute("delete from bat2")
con.commit()
cursor.execute("delete from bowl1")
con.commit()
cursor.execute("delete from bowl2")
con.commit()
fields=["Name","Runs","Balls","Strike_Rate","Runs_conceded","Wickets","Overs","Economy"]
f1=open("Team1.csv",'w')
f2=open("Team2.csv",'w')
f1csv=csv.writer(f1,lineterminator='\n')
f2csv=csv.writer(f2,lineterminator='\n')
f1csv.writerow(fields)
f2csv.writerow(fields)
t1,t1csv,t2,t2csv = [],[],[],[]
w1, w2, tot1, tot2, f, rc1, rc2, oversb1, oversb2, sr1, sr2, eco1, eco2,ch = 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,"yes"
print("-"*50)
print("CRICKET SCORE MANAGEMENT SYSTEM")
print("-"*50)
overs = int(input("Enter the number of overs of the match"))
d1, d2 = {}, {}
team1 = input("Enter name of team 1")
team2 = input("Enter name of team 2")
print("-"*40)
print("ACCEPTING DATA FOR TEAM 1")
print("-"*40)
for i in range(11):
name1 = input("Enter name of the player for the first team")
runs1 = int(input("Enter runs scored by the player"))
if runs1 < 0:
f = 1
balls1 = int(input("Enter balls faced by the player"))
if balls1 < 0:
f = 1
if balls1 == 0 and runs1 > 0:
f = 1
if (balls1 / 6) > overs:
f = 1
overs1 = float(input("Enter overs bowled by the bowler"))
if overs1 < 0:
f = 1
runsg1 = int(input("Enter runs conceded by the player"))
wickets1 = int(input("Enter wickets taken by the player"))
if wickets1 < 0:
f = 1
if overs1 == 0.0 and wickets1 > 0:
f = 1
if runsg1 < 0:
f = 1
if overs1 == 0.0 and runsg1 > 0:
f = 1
if overs1 > overs:
f = 1
if balls1 > 0:
sr1 = (runs1 / balls1) * 100
if balls1 == 0:
sr1 = 0.0
if overs1 > 0.0:
eco1 = runsg1 / overs1
if overs1 == 0.0:
eco1 = 0.0
"""inserting the data in the tables"""
cursor.execute("insert into Bat1(name,runs,balls_faced,strike_rate)values('{}',{},{},{})". format(name1,runs1,balls1,sr1))
con.commit()
cursor.execute("insert into Bowl1(name,runs_conceded,wickets,overs,economy)values('{}',{},{},{},{})".format(name1,runsg1,wickets1,overs1,eco1))
con.commit()
"""inserting the data in the dictionary"""
d1['Name'] = name1
d1['Runs'] = runs1
d1['Balls faced'] = balls1
d1['Strike Rate'] = sr1
d1['Overs'] = overs1
d1['wickets'] = wickets1
d1['runs conceded'] = runsg1
d1['economy'] = eco1
t1.append(d1)
rc1 = rc1 + runsg1#calculating the total number of runs conceded
oversb1 = oversb1 + overs1#calculating the total number of overs bowled
d1 = {}
w2 = w2 + wickets1#calculating the number of wickets
tot1 = tot1 + runs1#calculating the total number of runs scored
if runs1 > (balls1 * 6):
f = 1
if wickets1 > (overs1 * 6):
f = 1
t1csv.extend([name1,runs1,balls1,sr1,runsg1,wickets1,overs1,eco1])
f1csv.writerow(t1csv)
t1csv=[]
print("Accepting data for team1")
e1 = int(input("Enter extras for team1"))
r1 = int(input("Enter wickets lost due to runouts"))
w1 = w1 + r1#calculating the number of wickets
tot1 = tot1 + e1#calculating the total number of runs scored
if w2 > 10:
f = 1
print("-"*40)
print("ACCEPTING DATA FOR TEAM 2")
print("-"*40)
for i in range(11):
name2 = input("Enter name of the player for the second team")
runs2 = int(input("Enter runs scored by the player"))
if runs2 < 0:
f = 1
balls2 = int(input("Enter balls faced by the player"))
if balls2 < 0:
f = 1
if (balls2 / 6) > overs:
f = 1
if balls2 == 0 and runs2 > 0:
f = 1
overs2 = float(input("Enter overs bowled by the bowler"))
if overs2 < 0:
f = 1
runsg2 = int(input("Enter runs conceded by the player"))
wickets2 = int(input("Enter wickets taken by the player"))
if wickets2 < 0:
f = 1
if runsg2 < 0:
f = 1
if overs2 == 0.0 and (wickets2 > 0 or runsg2 > 0):
f = 1
if overs2 > overs:
f = 1
if balls2 != 0:
sr2 = (runs2 / balls2) * 100
if balls2 == 0:
sr2 = 0.0
if overs2 != 0:
eco2 = runsg2 / overs2
if overs2 == 0:
eco2 = 0.0
"""inserting the data in the tables"""
cursor.execute("insert into Bat2(name,runs,balls_faced,strike_rate)values('{}',{},{},{})". format(name2,runs2,balls2,sr2))
con.commit()
cursor.execute("insert into Bowl2(name,runs_conceded,wickets,overs,economy)values('{}',{},{},{},{})".format(name2,runsg2,wickets2,overs2,eco2))
con.commit()
"""inserting the data in the dictionary"""
d2['Name'] = name2
d2['Runs'] = runs2
d2['Balls faced'] = balls2
d2['Strike Rate'] = sr2
d2['Overs'] = overs2
d2['wickets'] = wickets2
d2['runs conceded'] = runsg2
d2['economy'] = eco2
t2.append(d2)
oversb2 = oversb2 + overs2#calculating the total number of overs bowled
rc2 = rc2 + runsg2#calculating the total number of runs conceded
d2 = {}
w1 = w1 + wickets2#calculating the number of wickets
tot2 = tot2 + runs2#calculating the total number of runs scored
if runs2 > (balls2 * 6):
f = 1
if wickets2 > (overs2 * 6):
f = 1
t2csv.extend([name2,runs2,balls2,sr2,runsg2,wickets2,overs2,eco2])
f2csv.writerow(t2csv)
t2csv=[]
print("Entering data for team2")
e2 = int(input("Enter extras for team2"))
r2 = int(input("Enter wickets lost due to runouts"))
w2 = w2 + r2#calculating the number of wickets
tot2 = tot2 + e2#calculating the total number of runs scored
if w1 > 10:
f = 1
if rc1 > tot2:
f = 1
if rc2 > tot1:
f = 1
if oversb1 > overs:
f = 1
if oversb2 > overs:
f = 1
def winner():#Displays the winner
print(team1,"scored",tot1,"for the loss of",w1,"wickets")
print(team2,"scored",tot2,"for the loss of",w2,"wickets")
if tot2>tot1:
print("The winner of",team1,"vs",team2,"is",team2)
if tot1>tot2:
print("The winner of", team1, "vs", team2, "is", team1)
if tot1==tot2:
print("Match tied")
def most_runs():#Displays Details of the players with the most runs
cursor.execute("select name,runs from bat1 order by runs desc")
data=cursor.fetchall()
print("For",team1)
print(data[0])
cursor.execute("select name,runs from bat2 order by runs desc")
data1=cursor.fetchall()
print("For",team2)
print(data1[0])
def most_wickets():#Displays Details of the players with the most wickets
cursor.execute("select name,wickets from bowl1 order by wickets desc")
data=cursor.fetchall()
print("For", team1)
print(data[0])
cursor.execute("select name,wickets from bowl2 order by wickets desc")
data1=cursor.fetchall()
print("For", team2)
print(data1[0])
def best_strike_rate():#Displays Details of the players with the most Strike Rate
cursor.execute("select name,strike_rate from bat1 order by strike_rate desc")
data=cursor.fetchall()
print("For", team1)
print(data[0])
cursor.execute("select name,strike_rate from bat2 order by strike_rate desc")
data1 = cursor.fetchall()
print("For", team2)
print(data1[0])
def best_economy():#Displays Details of the players with the best economy
cursor.execute("update bowl1 set economy=economy +37 where overs=0")
cursor.execute("select name,economy from bowl1 order by economy")
data = cursor.fetchall()
print("For", team1)
print(data[0])
cursor.execute("update bowl2 set economy=economy +37 where overs=0")
cursor.execute("select name,economy from bowl2 order by economy")
data1 = cursor.fetchall()
print("For", team2)
print(data1[0])
def entire_statistics_team1():#Displays entire statistics for team1
print(team1)
for a in t1:
print(a)
def entire_statistics_team2():#Displays entire statistics for team2
print(team2)
for a in t2:
print(a)
if f==0:
while(ch=="yes"or ch=="Yes"):
"""menu"""
print("-"*20)
print("OPTIONS MENU")
print("-"*20)
print("1.Winner")
print("2.Most Runs")
print("3.Most Wickets")
print("4.Best Strike Rate")
print("5.Best Economy")
print("6.Statistics for",team1)
print("7.Statistics for",team2)
choice=int(input("Enter your choice"))
if choice==1:
winner()
elif choice==2:
most_runs()
elif choice==3:
most_wickets()
elif choice==4:
best_strike_rate()
elif choice==5:
best_economy()
elif choice==6:
entire_statistics_team1()
elif choice==7:
entire_statistics_team2()
else:
print("invalid choice")
ch=input("Type Yes to continue")
ch.lower()
else:
print("Invalid Data inserted")