Question

In: Computer Science

IN PYTHON INF 120 – Project #6.5 In project 6.5 we are going to create a...

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.

Solutions

Expert Solution

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:


Related Solutions

(Python or C++) We are going to implement the following scheduling algorithms that we discussed in...
(Python or C++) We are going to implement the following scheduling algorithms that we discussed in class: 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with different quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the...
IN SWIFT LANGUAGE In this lab we are going to create a game that uses all...
IN SWIFT LANGUAGE In this lab we are going to create a game that uses all the different types of control flow operators that exist in SWIFT LANGUAGE. The game will be a choose your own adventure game. The user will have to answer a series of questions and this will change the path of a story. This must be done by using if/else statements that are nested within other if/else statements. Your story must have four (4) different possible...
create a project and in it a class with a main. We will be using the...
create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?"); int w = scan.nextInt();...
In this project we are going to model the Ball Toss with a quadratic function. So...
In this project we are going to model the Ball Toss with a quadratic function. So at 30 cm intervals, we draw 4 vertical lines extending from the eraser tray to the top of the marker board. We number the lines with their distances from the left most vertical line (which serves as the y-axis).Each of our volunteers selects a line and stand facing it at close proximity to the board. Between the board and the volunteers, I toss the...
JAVA PLEASE In this project, we are going to build a tiny database organized as a...
JAVA PLEASE In this project, we are going to build a tiny database organized as a singly linked list for storing and retrieving the information of a group of products on sale. The information of each product includes the following items: Product ID, Name, Seller, Quantity In Stock, Average Shipping Time, Original Price, Current Price. We assume that a node in the linked list should be defined by the following class. class Product {      long ID;      String name;...
You are going to invest in a stock mutual fund with a front-end load of 6.5...
You are going to invest in a stock mutual fund with a front-end load of 6.5 percent and an expense ratio of 1.37 percent. You also can invest in a money market mutual fund with a return of 2.7 percent and an expense ratio of 0.20 percent. If you plan to keep your investment for 2 years, what annual return must the stock mutual fund earn to exceed an investment in the money market fund? What if your investment horizon...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
Python we need to create a game using only the library graphic.py and use only Structure...
Python we need to create a game using only the library graphic.py and use only Structure Functions only.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT