0

Can anyone please explain me why c[0] and c[1] is used to display the number of counts in odd or even numbers

def evenodd(tup): ceven=0 codd=0 for i in tup: if i%2==0: ceven+=1 else: codd+=1 return ceven,codd t=() n=int(input("Enter total number of elements in a tuple:- ")) for i in range(n): num=int(input("Enter a number:- ")) t=t+(num,) c=evenodd(t) print("Even Numbers are:- ",c[0]) print("Odd Numbers are:- ",c[1])

13th May 2023, 4:49 PM
Sanskriti Chaurasiya
Sanskriti Chaurasiya - avatar
3 odpowiedzi
+ 5
The function evenodd(tup) returns a tuple which is stored in variable c Therefore to access the values we take c[0] and c[1] for even and odd respectively
13th May 2023, 5:09 PM
Vinome
Vinome - avatar
+ 5
Hello Sanskriti, Please use relevant tags for better context clarity. You can put Python in tags, that's the language relevant to the question, and the embedded snippet in Descripton. https://code.sololearn.com/W3uiji9X28C1/?ref=app
13th May 2023, 5:41 PM
Ipang
+ 4
evenodd(tup) returns a tuple so we use c[0] to access first element and c[1] for second
13th May 2023, 5:02 PM
Binx
Binx - avatar