0

python question

could someone help me write a program in python that asks a user to input ten integers,and then prints the largest odd number that was entered. if no odd number was entered, it should print a message to that effect.

25th Jun 2019, 8:27 PM
Audlyne
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")())
25th Jun 2019, 8:38 PM
Trigger
Trigger - avatar
+ 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
25th Jun 2019, 8:32 PM
Airree
Airree - avatar
+ 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")
25th Jun 2019, 9:02 PM
Choe
Choe - avatar
0
Guys that is just a problem I came across while studying. Thank you for your help.
26th Jun 2019, 4:21 PM
Audlyne