-6

I have a question: how to repeat an instruction of raw_input in python 2.7.5?

print("This is a NotePad")
main = raw_input()

this is the code(I started 3 minutes ago.) I can't find an answer to my question on Google.

This is the code with me trying but suffering

print("This is a NotePad")
main = raw_input()

for i in range(12000):
    main

The error is Process finished with exit code 0 Okay, it's not an error but it's not what I was expecting.

7
  • you need to call main the same way you called raw_input (they're both functions) Commented Jan 20, 2023 at 17:52
  • 1
    Maybe you should explain why you possibly would want to be using Python 2 when it's been dead and deprecated for over 3 years Commented Jan 20, 2023 at 17:52
  • for i in range(12000): raw input()? Also you should be using Python 3. Commented Jan 20, 2023 at 17:52
  • main isn't a function; it's str returned by a function. Commented Jan 20, 2023 at 17:54
  • 1
    What were you expecting? Assume Python 3 and replace raw_input with input, and this question still isn't really asking anything. Commented Jan 20, 2023 at 17:55

1 Answer 1

1

main = raw_input() does not make main a "macro" equivalent to raw_input(). It assigns the return value of a single call of raw_input to the name main. The closest thing to what you appear to be trying to do is to assign the value of the name raw_input itself (the function) to the name main, then call that function in the loop.

main = raw_input  # Another name for the same function

for i in range(12000):
    # Resolve the name lookup, then call the resulting function
    main()
Sign up to request clarification or add additional context in comments.

2 Comments

what di I need to write?
What do you mean? This is complete code, though it doesn't do anything interesting. It will ask you for 12000 lines of input, then exit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.