$30
CSE111
Makeup Final Exam
Marks: 30
Time: 100 Minutes
Question 1:
Suppose you are decrypting an incoming message for National Security purposes. For that you
need to find the most occurrence of a substring along with all other substring with their
occurrences number from a given string. Write a python program that will take a string and an
integer input from the user and then find all the sequential occurrences of that given length’s
substring from the given string and count the occurrences. Finally print the highest number of
occurrences among those substring. If there is not a single largest substring then print “No highest
substring found.”
Sample Input:
ABBCDABCD
3
Sample Output:
ABB 1
BBC 1
BCD 2
CDA 1
DAB 1
ABC 1
Highest substring: BCD
Sample Input:
ABBCDABCDABC
4
Sample Output:
ABBC 1
BBCD 1
BCDA 2
CDAB 2
DABC 2
ABCD 1
No highest substring found.
Question 2:
Implement the Player class with necessary properties so that the given output is produced.
Hints:
1. While creating ID always take the last word of that player’s name (last name), if the
name consists only one word then only take that word
You cannot change any of the given code.
#Write your code here
print(Player.player_details)
print("1.###############################################")
ronaldo = Player("Ronaldo", "Man United", "Forward", "2021")
ronaldo.cheer_player()
print("2.-----------------------------------------------")
messi = Player("Lionel Andrés Messi", "Barcelona", "Forward")
messi.cheer_player()
print("3.-----------------------------------------------")
ramos = Player.create_player("Sergio Ramos", "PSG", "Defender",
"2021")
ramos.cheer_player()
print("4.===============================================")
print(ronaldo)
print("5.===============================================")
print(messi)
print("6.===============================================")
print(ramos)
print("7.###############################################")
print(Player.player_details)
Output:
No players available
1.###############################################
Let's cheer for Ronaldo who is a pride of Man United
2.-----------------------------------------------
Let's cheer for Lionel Andrés Messi who is a pride of
Barcelona
3.-----------------------------------------------
Let's cheer for Sergio Ramos who is a pride of PSG
4.===============================================
Player Details
Player No: 1
ID: 1_2021_Ronaldo
Name: Ronaldo
Club: Man United
Joining Year: 2021
5.===============================================
Player Details
Player No: 2
ID: 2_Unknown_Messi
Name: Lionel Andrés Messi
Club: Barcelona
Joining Year: Unknown
6.===============================================
Player Details
Player No: 3
ID: 3_2021_Ramos
Name: Sergio Ramos
Club: PSG
Joining Year: 2021
7.###############################################
{'1_2021_Ronaldo': ['Ronaldo', 'Man United',
'Forward', '2021'], '2_Unknown_Messi': ['Lionel Andrés
Messi', 'Barcelona', 'Forward', 'Unknown'],
'3_2021_Ramos': ['Sergio Ramos', 'PSG', 'Defender',
'2021']}
Question 3:
Implement the Valorant class derived from Game class with necessary variables and methods
so that the expected output is generated. Do not change any given code.
[Hint:
- In order to form a team, you need at least 5 players. And in order to form a perfect
team you need 2 duelists, 1 initiator, 1 controller and 1 sentinel. ]
class Game:
agentCount=0
def __init__(self,name,gameType):
self.name = name
self.gameType = gameType
def formTeam(self):
if Game.agentCount >= 5:
return True
else:
return False
def __str__(self):
s = f"{self.name} is an {self.gameType} game.\n"
s+= f"Number of agents in {self.name} is {Game.agentCount}\n"
return s
#Write down your code here.
#Do not change the given code
v = Valorant("Valorant","FPS")
v.addAgent(["Raze","Duelist","Showstopper"],["Sova","Initiator","Hunter's fury"])
print("1.====================================")
print(v)
print("2.====================================")
v.formTeam()
print("3.====================================")
v.addAgent(["Killjoy","Sentinel","Lockdown"])
v.addAgent(["Viper","Controller","Viper's pit"])
print("4.====================================")
print(v)
print("5.====================================")
v.formTeam()
print("6.====================================")
v.addAgent(["Breach","Initiator","Rolling thunder"])
v.formTeam()
print("7.====================================")
v.addAgent(["Jett","Duelist","Bladestorm"])
print(v)
print("8.====================================")
v.formTeam()
Output:
1.====================================
Valorant is an FPS game.
Number of agents in Valorant is 2
The agents are:
Duelist:
Agent name: Raze, Ultimate:Showstopper
Initiator:
Agent name: Sova, Ultimate:Hunter's fury
2.====================================
We do not have enough agents to form a team.
3.====================================
4.====================================
Valorant is an FPS game.
Number of agents in Valorant is 4
The agents are:
Duelist:
Agent name: Raze, Ultimate:Showstopper
Initiator:
Agent name: Sova, Ultimate:Hunter's fury
Sentinel:
Agent name: Killjoy, Ultimate:Lockdown
Controller:
Agent name: Viper, Ultimate:Viper's pit
5.====================================
We do not have enough agents to form a team.
6.====================================
We have enough agents to form a team.
But we cannot form a perfect team.
7.====================================
Valorant is an FPS game.
Number of agents in Valorant is 6
The agents are:
Duelist:
Agent name: Raze, Ultimate:Showstopper
Agent name: Jett, Ultimate:Bladestorm
Initiator:
Agent name: Sova, Ultimate:Hunter's fury
Agent name: Breach, Ultimate:Rolling thunder
Sentinel:
Agent name: Killjoy, Ultimate:Lockdown
Controller:
Agent name: Viper, Ultimate:Viper's pit
8.====================================
We have enough agents to form a team.
Also we can form a perfect team!!