118 lines
3.6 KiB
Python
118 lines
3.6 KiB
Python
|
# DSL Assignment - 1
|
||
|
|
||
|
# List of players
|
||
|
|
||
|
cricket_players=[]
|
||
|
badminton_players=[]
|
||
|
football_players=[]
|
||
|
|
||
|
# Input values
|
||
|
|
||
|
## List for cricket players
|
||
|
def cricket_in():
|
||
|
total=int(input("Total number of students playing cricket: \t"))
|
||
|
for i in range(total):
|
||
|
players=int(input("Enter roll number: \t"))
|
||
|
cricket_players.append(players)
|
||
|
print("Roll numbers of", total, "students playing cricket: \t", cricket_players)
|
||
|
cricket_in()
|
||
|
|
||
|
## List for badminton players
|
||
|
def badminton_in():
|
||
|
total=int(input("Total number of students playing badminton: \t"))
|
||
|
for i in range(total):
|
||
|
players=int(input("Enter roll number: \t"))
|
||
|
badminton_players.append(players)
|
||
|
print("Roll numbers of", total, "students playing badminton: \t", badminton_players)
|
||
|
badminton_in()
|
||
|
|
||
|
## List for football players
|
||
|
def football_in():
|
||
|
total=int(input("Total number of students playing football: \t"))
|
||
|
for i in range(total):
|
||
|
players=int(input("Enter roll number: \t"))
|
||
|
football_players.append(players)
|
||
|
print("Roll numbers of", total, "students playing football: \t", football_players)
|
||
|
football_in()
|
||
|
|
||
|
# List of students playing cricket+badminton
|
||
|
|
||
|
cricket_and_badminton=[]
|
||
|
|
||
|
def cricket_and_badminton_fn():
|
||
|
for i in cricket_players:
|
||
|
if i in badminton_players:
|
||
|
cricket_and_badminton.append(i)
|
||
|
print("Roll numbers of students playing cricket and badminton are: \t", cricket_and_badminton)
|
||
|
|
||
|
# List of students playing either cricket or badminton but not both
|
||
|
|
||
|
cricket_or_badminton=[]
|
||
|
|
||
|
def cricket_or_badminton_fn():
|
||
|
for i in cricket_players:
|
||
|
if i not in badminton_players:
|
||
|
cricket_or_badminton.append(i)
|
||
|
for i in badminton_players:
|
||
|
if i not in cricket_players:
|
||
|
cricket_or_badminton.append(i)
|
||
|
print("Roll numbers of students playing either cricket or badminton are: \t", cricket_or_badminton)
|
||
|
|
||
|
# Number of students playing neither cricket nor badminton
|
||
|
|
||
|
football_only=[]
|
||
|
football_only_1=[]
|
||
|
|
||
|
def football_only_fn():
|
||
|
for i in cricket_players:
|
||
|
football_only.append(i)
|
||
|
for i in badminton_players:
|
||
|
if i not in cricket_players:
|
||
|
football_only.append(i)
|
||
|
for i in football_players:
|
||
|
if i not in football_only:
|
||
|
football_only_1.append(i)
|
||
|
print("Number of students playing neither cricket nor badminton: \t", len(football_only_1), "\n Roll numbers are:\t", football_only_1)
|
||
|
|
||
|
# Number of students playing cricket and football but not badminton
|
||
|
|
||
|
not_badminton=[]
|
||
|
|
||
|
def not_badminton_fn():
|
||
|
for i in badminton_players:
|
||
|
if i not in cricket_players:
|
||
|
not_badminton.append(i)
|
||
|
for i in badminton_players:
|
||
|
if i not in football_players:
|
||
|
not_badminton.append(i)
|
||
|
print("Number of students playing cricket and football but not badminton: \t", len(not_badminton), "\n Roll numbers are:\t", not_badminton)
|
||
|
|
||
|
# Choosing an option
|
||
|
def choose_optn():
|
||
|
while True:
|
||
|
print("Choose an operation to perform:")
|
||
|
print("1. List of students playing cricket and badminton both")
|
||
|
print("2. List of students playing either cricket or badminton")
|
||
|
print("3. List of students playing neither cricket nor badminton")
|
||
|
print("4. List of students playing cricket and football but not badminton")
|
||
|
print("5. Exit")
|
||
|
optn=int(input("Enter option number (1-5): \t"))
|
||
|
if optn==1:
|
||
|
cricket_and_badminton_fn()
|
||
|
if optn==2:
|
||
|
cricket_or_badminton_fn()
|
||
|
if optn==3:
|
||
|
football_only_fn()
|
||
|
if optn==4:
|
||
|
not_badminton_fn()
|
||
|
if optn==5:
|
||
|
print("## DESIGNED AND ENGINEERED BY KSHITIJ\n## END OF CODE")
|
||
|
quit()
|
||
|
else:
|
||
|
print("\nPlease choose a valid option.\n")
|
||
|
choose_optn()
|
||
|
choose_optn()
|
||
|
|
||
|
## END OF CODE
|
||
|
|