Quick actions

cmd+k|ctrl+k

Navigation

Languages

ex39_pyfml.py

Snippet info

Language

Python

Visibility

public

Author

cuongquach.learning

Created

2016-09-19T19:28:14Z

Updated

2016-09-19T19:28:27Z

# Exercise 3.9
# Pyfml course
# Name : Quach Chi Cuong
# Glot.io : https://glot.io/snippets/eilm6e2hd9
# Requirement :
# a, b, c la cac so nguyen duong nho hon 10 va ket qua tinh toan phai
# a + b/c = 10
# In ra list chua toan bo cac so thoa man dieu kien tren (a,b,c co the trung nhau)
# Vi du:
# - output: [[9, 1, 1], ...]

# Tao list ket qua rong.
lst_result = []

# Cho chay vong lap for 3 bien a,b,c deu duoi 10 theo yeu cau de bai
for a in range(0,10):
	for b in range(0,10):
		for c in range(0,10):
			
			# Neu c = 0 , thi b/0 se bi loi nen continue
			if c == 0:
				continue

			# Neu b % c , khong chia het cho c thi se ra so thap phan nen continue
			elif b % c != 0:
				continue
			else:
				# Neu ket qua cap 3 so a,b,c tinh toan = 10, thi lay cap ket qua hien tai luu vao list result
				result = a + (b / c)
				if int(result) == 10:
					lst_result.append([a,b,c])

print('Output: ', lst_result)
INFO