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

前端 未结 6 1275
悲哀的现实
悲哀的现实 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条回答
  •  Happy的楠姐
    2021-01-23 03:59

    In Python 2.x, input asks for a Python expression (like num1 + 2) which is then evaluated. You want raw_input which allows one to ask for arbitrary strings.

提交回复
热议问题