Lecture Notes on 3 Jul 2013
Let num be an int.
* Write a boolean expression that evaluates to True if num is even.
num % 2 == 0
* Write a boolean expression that evaluates to True if num is a four
digit number that is divisible by 13.
(num >= 1000) and (num <= 9999) and (num % 13 == 0)
* Write a boolean expression that evaluates to True if num is not a
multiple of 12.
num % 12 != 0
* Write a boolean expression that evaluates to True if num is not
a three digit number and is not a factor of 120.
((num < 100) or (num > 999)) and (120 % num != 0)
# Computes the Pythagorean triples less than 100
def main():
num_iter = 0
num_triples = 0
for c in range (100, 1, -1):
for b in range (c - 1, 0, -1):
for a in range (b, 0, -1):
num_iter += 1
if (a * a + b * b == c * c):
num_triples += 1
print (a, b, c)
print ("Number of iterations = ", num_iter)
print ("Number of triples = ", num_triples)
main()