Thursday, 5 September 2013

Python Splitting string to find largest odd integer

Python Splitting string to find largest odd integer

I need to split the raw_input from the user (which consists of 10
integers) so I can find the largest odd integer. The final output should
be the largest odd integer or "none" if there are no odds in the string.
This code gives me a TypeError: not all arguments converted during string
formatting error.
Here is what I have:
def uiLargestOddofTen():
userInput = raw_input("Please enter ten integers:")
oddList = []
x = userInput.split()
n = 10
for element in x:
y = int(element)
while n > 0:
if element % 2 != 0:
oddList.append(y)
n = n - 1
return max(oddList)
Thanks for your help!!

No comments:

Post a Comment