2. Basic logic statements in Python

It can be said that any programming language is built on logic statements like "if...else..." "for loop", and Python is no exception

These are the various entry-level sentences

while loop

a, b = 0, 1
while b < 10:
	print(b,end=',')
	a, b = b, a+b

for loop

print('\nQuestion: How many three-digit numbers can be composed of 1, 2, 3, and 4 numbers that are different from each other and have no repeating numbers? How many are all!')
print('Program analysis: The numbers that can be filled in the hundreds, tens, and ones are 1, 2, 3, and 4. After forming all the permutations, remove the permutations that do not meet the conditions.')
print('Program source code:')

d = []
for i in range(1,5):
	for j in range(1,5):
		for k in range(1,5):
			if(i != k) and (i != j) and (j != k):
				d.append({i,j,k})
print("Total number: ", len(d))
print(d,'\n')

break continue usage

for n in range(2, 12):
	for x in range(2,n):
		if n % x == 0:
			print(n, 'equals', x, '*', n//x)
			break
	else:
		# loop fell through without finding a factor
		print(n, 'is a prime number\n')

for num in range(2, 10):
	if num % 2 == 0:
		print("Found an even number", num)
		continue
	print("Found a number", num,'\n')

pass statement

class MyEmptyClass:
	pass
def initlog(*args):
	pass

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325644358&siteId=291194637