SPPU DSL Experiment no.1 Group A
Q.In second year computer engineering class,group A student's play cricket,group B students play badminton and group C students play football.write a python program using funcctions to compute following
a)list of students who play both cricket and badminton
b) list of students who play either cricket or badminton but not both
c)no. of students who play neither cricket nor badminton
d)no. of students who play cricket and football but not badminton
ans-
cricket = {"dhoni","sachin","virat","rohit"}
badminton = {"sahil","aarya","bhavik","dhoni","rohit"}
football = {"ronaldo","messi","sunil"}
def both_cricket_and_badminton(cricket,badminton):
both_play=[]
for student in cricket:
if student in badminton:
both_play.append(student)
return both_play
def either_cricket_or_badminton_but_not_both(cricket,badminton):
either_play=[]
for student in cricket:
if student not in badminton:
either_play.append(student)
for student in badminton:
if student not in cricket:
either_play.append(student)
return either_play
def neither_cricket_nor_badminton(cricket,badminton,football):
neither_play=[]
for student in football:
if student not in cricket and student not in badminton:
neither_play.append(student)
return neither_play
both_play= both_cricket_and_badminton(cricket,badminton)
either_play=either_cricket_or_badminton_but_not_both(cricket,badminton)
neither_play=neither_cricket_nor_badminton(cricket,badminton,football)
print("student who play both cricket and badminton",both_play)
print("student who play either cricket or badminton but not both",either_play)
print("student who play neither cricket nor badminton",neither_play)
OR
cricket = ["abhi", "shiv", "tank", "chank"]
badminton = ["road", "abhi", "chank", "rudra"]
football = ["abhi", "shiv", "road", "naman", "janak"]
a = list()
for i in cricket:
if i in badminton:
a.append(i)
print("student who play both cricket and badminton : ",a);
b = []
for i in cricket:
if i not in badminton:
b.append(i)
for i in badminton:
if i not in cricket:
b.append(i)
print("student who play either cricket or badminton but noth both : ",b)
c=[]
for i in football:
if i not in badminton and i not in cricket:
c.append(i)
print("student who neither play circket nor badminton : ",c)
d = []
for i in football:
if i in cricket and i not in badminton:
d.append(i)
print("Students who play cricket and football but not badminton:", d)
Follow me on
Main Channel :-
/ @sahilkumbhar24
Second channel:-
/ @gamingbuddy24303
Instagram:-
/ sahil_kumbhar_24
Twitter:-
https://mobile.twitter.co/Sahilkumbha...
Facebook:-
/ sahil.kumbhar.7311
Telegram:-
https://t.me/Sahil24042004
For Business Enquiry Email :
Don't Forget To Like, Comment, Share & Subscribe
...
[THANKS FOR WATCHING THIS VIDEO]
Sahil Kumbhar
From - Karad Maharashtra #motivationalstatus3D
*FAIR USE*
Copyright Disclaimer under section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, education and research.
Fair use is a use permitted by copyright statute that might otherwise be infringing.
Non-profit, educational or personal use tips the balance in favor of fair use.
python,programming,tech,software,engineering,program,technology,coding,code,coder,programmer,engineer,software engineer,computer,computer programming,tips,codelife,computers,function,operators,new,learn python,what is python,how to,python tips,tricks,beginner,tutorial,learn,decorators,@decorators,@ sign,at sign,@symbol,@ symbol,@sign,decorator,above