-3

For some reason this code prints out nothing? can someone help?

n = raw_input()
for i in range (10):
    if len(str(i ** 2)) == n:
        print i**2
2
  • 4
    Integers and strings can never be equal. Commented Nov 16, 2014 at 20:23
  • n = int(raw_input()) Commented Nov 16, 2014 at 20:27

1 Answer 1

0

raw_input does not return int. (Python 2) always returns strings.

Convert the result to integer explicitly with int()

Demo:

try:
    n = int(raw_input())
    for i in range (10):
       if len(str(i ** 2)) == n:
         print i**2
except ValueError:
    # value error
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.