0

num= int(input("Enter any number:")) f = 0 i = 2 while i <= num/2: if num%i == 0: f=1 break i+=1 if f == 0: print(" it is a Prime Number") else: print(" is Not a Prime Number")

18th Jan 2019, 11:28 AM
Nikhil
+ 6
Indentation works like this: If one line ends with a colon (:), start the next line with four more spaces. Like this: if condition: #(1) do_something() #(2) while condition2: #(3) print() #(4) (1) this line ends with a colon (:) (2) so this line is indented (3) this line ends with another colon (4) so this line is even more indented Two lines that belong together logically, like "if" and the corresponding "else", have to be on the same indentation level: if condition: #(5) do_something() #(6) do_something_2() #(7) else: #(8) do_something_else() #(9) (5) if clause (6) indented (7) same indentation level as line before: (6) and (7) belong together and will both be executed if condition (5) is True (8) "else" belongs to "if" -> needs to be on same indentation level (9) indented >> EVERYTHING ELSE is wrong. This is wrong: if condition: do_something() do_something_2() # indentation error This is wrong: if condition: do_something() else: # error: not on same level as "if" do_something_else() This is wrong: do_something() do_something_2() # indentation error, can't change indentation level for no reason
18th Jan 2019, 1:41 PM
Anna
+ 4
Indentation is the most fundamental knowledge of Python Try putting your code in code playground for our inspection on your indentation
18th Jan 2019, 11:34 AM
Gordon
+ 3
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2277/ The explanation is in the yellow box. When the lines have the same number of space at the beginning of each line, they are considered, for example in C++(i saw you finished C++), in the same code block enclosed by the paired brackets { }.
18th Jan 2019, 11:37 AM
Gordon
18th Jan 2019, 11:48 AM
Nikhil
+ 1
Don't indent line 4 Line 7 should be same indented as line 6 Line 8 should be same indented as line 5 Line 9 shouldn't be indented Line 11 should be same indented as line 9, in this case not indented Fix these 5 and your code should work. Let me know if you don't understand after you corrected your code.
18th Jan 2019, 12:13 PM
Gordon
+ 1
Thank you guys for your help my code successfully runs without any error. I am new to python I had done c++ that's why I am suffering this type of error as in c++ we put semicolon and extra brackets. well thanks for your help
18th Jan 2019, 3:25 PM
Nikhil
0
Ok
18th Jan 2019, 11:35 AM
Nikhil
0
I know but error is still there can anyone write the code of finding prime number using while loop using python and then send here. this prime number logic is fully working in c++ but in python I am getting error.
18th Jan 2019, 11:39 AM
Nikhil
0
You put it in code playground first, and use the + button beside the send button to post the link of your code here.
18th Jan 2019, 11:42 AM
Gordon
0
Oh ok
18th Jan 2019, 11:44 AM
Nikhil
0
Ahmad chitsazzade thanks I corrected it and i got my code without any error.
19th Jan 2019, 10:56 AM
Nikhil
- 1
no it's not correct for example enter 1001 Of course, if you put your code in the playground, we could be better able to help, because the code of its distances is meaningless.
18th Jan 2019, 9:02 PM