Job Hernandez
2015-07-25 01:49:26 UTC
I have been reading a book on Python. I am currently stuck with one of
the exercises and so wanted to ask you if you can help me.
Of course, if you have the time.
Exercise : Ask the user to input 3 integers and prints out the largest odd
number. if no odd number was entered it should print a message o that
effect.
These lines of code don't work :
a = raw_input('enter number: ')
b = raw_input('enter number: ')
c = raw_input('enter number: ')
list = [ a, b, c]
list2 =[ ]
for x in list:
if x%2 == 1: # responsible for the type error: not all arguments
converted during string #
#formatting
list2.append(x)
print list2
w = max(list2)
print ' %d is the largest odd number.' % w
# i don't know but maybe I have to return the list for this to work?
Because if I assign a
#variable to to 3 integers, like the code below it works.
But these do:
a = 3
b = 7
c = 9
list = [ a, b, c]
list2 =[]
for x in list:
if x%2 == 1:
list2.append(x)
print list2
w = max(list2)
print ' %d is the largest odd number.' % w
#Thank you for your time.
Sincerely ,
Job
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
the exercises and so wanted to ask you if you can help me.
Of course, if you have the time.
Exercise : Ask the user to input 3 integers and prints out the largest odd
number. if no odd number was entered it should print a message o that
effect.
These lines of code don't work :
a = raw_input('enter number: ')
b = raw_input('enter number: ')
c = raw_input('enter number: ')
list = [ a, b, c]
list2 =[ ]
for x in list:
if x%2 == 1: # responsible for the type error: not all arguments
converted during string #
#formatting
list2.append(x)
print list2
w = max(list2)
print ' %d is the largest odd number.' % w
# i don't know but maybe I have to return the list for this to work?
Because if I assign a
#variable to to 3 integers, like the code below it works.
But these do:
a = 3
b = 7
c = 9
list = [ a, b, c]
list2 =[]
for x in list:
if x%2 == 1:
list2.append(x)
print list2
w = max(list2)
print ' %d is the largest odd number.' % w
#Thank you for your time.
Sincerely ,
Job
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor