+ 2

PIG LATIN

Heres what I came up with it is just something I threw on the table x= input('').split() for i in range(len(x)): x = x[i] + x[i][0] + 'ay' x= [i[7:] for i in x] i+=1 break message='' message +=message.join(x)

10th May 2020, 1:50 PM
ACID
ACID - avatar
20 Answers
+ 8
Why are you using the number 7?
10th May 2020, 3:31 PM
David Ashton
David Ashton - avatar
+ 8
Here is how I did it:- x="" for i in input().split(): x += i[1:] + i[0:1] + "ay " print (x)
26th May 2020, 8:24 PM
pranay sharma
pranay sharma - avatar
+ 5
Paulina Kowalczyk , the reason why only the first word is processed is the *return* statement in the function, that terminates the function after the first word is done. to avoid this behavior, we can implement a *list* as a buffer that can hold all the processed words. after the for loop is done, we can return the list back to the caller.
20th Aug 2022, 3:36 PM
Lothar
Lothar - avatar
+ 4
Jan Kowalski , just allow me a friendly comment from my side about your code: ▪︎when using input(), the result always will be a string by default, so you can omit str() ▪︎when using split() with a whitespace as separator like split(" "), you will run in problems if there are 2 or more consecutive spaces between two words. by giving this as input: "hello sololearn" (3 spaces are used), the resulting list is ['hello', '', '', 'sololearn']. from the 3 spaces one is consumed by the split function, the other two will be stored as an empty string with a length of 0. when applying a slice on these empty strings python will throw an error: "Index out of range" so the preferred way of handling the input in this case will be: sentence = input().split() happy coding!
20th Jun 2021, 12:58 PM
Lothar
Lothar - avatar
+ 3
I did: sentence = input() senl = sent.split(" ") for word in x: word = word + word[0] print(word[1:-1] + word[0] + "ay", end = " ")
30th Jan 2021, 2:19 AM
tom
tom - avatar
+ 3
Lothar That's great information. I always preferred split() over split(" ") just because it's simpler. I didn't realize they were different. This code proves it, just as you said https://code.sololearn.com/cdYYB9gE0aH8 I see that's in the Python docs https://docs.python.org/3/library/stdtypes.html#str.split https://stackoverflow.com/questions/62013468/is-there-a-difference-between-split-vs-split
20th Jun 2021, 1:28 PM
David Ashton
David Ashton - avatar
+ 2
Check my solutions i think that will help . I always use simple things. (Easy to understand)
10th May 2020, 4:31 PM
Yash Jain
Yash Jain - avatar
+ 2
pig_latins = str(input()).split() for pig_latin in pig_latins: print(pig_latin [1:] + pig_latin[0] + "ay", end = " ")
15th Dec 2021, 5:41 AM
Samnith Vath
Samnith Vath - avatar
+ 1
Pig latin
10th May 2020, 1:56 PM
ACID
ACID - avatar
+ 1
I keep on get a errror
10th May 2020, 1:56 PM
ACID
ACID - avatar
+ 1
You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in the same order except that you take the first letter of each word and put it on the end, then you add 'ay' to the end of that. ("road" = "oadray") Task Your task is to take a sentence in English and turn it into the same sentence in Pig Latin! Input Format A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization) Output Format A string of the same sentence in Pig Latin. Sample Input "nevermind youve got them" Sample Output "evermindnay ouveyay otgay hemtay"
10th May 2020, 1:57 PM
ACID
ACID - avatar
+ 1
Pls help
10th May 2020, 1:57 PM
ACID
ACID - avatar
+ 1
The first line of the code is ok, but the rest does not solve the task. It's just as you mentioned: Thrown on the table, but can not be used as it is. Sorry to say. I think that you should learn the basics of python again.
10th May 2020, 3:18 PM
Lothar
Lothar - avatar
+ 1
Thank I fixed
10th May 2020, 5:32 PM
ACID
ACID - avatar
+ 1
Pig Latin solution without end()function: sentence = (str(input())).split(" ") new_sentence = "" n = "" for word in sentence: n = (word[1::]+word[0]+"ay ") new_sentence += n print(new_sentence) While solving this problem, I just got to know the end () function
17th Jun 2021, 7:15 PM
Przemysław Komański
Przemysław Komański - avatar
+ 1
Thanks for explaining this!
21st Aug 2022, 8:49 AM
Paulina Kowalczyk
Paulina Kowalczyk - avatar
0
Why my code printing only first word in sentence?? sent = input ().split() def piglatin(w): for w in sent: return w[1:] + w[0] + "ay" print(piglatin(sent)) 🙏 help
20th Aug 2022, 3:02 PM
Paulina Kowalczyk
Paulina Kowalczyk - avatar