4 Answers
+ 2
This is a (relatively) easy to understand method. Works for any amount if integers separated by a SPACE
x = input()
# split into integers
x = [int(i) for i in x.split()]
max = 0
odd = False
for i in x:
if i%2!=0 and i>max:
max=i
odd = True
if odd:
print(max)
else:
print("No odds")
Oneliner version for funđ (not sure if it works tho)
print((lambda x=[int(i) for i in input().split() if x%2!=0]: max(x) if len(x)>=0 else "No odd number")())
+ 1
Did you just join Sololearn to ask other people to make your homework for you? Sorry, but here we kind of need you to show your attempt before helping you :/ I can tell you the process though:
Get the user inputs with a for loop and store them in an array, then filter the array so it only contains odd numbers, and then get the max number. If the array is empty, print the message
+ 1
im sorry, but i believe you dont understand the definition of âquestionâ
anyways,
try:
print(max([int(i) for i in input().split()if int(i)%2!=0]))
except:
print("No odd numbers")
0
Guys that is just a problem I came across while studying. Thank you for your help.