Skip to content

Commit feeb243

Browse files
Speak like Yoda (avinashkranjan#986)
1 parent a86f418 commit feeb243

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Speak-like-Yoda/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Speak-Like-Yoda
2+
3+
## Description
4+
A python script that translates an input English sentence into Yoda-speak.
5+
6+
## Usage
7+
Run ```python speak_like_yoda.py```. Type in your sentence to get it translated into Yoda-speak.
8+
9+
## Requirements
10+
The script only uses Python's standard modules ```random``` and ```string```, so no additional installation is needed.
11+
12+
## Output
13+
```
14+
Your English sentence:
15+
Avoiding failure is something we learn at some later point in life.
16+
17+
Your Yodenglish sentence:
18+
Something is we point some failure learn avoiding later at in life
19+
20+
```
21+
22+
## Author(s)
23+
24+
[Soumik Kumar Baithalu](https://www.github.com/soumik2012)

Speak-like-Yoda/Speak_Like_yoda.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import random
2+
import string
3+
4+
def speak_like_yoda(sentence):
5+
"""
6+
Translate the input sentence into Yoda-speak.
7+
8+
:param sentence: input string
9+
:return: translation to Yoda-speak
10+
"""
11+
sentence = sentence.lower()
12+
for p in string.punctuation.replace("'", ''):
13+
sentence = sentence.replace(p, '')
14+
words = sentence.split()
15+
random.shuffle(words)
16+
new_sent = ' '.join(words)
17+
print('\nYour Yodenglish sentence: ')
18+
print(new_sent.capitalize())
19+
20+
if __name__ == '__main__':
21+
print('Your English sentence: ')
22+
sentence = str(input())
23+
speak_like_yoda(sentence)

Speak-like-Yoda/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
random
2+
string

0 commit comments

Comments
 (0)