forked from vandanagarg/practice_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslator
More file actions
48 lines (36 loc) · 1.28 KB
/
translator
File metadata and controls
48 lines (36 loc) · 1.28 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
#Tanslator
#Lets's say Giraffe Language
#vowels --> g # in place of vowels g should come
#create a translate function
def translate (phrase):
translation = ""
for letter in phrase:
if letter in "AEIOUaeiou": # or we can even use: if letter.lower() in "aeiou":
translation = translation + "g"
else:
translation = translation+ letter
return translation
print(translate(input("Enter a phrase: ")))
o/p
C:\Users\as\Anaconda3\envs\Giraffe\python.exe C:/Users/as/PycharmProjects/Giraffe/app.py
Enter a phrase: to be or not to be
tg bg gr ngt tg bg
Process finished with exit code 0
# but the above programm doesn't handle the upper case so lets modify it with one more if else
def translate (phrase):
translation = ""
for letter in phrase:
if letter.lower() in "aeiou":
if letter.isupper():
translation = translation + "G"
else:
translation = translation + "g"
else:
translation = translation+ letter
return translation
print(translate(input("Enter a phrase: ")))
o/p
C:\Users\as\Anaconda3\envs\Giraffe\python.exe C:/Users/as/PycharmProjects/Giraffe/app.py
Enter a phrase: On the spot, we went.
Gn thg spgt, wg wgnt.
Process finished with exit code 0