How do I input an integer on a new line

时间:2016-02-03 03:53:35

标签: python-3.x

I am trying to make an input integer on a new line using python, but I get an error when I do this.

#inputs myMath as an integer
print = ("Give me a number and I will double it for you.")
myMath = int(input + "\n")

#Multiplies myMath(the variable) times 2
result = eval("2 * myMath")

The error says "TypeError: unsupported operand type(s) for +: 'builtin_function_or_method' and 'str'" I am using python 3.5.1.

1 个答案:

答案 0 :(得分:1)

Here is what you want:

yourVal = int(input("Double a number:\n"))
result = yourVal*2
print(result)