+ 1

About the printing function

Hi everyone, I faced some problems in understanding the indentation, for example: i = 0 while True: i = i +1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) print("Finished") The python sololearn playground will play the answer as: >>> 1 Skipping 2 3 4 Breaking Finished >>> But when I type the same thing in the python idle, it always shows the invalid syntax, such that I can only input something like this: >>> i=0 >>> while True: i=i+1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) 1 Skipping 2 3 4 Breaking >>> print("Finished") Finished >>> I am wondering how I can type the print("Finished") outside the while loop. It seems that click enter twice will directly run the loop and not allowing me to type the print function anymore. Would there be anyone can help me solve this problem?

2nd Feb 2020, 1:00 PM
Billy Lee
Billy Lee - avatar
10 Answers
+ 2
Billy Lee as I told you, it is because you are probably writing it wrong. A picture would be better for this kind of situations, if you can share a link here.
2nd Feb 2020, 2:01 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
You did not respect the indentation probably, you should leave a tab or space for all the statements executed inside the loop. Also, we can't know exactly what was written in the interpreter. Try to write it clearer, so we can get a better idea of where the problem might be.
2nd Feb 2020, 1:19 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
I don't see ant errors in your code, it should work fine. Can you write it in the code playground and share it ?
2nd Feb 2020, 1:28 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
I just copied the first part of your code, and it ran great. Isn't this what you want ? https://code.sololearn.com/cgWPp0EOayuw/?ref=app
2nd Feb 2020, 1:50 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Billy Lee that's weird, I tried the exact same syntax on my computer to make sure it was correct, and didn't get any errors at all.
2nd Feb 2020, 2:28 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
Oh sorry I copy it without making the identation, it should be like this: i=0 >>> while True: i=i+1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) 1 Skipping 2 3 4 Breaking >>> print("Finished") Finished >>> And the result is I still cannot type all the line and have to break it to two parts, so I would like to know if I can type in python idle and making all the code is like: i = 0 while True: i = i +1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) print("Finished")
2nd Feb 2020, 1:26 PM
Billy Lee
Billy Lee - avatar
0
I have typed the problem in the playground and makes it be public file=( Hope you can understand what I was talking (I apologize for my poor english)
2nd Feb 2020, 1:40 PM
Billy Lee
Billy Lee - avatar
0
No, I would like to know why I get the invalid syntax when typing the same code in python idle... I know it can work in the playground, but it does not work in the python idle... anyway thank you for your help lol
2nd Feb 2020, 1:53 PM
Billy Lee
Billy Lee - avatar
0
https://ibb.co/Wn9rKQk Thank you very much!!!!!!!! orz
2nd Feb 2020, 2:16 PM
Billy Lee
Billy Lee - avatar
0
Okay then ...=( Thank you for your answer
2nd Feb 2020, 2:31 PM
Billy Lee
Billy Lee - avatar