Why the output is 3? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why the output is 3?

list=[1,2,3,4,6] if len(list)%2!=0; print(list[max(list)%4]) else: print(list[min(list)]) the len is 4 indexes 4%2 =2 list max - 4%4 —>1 so why it is not 1 but 3 and what is min list -0?

19th Nov 2019, 8:03 PM
THEGreatGatsby
THEGreatGatsby - avatar
3 Answers
+ 5
THEGreatGatsby , the length of the list is 5 (there are five elements in the list starting from index 0 to 4). So if conditional is true => 5%2! =0 and max element in the list is 6 => print (list [6%4]) => list[2] => 3. Hope now everything is clear 🐱
19th Nov 2019, 8:12 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Just adding a note. Python is really strict when it comes to code indentation. As I see your code, all the lines are on the same indentation level, so I think this code is not running, at least until one fixed the indentation problem.
20th Nov 2019, 6:28 AM
Ipang
0
cool :)
19th Nov 2019, 8:13 PM
THEGreatGatsby
THEGreatGatsby - avatar