In: Computer Science
IN PYTHON
INF 120 – Project #6.5
In project 6.5 we are going to create a program and test cases to test each path/branch through the program.
Our program is going to get a word from the user and check if it is a palindrome. If it is it will output to the user that it is a palindrome. A palindrome is where the word is the same forwards as backwards.
For example racecar.If the word isn’t a palindrome then we will “translate” the word to pig Latin according to the following rules.1. If the word begins with a consonant move the 1st letter to the end of the word and then append “ay”. So dog becomes ogday.2. If the words begins with a vowel just add “ay” to the end of the word. So elk becomes Elkay.
Write your program and get it working.
Answer the following questions about your program.
1. How many paths/branches are in your program.
2. For each path/branch in your program craft a test case.
3. Run your program with each test case and screenshot the result and include them as the answer to this question.
1. There are 2 if else branches and 2 paths for different function in the code.
2. For the first branch, we have the following test cases:
racecar : word is palindrome
dog: begins with a consonant
erk: begins with a vowel
3. Result below:
Code:
def isVowel(c):
return (c == 'A' or c == 'E' or c == 'I' or
c == 'O' or c == 'U' or c == 'a' or
c == 'e' or c == 'i' or c == 'o' or
c == 'u');
def isPalindrome(s):
return s == s[::-1]
def main():
s = input('Enter a word : ')
if isPalindrome(s):
print('The word is palindrome')
else:
if(isVowel(s[0])):
print(s+'ay')
else:
print(s[1:]+s[0]+'ay')
if __name__ == "__main__":
main()
Code screenshot:
Output for various test cases: