Write a function named num_test that takes a number as input. If the number is greater than 10, the function should return βGreater than 10.β If the number is less than 10, the function should return βLess than 10.β If the number is equal to 10, the function should return βEqual to 10.β
Checkpoint8.14.2.
Write a function that will return the number of digits in an integer.
Write a function that removes all occurrences of a given letter from a string.
Checkpoint8.14.6.
Write a function replace(s, old, new) that replaces all occurences of old with new in a string s:
test(replace('Mississippi', 'i', 'I'), 'MIssIssIppI')
s = 'I love spom! Spom is my favorite food.
Spom, spom, spom, yum!'
test(replace(s, 'om', 'am'),
'I love spam! Spam is my favorite food.
Spam, spam, spam, yum!')
test(replace(s, 'o', 'a'),
'I lave spam! Spam is my favarite faad.
Spam, spam, spam, yum!')
Hint: use the split and join methods.
Checkpoint8.14.7.
Write a function findHypot. The function will be given the length of two sides of a right-angled triangle and it should return the length of the hypotenuse. (Hint: x ** 0.5 will return the square root, or use sqrt from the math module)
Checkpoint8.14.8.
Write a function called is_even(n) that takes an integer as an argument and returns True if the argument is an even number and False if it is odd.
Checkpoint8.14.9.
Now write the function is_odd(n) that returns True when n is odd and False otherwise.
Checkpoint8.14.10.
Write a function is_rightangled which, given the length of three sides of a triangle, will determine whether the triangle is right-angled. Assume that the third argument to the function is always the longest side. It will return True if the triangle is right-angled, or False otherwise.
Hint: floating point arithmetic is not always exactly accurate, so it is not safe to test floating point numbers for equality. If a good programmer wants to know whether x is equal or close enough to y, they would probably code it up as
if abs(x - y) < 0.001: # if x is approximately equal to y
...