How do I get user input from the keyboard in Python 2?

前端 未结 6 1284
悲哀的现实
悲哀的现实 2021-01-23 03:49

I wrote a function in Python which prompts the user to give two numbers and adds them. It also prompts the user to enter a city and prints it. For some reason, when I run it in

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-23 04:15

    You want raw_input, not input.

    input(...)
        input([prompt]) -> value
    
        Equivalent to eval(raw_input(prompt)).
    

    As opposed to...

    raw_input(...)
        raw_input([prompt]) -> string
    
        Read a string from standard input.  The trailing newline is stripped.
        If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
        On Unix, GNU readline is used if enabled.  The prompt string, if given,
        is printed without a trailing newline before reading.
    

提交回复
热议问题