Why my python code not working properly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why my python code not working properly

I have explained my all problems in code comments.. I hv made a program to find largest of three numbers. But when i gives three random no. In which 3rd is largest , even in that case the 2nd entered number is being executed as largest no. I am not getting why does it happen Please debug it... https://code.sololearn.com/cXhHrB7NN3rw/?ref=app

4th Jul 2022, 3:36 PM
🙅‍♂️ DND 🙅‍♂️
3 Answers
+ 3
"and" operator processes 2 booleans. It can't add operands to a comparison - won't compare c to a. So "if b > a and c" goes like: If b is 2nd greater, first condition is true If c is not zero, second condition is also true
4th Jul 2022, 5:48 PM
Emerson Prado
Emerson Prado - avatar
+ 2
if a > b and a > c: print("largest number is", a) elif b > a and b > c: print ("largest number is ", b) else : print ("largest number is", c) # Look at the 2nd part of the if/elif conditions
4th Jul 2022, 4:07 PM
Lisa
Lisa - avatar
0
a = int(input()) b = int(input()) c = int(input()) li = [] li.append(a) li.append(b) li.append(c) li.sort() print ("largest number is ",li[-1])
6th Jul 2022, 3:28 PM
N. Vimukthi Dilshan Fernando