PYTHON code runs were IndentationError: unindent does not match any outer indentation level and the card does not move in there

 table of Contents

A code and error shots;

Second, analyze the reasons and solutions;

Third, the correct code format;

 

Here is the code and error screenshots

Code

# -*- coding: utf-8 -*-
n = 1
while n <= 100:
	if n > 10:
		break
		print(n)
		n = n + 1
		print('end')

Error Screenshot

This error code: (unindent does not match any outer indentation level IndentationError) appears; Screenshot 1

Screenshot 2 (Fixed then stuck I ctrl + c be terminated);

Cause Analysis:

Python is a cable block incoming category code, so write only when n is greater than 10 will enter if the segment (from line 5 to line 8, comprising n = n + 1 line), and in addition if the loop portion no other parts of the code block, i.e. the value of n does not change (increase or decrease), while the body of the loop as long as n is less than or equal to 100 will not exit the loop, so that, when the program runs, it will have been trapped in the while loop body.

The correct format:

# -*- coding: utf-8 -*-
n = 1
while n <= 100:
	if n > 10:
		break
	print(n)
	n = n + 1
print('end')

Results are as follows:

Published 153 original articles · won praise 15 · Views 150,000 +

Guess you like

Origin blog.csdn.net/beyond911/article/details/104095762