By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,525 Members | 1,648 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,525 IT Pros & Developers. It's quick & easy.

compare items in list to x

P: n/a
I want a program that loops over a list of numbers (y) and tells me whether each number in the list is less than, greater than or equal to another number (x).

In the below code, I can't get python to see that 2 is equal to 2.

x = 2

def compare():

for y in ['12', '33', '2']:

if x < y:
print x, "is less than", y

elif x y:
print x, "is greater than", y

print x, "and", y, "are equal"

"'My country, right or wrong,' is a thing that no patriot would think of saying. It is like saying, 'My mother, drunk or sober.'"

-- G.K. Chesterton
Nov 2 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.