Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. Write a function with the following header
  2.  
  3. def reverseDigits(n) :
  4.  
  5. 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.
  6.  
  7. 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.
  8.  
  9. Question 2 (30 marks)
  10.  
  11. Write a function with the following header
  12.  
  13. def threeDigits() :
  14.  
  15. 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.
  16.  
  17.  
  18. Question 3 (30 marks)
  19.  
  20. Write a function with the following header
  21.  
  22. def f1089(n) :
  23.  
  24. The function f1089 carries out the following calculations.
  25. i) m = n-reverseDigits(n)
  26. ii) p = m+reverseDigits(m)
  27. The value of p is returned. Place a short explanatory comment immediately before the definition of f1089.
  28.  
  29. 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