Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write a function with the following header
- def reverseDigits(n) :
- The parameter n is a positive integer with three decimal digits. The function reverseDigits returns the integer obtained by reversing the digits of n. For example if n has the value 631 then the returned integer is 136. Place a short explanatory comment immediately before the definition of reverseDigits.
- Make five calls to reverseDigits to test the code. Use print to display the results in the Shell. Include in each print statement a short description of the meaning of the print out.
- Question 2 (30 marks)
- Write a function with the following header
- def threeDigits() :
- The function threeDigits prompts the user to enter a three digit integer such that the individual digits are strictly decreasing from left to right. This integer is returned by threeDigits. Place a short explanatory comment immediately before the definition of threeDigits.
- Question 3 (30 marks)
- Write a function with the following header
- def f1089(n) :
- The function f1089 carries out the following calculations.
- i) m = n-reverseDigits(n)
- ii) p = m+reverseDigits(m)
- The value of p is returned. Place a short explanatory comment immediately before the definition of f1089.
- Carry out the following test five times: use the function threeDigits to input a number n, make the function call f1089(n) and then print the value returned by the function call in the Shell. Add to your code a comment on the five returned values.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement