+ 2

Splitting Input

Asssume that the input is given in a huge line of multiple input, for example: " 7 3 SUM 5 4 MUL 3 3 DIV ,etc". how can i command pyhton to read the last line as the operation, and splitting up those input so i can get the output of each operation one by one?

20th Sep 2018, 5:18 AM
fadhlan pasyah
fadhlan pasyah - avatar
7 odpowiedzi
+ 3
fadhlan pasyah Look at the code, I updated it
21st Sep 2018, 12:07 PM
Anna
Anna - avatar
+ 3
I updated the code again
21st Sep 2018, 6:05 PM
Anna
Anna - avatar
+ 2
thankyou so much :)
21st Sep 2018, 8:34 AM
fadhlan pasyah
fadhlan pasyah - avatar
+ 1
thankyou very much :)
22nd Sep 2018, 3:24 AM
fadhlan pasyah
fadhlan pasyah - avatar
0
Anna i would like to ask a follow-up question. if the s changed into input like giving 2 number and operation in huge number, each n1 n2 op separated by an enter, i have tried to add the operation but the result is the python only calculate the first line i input. How do i command python to count each line according to each of given operation keyword?
21st Sep 2018, 10:44 AM
fadhlan pasyah
fadhlan pasyah - avatar
0
sorry, there was a mistake in my words so misunderstood happens :(. https://code.sololearn.com/c6XTXRGAI16w/?ref=app i tried to run this code and (ex.) 7 3 MUL works. but when i try to input: 7 3 MUL 4 8 SUM 9 3 DIV 6 6 SUB etc; the code just operate the top operation. how can i program it to read all lines from top to bottom and calculate one by one? it says that too many input to unpack if i tried the while True loop. expected result: 21 12 3 0
21st Sep 2018, 5:41 PM
fadhlan pasyah
fadhlan pasyah - avatar