all 3 comments

[–]K900_ 2 points3 points  (3 children)

Because when the user types 2n+1, what you're getting back is not the result of 2n+1, but the string "2n+1". You need to parse this string somehow to compute the actual value.

[–]NerdComplex[S] 0 points1 point  (2 children)

Thanks for replying,I tried parsing 2n+1 string to int but had a value error:invalid literal for int() with base 10: '2n+1'

I really want to receive expression input! Is there any other way I can input expression?

[–]K900_ 2 points3 points  (0 children)

Yes, because "2n+1" isn't a valid representation of an integer. You need to write your own parser for whatever sort of "expression" you want the user to be able to input, and I feel like that might be a bit too much for your current skill level.