Python @ DjangoSpin

PyPro #51 Divisible by 9 but not multiples of 2

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

divisible by 9 but not multiples of 2 in Python

divisible by 9 but not multiples of 2 in Python

Divisible by 9 but not multiples of 2: Write a Python program to find all numbers lying between 0 and 200 which are divisible by 9 but are not multiples of 2. Print the output in the form of a comma-separated sequence.

Divisible by 9 but not multiples of 2

outputList = []

for number in range(0, 201):
	if (number % 9 == 0) and (number % 2 != 0):
		outputList.append(str(number))
	
print(', '.join(outputList))		# 9, 27, 45, 63, 81, 99, 117, 135, 153, 171, 189

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply