Why is this happening?
x = eval(input("Enter a number: ")) is not the same as x = eval('input("Enter a number: ")')
The first first calls input(...) , gets a string, for example. '5' then evaluates it, so you get int as follows:
>>> eval('5')
While the latter (more consistent with the expected) evaluates the expression 'input("Enter a number: ")'
>>> x = eval('input("Enter a number: ")') Enter a number: 5 >>> x '5'
source share