-4

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.

EvrestRGB
  • 1
  • 3
  • you need to call `main` the same way you called `raw_input` (they're both functions) – Paul H Jan 20 '23 at 17:52
  • 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 – Random Davis Jan 20 '23 at 17:52
  • `for i in range(12000): raw input()`? Also you should be using Python 3. – jfaccioni Jan 20 '23 at 17:52
  • `main` isn't a function; it's `str` *returned* by a function. – chepner Jan 20 '23 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. – chepner Jan 20 '23 at 17:55
  • Are you expecting 12,000 calls to `raw_input`? `main = raw_input` and `for i in range(12000): main()`. – chepner Jan 20 '23 at 17:56
  • If you want to call `raw_input` 12,000 times, just put the call in the loop: `for i in range(12000): raw_input()`. But probably you want to store the input somewhere, like appending it to a list. It would help a lot if you were to explain what are you trying to do, and what's your expected output. – Ignatius Reilly Jan 20 '23 at 18:07

1 Answers1

0

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()
chepner
  • 497,756
  • 71
  • 530
  • 681