+ 1

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

3rd Dec 2021, 9:48 AM
Nordo Fin
Nordo Fin - avatar
5 Answers
+ 3
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))
3rd Dec 2021, 10:29 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
[user id=12572725]Rik Wittkopp[/user] you just saved me man thank you!
4th Dec 2021, 12:03 AM
Nordo Fin
Nordo Fin - avatar
0
here is my code
18th Jul 2022, 3:24 PM
Lwin Phyoe
0
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))
18th Jul 2022, 3:24 PM
Lwin Phyoe
0
import java.util.*; public class PigLatin { public static void main(String[] args) { try { Scanner scan = new Scanner(System.in); String Line = scan.nextLine(); String words[] = Line.split(" "); String Final = ""; for (String modify : words) { char tu[] = modify.toCharArray(); Final += (modify.substring(1) + tu[0] + "ay "); } System.out.println(Final); scan.close(); } catch (Exception error) { System.out.println("Error occured"); } } } //my solution for java users
20th Nov 2022, 7:56 AM
Isuru
Isuru - avatar