+ 1

Question: Input 10 numbers and find largest odd number.

Can anyone help me to answer this Question, ask the user to input 10 integers, and then prints the largest odd number without using max function. hope i can see the answer in Python.

22nd Apr 2018, 6:26 AM
Lhak C:
Lhak C: - avatar
5 Réponses
+ 2
#Enter the numbers seperated by space. print(sorted([i for i in map(int,input().split()) if i%2])[-1])
22nd Apr 2018, 7:49 AM
Louis
Louis - avatar
+ 2
Lhak Chung If you tried it you would have seen that it does only print the largest one. The [-1] at the end only references one item. The sorted makes sure that the last item of list is largest. The listcomp removes even numbers.
22nd Apr 2018, 9:47 AM
Louis
Louis - avatar
+ 1
I don't know python but i am sure that the easiest way to do is using a for loop and a variable called bigger. If the variables are stored in an array it should look like this int bigger = 0 for(int i =0;i<10;i++) if(num[i] %2 !=0 && num[i] > bigger) bigger=num[i] print(bigger) You can change it to make it look like python
22nd Apr 2018, 7:03 AM
xaralampis_
xaralampis_ - avatar
0
thanks
22nd Apr 2018, 7:46 AM
Lhak C:
Lhak C: - avatar
0
@Louis okay, but I only want to print largest one, thanks anyway
22nd Apr 2018, 9:19 AM
Lhak C:
Lhak C: - avatar