COMP 141-03 Fall 2013

Program 3: Palidrome Integers

50 Points

Assigned: Wednesday, October 2
Due: Wednesday, October 9, 2013 by 11:55pm

You will write a program that allows the user to input a positive integer and your program will output if that integer is a palindrome. This will be done using a loop and 3 functions to test your understanding of functions that return values as well as your understanding of loops. You should not use lists or string manipulation in this program as we have not covered those topics yet.

Program Specifications

This program requires you to use:

  • The input function to prompt the user.
  • The print function to output the results.
  • At least one loop
  • Boolean logic
  • Functions that return value(s)
  • Description

    A number is a palidrome if its reversal is the same as itself. For example, 121 is a palidrome.

    Your code needs to include 3 functions:

  • main() - prompts the user to enter a positive integer
  • reverse(number) - returns the reversal of an integer, e.g. reverse(456) returns 654
  • isPalindrome(number) - return true if a number is a palidrome and false otherwise
  • HINTS:
    main() needs to call isPalindrome and isPalidrome needs to call reverse
    Recall the in-class practice from 10/2 where we used % and // operators to extract individual digits from an integer - this will help you write the reverse function.

    Comments in your code

    Because I'm requiring you to write functions in this assignment, I'm adding additional mandatory comments. It is good practice to always describe your functions in terms of what they do, the input they take in and the output they produce.

  • For every function you write (except main), you must include a comment immediately before the function definition line that contains:

    Here's an example you'd use for a function that computes the circumference of a circle:

    	# This function computes the circumference of a circle.
    	# Parameters: r, the radius of the circle.
    	# Returns: the circumference of the circle.
    	def area_of_circle(r):
    	  return 2 * math.pi * r
    	

    An example of possible dialog with the user might be (user input is in italics):

    Example 1

    Enter a positive integer: 12345
    12345 is not palindrome.
    

    Example 2

    Enter a positive integer: 2345432
    2345432 is a palindrome.
    
    Your code does not need to follow this exact script, but all the mentioned functionality should work as shown.

    What to Do

  • Create a Python program named yourlastname_prg3.py
  • Include the standard program header at the top of your Python file.
  • Submit your Python file on Moodle under Program 3
  • Requirements

    When I examine your program, it must satisfy the following requirements. The maximum point value for each requirement is shown in brackets.

  • [3] Your program file is named correctly and it includes the standard program header.
  • [5] You must prompt the user to enter a number.
  • [5] You must output (in the main function) whether the inputted number is a palindrome or not.
  • [15] You must write a function that determines if a number is a palindrome and returns true if it is and false otherwise.
  • [17] You must write a function that returns the reversal of a number.
  • [5] You must comment your code appropriately (particularly your functions) and your code must be neatly and clearly formatted and include proper use of 'white space'.

  • Note: If your program doesn't run (i.e, has a syntax error), you may receive partial credit for the items listed above in bold.