+ 1

User input + spaces

Hi, the input is like: num1+num2 I need to split input into 3 fragments: 'num1', '+', 'num2'. But if the user input without spaces, Python treats it like one string (so I cant use index). Can I enforce user's input to add the spaces (num1_space_ + _space_ num2? Thank you!

20th Aug 2018, 3:15 PM
Alex
Alex - avatar
3 odpowiedzi
+ 5
If you're going to use eval(), there's a much simpler way >>> eval(input()) 21*2 42
20th Aug 2018, 3:34 PM
Just A Rather Ridiculously Long Username
0
Just A Rather Ridiculously Long Username, superb! Thanks a lot!
20th Aug 2018, 4:02 PM
Alex
Alex - avatar
0
No problem :)
24th Aug 2018, 1:26 PM
Just A Rather Ridiculously Long Username