-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS7-pigLatin.py
More file actions
77 lines (59 loc) · 2 KB
/
S7-pigLatin.py
File metadata and controls
77 lines (59 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
This program takes the first letter of every word,
move it to the end of the word and add ‘ay’
Author: Aditya Nain
Date: 01/23/2019
"""
"""
************pseudocode***********
take user input as string
convert string to lower case
create a list "ls" of words using split by whitespaces
initialise ls_letter[]....this will store letters
initialise ls_new[]
for words in ls..................loop through individual words
for letters in words.........loop through individual letters in those words
add letters to ls_letter
retrieve first letter using slice and add it to a new list "y"
delete the first letter from ls_letter
append y[0] to ls_letter
append "ay" to ls_letter
join letters to create word using join()
append newly created words to ls_new
clear ls_letter tp process the next word
join the words seperated by space to form a new sentence using join()
print the sentence to screen
"""
#take user input
st = input("Type a statement and press enter to translate to piglatin : \n")
#convert to lowercase
st = st.lower()
#create a list
ls = st.split(" ")
#initialise empty lists
ls_letter = []
ls_new = []
#loop through every word
for word in ls:
#loop through every letter in each word one by one
for letter in word:
#add letter to a list
ls_letter.append(letter)
#retrieve the first letter and store it in list y
x = slice(1)
y= ls_letter[x]
#delete the first letter
del ls_letter[0]
#add the first letter taken out at the last of ls_letter
ls_letter.append(y[0])
#add "ay" to the end of ls_letter
ls_letter.append("ay")
#join letters to form words and create a list
z = "".join(ls_letter)
ls_new.append(z)
#empty ls_letter for processing of the next word
ls_letter.clear()
#join words to create sentence
pig_latin = " ".join(ls_new)
#print sentence to screen
print(pig_latin)