+ 1

Why isn't my code working ? Big latin using python

Here's my code : sen = input() words = sen.split() b = [] for i in range (len(words)): first_letter = words[i][0] sans_one = words[i].replace(words[i][0],"") if first_letter in ["a","e","u","i"] : big_latin = f"{sans_one }way" else : big_latin = f"{sans_one }{first_letter}ay" b=b+[big_latin] print (' '.join(word for word in b)) . . . . . . . . . . Instructions : 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"

22nd Oct 2021, 10:23 PM
Chaimae Belmaarouf
Chaimae Belmaarouf - avatar
3 ответов
+ 3
I'm not sure what you are trying to do. There are too many lines and conditions in your code. This one is it simplyfied: https://code.sololearn.com/c0omY10PbB55/?ref=app
22nd Oct 2021, 10:55 PM
Coding Cat
Coding Cat - avatar
+ 3
I am going to modify your code for your understanding sen = input() words = sen.split() b = [] for i in range (len(words)): first_letter = words[i][0] sans_one = words[i].replace(words[i][0],"",1)#Here big_latin = f"{sans_one }{first_letter}ay"#Here b=b+[big_latin] print (' '.join(word for word in b)) 1)There is no need to check for a e u i 2)replace , will replace all the entities in the word, you have to replace only first one . syntax: replace(oldvalue,newvalue,count) place count as 1 edit: a=input().split() print(' '.join(list(map(lambda x : x[1:]+x[0]+'ay',a)))) alternative
23rd Oct 2021, 2:32 AM
Prabhas Koya
+ 2
Chaimae Belmaarouf Try to simplify your concepts and look for functions that may assist you. This challenge is all about string manipulation -> slicing See if this helps you words = input().split(" ") #create list b = [] #empty list for i in range(len(words)): pig_latin = words[i][1:]+words[i][:1]+"ay" #string slice each item b.append(pig_latin) #add result to b print(" ".join(b)) #output
23rd Oct 2021, 1:37 AM
Rik Wittkopp
Rik Wittkopp - avatar