+ 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)
17 Antworten
+ 8
Why are you using the number 7?
+ 8
Here is how I did it:-
x=""
for i in input().split():
x += i[1:] + i[0:1] + "ay "
print (x)
+ 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.
+ 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!
+ 3
I did:
sentence = input()
senl = sent.split(" ")
for word in x:
word = word + word[0]
print(word[1:-1] + word[0] + "ay", end = " ")
+ 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
+ 2
Check my solutions i think that will help .
I always use simple things. (Easy to understand)
+ 2
pig_latins = str(input()).split()
for pig_latin in pig_latins:
print(pig_latin [1:] + pig_latin[0] + "ay", end = " ")
+ 1
Pig latin
+ 1
I keep on get a errror
+ 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"
+ 1
Pls help
+ 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.
+ 1
Thank I fixed
+ 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
+ 1
Thanks for explaining this!
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