Wednesday, October 28, 2015

Write a program, which will find all such numbers between 1000 and 3000

#Question:
#Write a program, which will find all such numbers between 1000 and 3000
#(both included) such that each digit of the number is an even number.
#The numbers obtained should be printed in a comma-separated sequence on a single line.

values=[]
for x in range(1000,3000):
    s=str(x)
    if (int(s[0]) %2 == 0) and (int(s[1]) %2 == 0) and (int(s[2]) %2 == 0) and (int(s[3]) %2 == 0):
        values.append(s)
print "-".join(values)

6 comments:

  1. when i run this it says str is not callable

    ReplyDelete
  2. values = []
    for x in range(1000, 3000):
    s = str(x)
    if (int(s[0]) % 2 == 0) and (int(s[1]) % 2 == 0) and (int(s[2]) % 2 == 0) and (int(s[3]) % 2 == 0):
    values.append(s)
    print ("-".join(values))

    ReplyDelete
  3. when i run this program, it is showing the error that str is not callable

    ReplyDelete
  4. values=[]
    for x in range(1000,3000):
    s=str(x)
    if (int(s[0]) %2 == 0) and (int(s[1]) %2 == 0) and (int(s[2]) %2 == 0) and (int(s[3]) %2 == 0):
    values.append(s)
    print(values)

    ReplyDelete