This is the question:
"The user must enter a non-negative number to add to the lists or a negative number to stop the program. For every non-negative number entered, place each even and odd number in its respective list. Print the lists of even and odd numbers at the end of the program. You must use a while loop."
This is my code and algorythm:
I keep getting an error message when I run the program. Does anybody know what is wrong?
"The user must enter a non-negative number to add to the lists or a negative number to stop the program. For every non-negative number entered, place each even and odd number in its respective list. Print the lists of even and odd numbers at the end of the program. You must use a while loop."
This is my code and algorythm:
Code:
#create empty lists to hold even and odd numbers
even = ""
odd = ""
#create a message giving the directions
mess = "Enter a non-negative number to add to the lists or a negative number to stop"
#get input from the user
val = raw_input(mess)
#while input does not equal sentinal
while (val > 0):
#process the data using if statements
if ((val%2) == 0):
even = even + val
else:
odd = odd + val
#get next value
val = raw_input(mess)
#print lists
print even
print odd
Comment