Skip to content Skip to sidebar Skip to footer

Input Command Taking Input As An Int Instead Of A Str In Python

I am a beginner programing with Python 2.79. I am writing a program that 'tokenizes' a mathematical formula, basically turning each number and operator into an item in a list. My

Solution 1:

The reason Python is interpreting the user's input as an integer is because of the line input('Enter a math equation: '). Python interprets that as eval(raw_input(prompt)). The raw_input function creates a string from the user input, and eval evaluates that input -- so an input of 5+2 is considered "5+2" by raw_input, and eval evaluates that to be 7.

Documentation

Post a Comment for "Input Command Taking Input As An Int Instead Of A Str In Python"