+ 2

I need help from a guru đŸ€­

Why is the answer "0": What is the output from the code? ages = [23, 11, 18, 75, 99] p = ages.count(99) - ages.count(11) print(p)

22nd Jan 2020, 11:09 AM
Shamil Erkenov
Shamil Erkenov - avatar
5 Answers
+ 4
Please use appropriate tag. In this case, Python and count https://www.sololearn.com/Discuss/1316935/?ref=app
22nd Jan 2020, 11:45 AM
Gordon
Gordon - avatar
+ 7
count function of the list basically gives you how many times the data occur in the list. ages.count(99) is 1 because 99 occurs in the list only once or you can say the frequency of 99 in ages list is 1. ages.count(11) is also occur in ages list 1. that's why when you minus ages.count(99) from ages.count(11) gives you value 0 because both have the same value.
22nd Jan 2020, 11:14 AM
Maninder $ingh
Maninder $ingh - avatar
+ 6
list.count(x) returns the frequency of specified element x found within the list. The list you provided contains one 99 and one 11, so ages.count(99) and ages.count(11) both returns 1. 1-1 is 0. Ref: https://docs.python.org/3/tutorial/datastructures.html
22nd Jan 2020, 11:12 AM
Fermi
Fermi - avatar
+ 3
Oh, I got that thank you so muchâ˜ș
22nd Jan 2020, 11:18 AM
Shamil Erkenov
Shamil Erkenov - avatar
+ 1
1-1=0
23rd Jan 2020, 11:31 AM
Sonic
Sonic - avatar