ProblemStatement:Insecondyearcomputerengineeringclass,groupAstudent's play cricket, group B students play badminton and group C students play football.
total=int(input("Total number of CRICKET players:\t"))
foriinrange(total):
players=int(input(f"Roll number of player {i+1}:\t"))
cricketPlayers.append(players)
print(f"\n----------\nStudents playing cricket:\t{cricketPlayers}\n----------\n")
# Input badminton
defbadmintonInput():
total=int(input("Total number of BADMINTON players:\t"))
foriinrange(total):
players=int(input(f"Roll number of player {i+1}:\t"))
badmintonPlayers.append(players)
print(f"\n----------\nStudents playing badminton:\t{badmintonPlayers}\n----------\n")
# Input football
deffootballInput():
total=int(input("Total number of FOOTBALL players:\t"))
foriinrange(total):
players=int(input(f"Roll number of player {i+1}:\t"))
footballPlayers.append(players)
print(f"\n----------\nStudents playing football:\t{footballPlayers}\n----------\n")
# Playing both cricket and badminton
defCricketAndBadminton():
listCricketAndBadminton=[]
foriincricketPlayers:
ifiinbadmintonPlayers:
listCricketAndBadminton.append(i)
print(f"\n----------\nStudents playing cricket and badminton:\t{listCricketAndBadminton}\n----------\n")
# Either cricket or badminton but not both
defCricketOrBadminton():
listCricketOrBadminton=[]
foriincricketPlayers:
ifinotinbadmintonPlayers:
listCricketOrBadminton.append(i)
foriinbadmintonPlayers:
ifinotincricketPlayers:
listCricketOrBadminton.append(i)
print(f"\n----------\nStudents playing cricket or badminton (but not both):\t{listCricketOrBadminton}\n----------\n")
# Neither cricket nor badminton, i.e. football only
defFootballOnly():
listCricketAndBadminton=[]
listFootballOnly=[]
foriincricketPlayers:
listCricketAndBadminton.append(i)
foriinbadmintonPlayers:
ifinotincricketPlayers:
listCricketAndBadminton.append(i)
foriinfootballPlayers:
ifinotinlistCricketAndBadminton:
listFootballOnly.append(i)
print(f"\n----------\nTotal students playing football only are:\t{len(listFootballOnly)}\nList:\t{listFootballOnly}\n----------\n")
# Cricket and football but not badminton
defnotBadminton():
listNotBadminton=[]
foriincricketPlayers:
ifiinfootballPlayers:
ifinotinbadmintonPlayers:
listNotBadminton.append(i)
print(f"\n----------\nTotal students not playing badminton (but do play cricket and football):\t{len(listNotBadminton)}\nList:\t{listNotBadminton}\n----------\n")
# Main function with options
defmain():
print("----- ENTER ROLL NUMBERS IN LIST -----")
cricketInput()
badmintonInput()
footballInput()
print("----- ROLL NUMBERS SAVED -----\n")
while(1):
print("\n----- MAIN MENU -----")
print("1 -> Students playing both cricket and badminton")
print("2 -> Students playing either cricket or badminton, but not both")
print("3 -> Students playing neither cricket nor badminton (i.e. football only)")
print("4 -> Students playing cricket and football, but not badminton")