Question

. Write a function in python that accepts a sentence as the argument and converts each...

. Write a function in python that accepts a sentence as the argument and converts each word to “Pig Latin.” In one version, to convert a word to Pig Latin, you remove the first letter and place that letter at the end of the word. Then you append the string “ay” to the word. Here is an example: English: I SLEPT MOST OF THE NIGHTPIG LATIN: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY.

Homework Answers

Answer #1

def Pig_latin(sentence):
# to extract words from string
word = sentence.split()
new_sentance=""
  
for i in range(len(word)):
temp=word[i]
#swap word
a=temp[0] #first character of word
b=temp[1:]+a #place fisrt chracter to last
word_fin=b+"AY "
new_sentance=new_sentance+word_fin;
print(new_sentance)   
  
Pig_latin("I SLEPT MOST OF THE NIGHT")

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
In Python: Problem 5] Write a function that accepts a list as argument and returns a...
In Python: Problem 5] Write a function that accepts a list as argument and returns a list that contains: (1) The positive elements of the taken list (2) The negative elements of the taken list (3) The odd elements of the taken list (4) The even elements of the taken list
Write a function that takes as input an English sentence (a string) and prints the total...
Write a function that takes as input an English sentence (a string) and prints the total number of vowels and the total number of consonants in the sentence. The function returns nothing. Note that the sentence could have special characters such as dots, dashes, and so on. write a python program please.
Write a function that accepts a line of text and a single letter as input (case...
Write a function that accepts a line of text and a single letter as input (case insensitive) and returns the number of times the letter is the first character of a word. Note your program should be able to handle different cases. And check if the user input is a single letter. Example: Input text = "When the SUN rises at dawn, the chicken flies into the window." Input letter = "t" Output = "The letter t has appeared 3...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
python code Write the function definition for a function which accepts one value from the main...
python code Write the function definition for a function which accepts one value from the main program and prints three times the number that is sent to it. For example, if the program sent 8, the function would print 24.
Python The capitalize function should receive a word as a parameter in the form of a...
Python The capitalize function should receive a word as a parameter in the form of a string and return one version where the first character is written in capital letters. Other characters must be unchanged. For example ‘hey’ become ‘Hey’. Write the function clearly. Consider that str has the method upper that returns a new string where all characters are capitalized
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum number in the list. Do NOT use Python’s built-in function max. Example: result = myMax([-999000, -1000000, -2000000]); print(result) #output is -999000 Example: result = myMax([1000000, 1000001, 1000002]); print(result) #output is 1000002
Write a program in python reverse each and every word of the sentence using function taking...
Write a program in python reverse each and every word of the sentence using function taking string as input parameter from user and passing that string into function and also explain the logic ======================================= input: 'Exam is gonna be good' output: 'maxE si annog eb doog' ================ i am trying like this but getting confused '.'join([w::-1] for w in s.split()]) i need more focus on explanations because it is making me confuse i am not clear with concepts so please...