Project File Ipp
Project File Ipp
The aim of the above code is to simulate an interactive cricket game where a user plays against the
computer. The game consists of several rounds where the user chooses between batting or bowling
based on the toss result, and both the user and the computer take turns attempting to score or get
out. The program keeps track of the scores and determines the winner of each match. It also includes
options for playing a super-over if a match ends in a tie.
Specifications required:
1. Software:
2. Hardware:
3. File Path:
o Ensure the proper file path for datas.csv is set up and accessible for reading/writing
data.
4. Input:
o User provides numeric input (0-6) for batting and bowling scores.
o User selects options like "Bat," "Ball," "Tie," and for playing a super-over.
5. Graphical Output:
o The system should support graphical output via matplotlib (ensure graphical
libraries(matplotlib.pyplot) are properly configured).
if x==a:
k=input("\nYOU WON THE TOSS\nYOU CHOSE TO(BAT/BALL) : ")
print()
if k.lower()=='bat':
ru=0
print("\n\t\t\t < YOU ARE BATTING >")
while True:
m=int(input("\nENTER YOUR NUMBER TO SCORE(0-6) : "))
if m>6:
print("DON'T DO THAT AGAIN")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
c=int(r.randint(1,6))
print("COMPUTER BOWLED : ",c)
if m!=c:
ru+=m
print("YOUR CURRENT SCORE IS : ",ru)
print()
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
print('Runs scored by you is ',ru)
print('Target to the computer is ',ru+1)
rc=0
print("\n\n\t\t\t < YOU ARE BOWLING >")
while True:
if m!=c:
rc+=c
print("COMPUTER'S CURRENT SCORE IS : ",rc)
print()
x+=1
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
print('Runs scored by computer is ',rc)
print('The Target to YOU is ',rc+1)
print("\n\n\t\t\t < YOU ARE BATTING >")
x=1
ru=0
while x<=6:
m=int(input("ENTER YOUR NUMBER TO SCORE(0-6) : "))
if m>6:
print("DON'T DO THAT AGAIN")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
c=int(r.randint(1,6))
print("COMPUTER BOWLED : ",c)
if m!=c:
ru+=m
print("YOUR CURRENT SCORE IS : ",ru)
print()
x+=1
if ru>rc:
print("\n\n\t\t\t <<< YOU WON >>>")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
if ru<rc:
print("\n\n\t\t\t <<< COMPUTER WON >>>")
#BATTING OVER
if k.lower()=='ball':
rc=0
print("\n\t\t\t < YOU ARE BOWLING >")
while True:
m=int(input("\nENTER YOUR NUMBER TO BOWL(0-6) : "))
c=int(r.randint(1,6))
print("COMPUTER PLAYED : ",c)
if m!=c:
rc+=c
print("COMPUTER'S CURRENT SCORE IS : ",rc)
print()
else :
print("\n\n\t\t\t < THAT'S OUT! >")
print()
break
print('Runs scored by computer is ',rc)
print('The Target to YOU is ',rc+1)
ru=0
print("\n\t\t\t < YOU ARE BATTING >")
while True:
m=int(input("\nENTER YOUR NUMBER TO SCORE(0-6) : "))
if m>6:
print("DON'T DO THAT AGAIN")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
c=int(r.randint(1,6))
print("COMPUTER BOWLED : ",c)
if m!=c:
ru+=m
print("YOUR CURRENT SCORE IS : ",ru)
print()
if ru>rc:
print("\n\n\t\t\t <<< YOU WON >>>")
break
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
if ru<rc:
print("\n\n\t\t\t <<< COMPUTER WON >>>")
elif ru==rc:
while ru==rc:
j=input('''\n\n\t\t\t !! IT'S A TIE !!''''\n\n\nDO YOU WANT TO PLAY A SUPEROVER MATCH?(Y/N) : ')
if j.lower()=='y':
print("\n\n\t\t\t < YOU WILL BAT FIRST >")
x=1
ru=0
while x<=6:
m=int(input("ENTER YOUR NUMBER TO SCORE(0-6) : "))
if m>6:
print("DON'T DO THAT AGAIN")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
c=int(r.randint(1,6))
print("COMPUTER BOWLED : ",c)
if m!=c:
ru+=m
print("YOUR CURRENT SCORE IS : ",ru)
print()
x+=1
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
print('Runs scored by you is ',ru)
print('Target to the computer is ',ru+1)
print("\n\t\t\t < YOU ARE BOWLING >")
x=1
rc=0
while x<=6:
m=int(input("ENTER YOUR NUMBER TO BOWL(0-6) : "))
c=int(r.randint(1,6))
print("COMPUTER PLAYED : ",c)
if m!=c:
rc+=c
print("COMPUTER'S CURRENT SCORE IS : ",rc)
print()
x+=1
if ru<rc:
print("\n\n\t\t\t <<< COMPUTER WON >>>")
break
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
if ru>rc:
print("\n\n\t\t\t <<< YOU WON >>>")
#BOT WON THE TOSS
else:
p=r.randint(0,1)
if p==0:
print("\nCOMPUTER WON THE TOSS AND CHOSE TO BAT FIRST")
print("\n\t\t\t < YOU ARE BOWLING >")
rc=0
while True:
m=int(input("\nENTER YOUR NUMBER TO BOWL(0-6) : "))
c=int(r.randint(1,6))
print("COMPUTER PLAYED : ",c)
if m!=c:
rc+=c
print("COMPUTER'S CURRENT SCORE IS : ",rc)
print()
else:
print("\n\n\t\t\t < THAT'S OUT! >")
break
print('Runs scored by computer is ',rc)
print('The Target to YOU is ',rc+1)
ru=0
print("\n\t\t\t < YOU ARE BATTING >")
while True:
m=int(input("\nENTER YOUR NUMBER TO SCORE(0-6) : "))
if m>6:
print("DON'T DO THAT AGAIN")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
c=int(r.randint(1,6))
print("COMPUTER BOWLED : ",c)
if m!=c:
ru+=m
print("YOUR CURRENT SCORE IS : ",ru)
print()
if ru>rc:
print("\n\n\t\t\t <<< YOU WON >>>")
break
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
if ru<rc:
print("\n\n\t\t\t <<< COMPUTER WON >>>")
elif ru==rc:
j=input('''\n\n\t\t\t !! IT'S A TIE !!''''\n\n\nDO YOU WANT TO PLAY A SUPEROVER MATCH?(Y/N) : ')
if j.lower()=='y':
print("\n\t\t\t < YOU ARE BATTING >")
x=1
ru=0
while x<=6:
m=int(input("ENTER YOUR NUMBER TO SCORE(0-6) : "))
if m>6:
print("DON'T DO THAT AGAIN")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
c=int(r.randint(1,6))
print("COMPUTER BOWLED : ",c)
if m!=c:
ru+=m
print("YOUR CURRENT SCORE IS : ",ru)
print()
x+=1
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
print('Runs scored by you is ',ru)
print('Target to the computer is ',ru+1)
print("\n\t\t\t < YOU ARE BOWLING >")
x=1
rc=0
while x<=6:
m=int(input("ENTER YOUR NUMBER TO BOWL(0-6) : "))
c=int(r.randint(1,6))
print("COMPUTER PLAYED : ",c)
if m!=c:
rc+=c
print("COMPUTER'S CURRENT SCORE IS : ",rc)
print()
x+=1
if ru>rc:
print("\n\n\t\t\t <<< YOU WON >>>")
break
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
if ru<rc:
print("\n\n\t\t\t <<< COMPUTER WON >>>")
else:
print("\nCOMPUTER WON THE TOSS AND CHOSE TO BALL FIRST")
print("\n\t\t\t < YOU ARE BATTING >")
ru=0
while True:
m=int(input("\nENTER YOUR NUMBER TO SCORE(0-6) : "))
if m>6:
print("DON'T DO THAT AGAIN")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
c=int(r.randint(1,6))
print("COMPUTER BOWLED : ",c)
if m!=c:
ru+=m
print("YOUR CURRENT SCORE IS : ",ru)
print()
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
print('\nRuns scored by you is ',ru)
print('Target to the computer is ',ru+1)
rc=0
print("\n\n\t\t\t < YOU ARE BOWLING >")
while True:
c=int(r.randint(1,6))
print("COMPUTER PLAYED : ",c)
if m!=c:
rc+=c
print("COMPUTER'S CURRENT SCORE IS : ",rc)
print()
if ru<rc:
print("\n\n\t\t\t <<< COMPUTER WON >>>")
break
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
if ru>rc:
print("\n\n\t\t\t <<< YOU WON >>>")
elif ru==rc:
j=input('''\n\n\t\t\t !! IT'S A TIE !!''''\n\n\nDO YOU WANT TO PLAY A SUPEROVER MATCH?(Y/N) : ')
if j.lower()=='y':
print("\n\n\t\t\t < COMPUTER WILL BAT FIRST >")
x=1
rc=0
while x<=6:
m=int(input("ENTER YOUR NUMBER TO BOWL(0-6) : "))
c=int(r.randint(1,6))
print("COMPUTER PLAYED : ",c)
if m!=c:
rc+=c
print("COMPUTER'S CURRENT SCORE IS : ",rc)
print()
x+=1
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
print('Runs scored by computer is ',rc)
print('The Target to YOU is ',rc+1)
print("\n\n\t\t\t < YOU ARE BATTING >")
x=1
ru=0
while x<=6:
m=int(input("ENTER YOUR NUMBER TO SCORE(0-6) : "))
if m>6:
print("DON'T DO THAT AGAIN")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
c=int(r.randint(1,6))
print("COMPUTER BOWLED : ",c)
if m!=c:
ru+=m
print("YOUR CURRENT SCORE IS : ",ru)
print()
x+=1
if ru>rc:
print("\n\n\t\t\t <<< YOU WON >>>")
while True:
print("CHEATING KARTA HAI, CHEATING KARTA HAI")
else :
print("\n\n\t\t\t < THAT'S OUT! >")
break
if ru<rc:
print("\n\n\t\t\t <<< COMPUTER WON >>>")
d={'ru':ru,'rc':rc}
df1=pandus.DataFrame(d,index=['1'])
df=pandus.read_csv('C:\\Users\\ENG LAB\\Desktop\\JINU\\datas.csv',index_col=0)
s=len(df)+1
df1.index=['Match %s'%s]
df=df._append(df1)
df.to_csv('C:\\Users\\ENG LAB\\Desktop\\JINU\\datas.csv')
while True:
opt=input('\n\n0 : Show recent match score\n1 : Show all match scores\n2 : Show graph of all the matches(for more than 1 match)\n3 :
delete previous datas \n4 : exit the program \nEnter your choice : ')
if opt=='0':
print('\n\n',df1)
elif opt=='1':
print('\n\n',df)
elif opt=='2':
x=list(df.index)
y1=list(df['ru'])
y2=list(df['rc'])
mpl.plot(x,y1,label='User runs')
mpl.plot(x,y2,label='Computer runs')
mpl.legend()
mpl.show()
elif opt=='3':
df2=pandus.DataFrame(columns=['ru','rc'])
df2.to_csv('C:\\Users\\ENG LAB\\Desktop\\JINU\\datas.csv')
elif opt=='4':
break
else:
print("\n\n\t\t <<< CHOOSE YOUR OPTION WISELY >>>")
#learning
From the cricket game code, I learned key programming concepts such as variables, loops,
conditionals, and functions. I practiced handling user input, simulating random events with the
random library, and managing game flow. I explored file handling with CSV files, using pandas for
data storage and manipulation, and matplotlib for visualizing match scores. The game’s design
improved my logical thinking and problem-solving skills. Additionally, I gained experience with
external libraries and learned how to structure and organize code.
1. Toss I/O
4b.
4c.