+ 2
Pig Latin
Pig Latin is a problem where you should replace all the words in the sentence in Pig Latin. You should move your first Alphabet of each word to the end of it, and put ‘ay’ in the end. sent = input().split() latin = [] for i in sent: i += 'xay' p = i.replace(i[len(i)-3], i[0]) p = p.replace(p[0], "") latin += [p] final = " ".join(latin) print(final) This is my code, and when I put ‘go over there’, it prints ‘oay veray hereay’ when it should print ‘ogay veroay heretay’. Please help
9 Respuestas
+ 7
Your use of replace() is causing all sorts of problem.
Words with multiple letters have all those letters removed, which does not meet challenge requirements.
Please review the following solution using string slices and concatenation.
It is a simpler concept
sent = input().split()
latin = []
for i in sent:
latin.append(i[1:]+i[0]+"ay")
print(" ".join(latin))
+ 3
Rik Wittkopp you just saved me man thank you!
+ 1
sentence = input()
my_str = list(sentence.split())
pig_latin = []
for x in my_str:
pig_latin.append(x[1::] + x[0] + "ay")
print(" ".join(pig_latin))
0
here is my code
0
how is my cod?
txt=input().split(" ")
wordlist=[]
for word in txt:
word = word[1:]+word[0]+"ay"
wordlist.append(word)
print(" ".join(wordlist))
0
n=input()
x=n.split()
v=""
for i in x:
v+=i[1:]+i[0]+'ay '
print(v)
0
latin = input()
latin_list = latin.split(" ")
word = ""
word_list = []
pig_word = ""
pig_word_list = []
for i in range(len(latin_list)):
word = latin_list[i]
for n in range(len(word)):
first_letter = word[0]
word_list = list(word[1:])
word_list.append(first_letter + "ay" + " ")
pig_word_list += (word_list[n])
pig_words = "".join(pig_word_list)
print(pig_words)
0
#include <stdio.h>
#include <string.h>
int main() {
char a[100];
char b[100] = "";
int j = 0;
fgets(a, sizeof(a), stdin);
for (int i = 0; a[i]; i++) {
if (a[i] == ' ' || a[i] == '\n') {
if (j > 1) {
char lastChar = b[j - 1];
for (int k = j - 1; k > 0; k--) {
b[k] = b[k - 1];
}
b[0] = lastChar;
b[j] = 'a';
b[j + 1] = 'y';
b[j + 2] = '\0';
}
printf("%s ", b);
j = 0;
b[0] = '\0';
} else {
b[j] = a[i];
j++;
b[j] = '\0';
}
} //for c users
return 0;
}