Merge pull request #83 from sonniki/yoda-speak

add yoda translator
This commit is contained in:
Ayush Bhardwaj 2019-10-07 12:46:48 +05:30 committed by GitHub
commit 537132d254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 0 deletions

View File

@ -62,6 +62,7 @@ So far, the following projects have been integrated to this repo:
|[CLI Calculator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/cli_calculator)|[Willian GL](https://github.com/williangl) | |[CLI Calculator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/cli_calculator)|[Willian GL](https://github.com/williangl) |
|[Find PhoneNumber in String](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Find-PhoneNumber-in-String)|[Austin Zuniga](https://github.com/AustinZuniga)| |[Find PhoneNumber in String](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Find-PhoneNumber-in-String)|[Austin Zuniga](https://github.com/AustinZuniga)|
|[IMDB TV Series Info Extractor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/imdb_episode_ratings)|[Yash Raj Sarrof](https://github.com/yashYRS) | |[IMDB TV Series Info Extractor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/imdb_episode_ratings)|[Yash Raj Sarrof](https://github.com/yashYRS) |
|[Yoda-speak Translator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/speak_like_yoda)|[sonniki](https://github.com/sonniki) |
## How to use : ## How to use :

10
speak_like_yoda/README.md Normal file
View File

@ -0,0 +1,10 @@
# Speak-Like-Yoda
## Description
A python script that translates an input English sentence into Yoda-speak.
## Usage
Run ```python speak_like_yoda.py```. Type in your sentence to get it translated into Yoda-speak.
## Requirements
The script only uses Python's standard modules ```random``` and ```string```, so no additional installation is needed.

View File

@ -0,0 +1,2 @@
random
string

View File

@ -0,0 +1,24 @@
import random
import string
def speak_like_yoda(sentence):
"""
Translate the input sentence into Yoda-speak.
:param sentence: input string
:return: translation to Yoda-speak
"""
sentence = sentence.lower()
for p in string.punctuation.replace("'", ''):
sentence = sentence.replace(p, '')
words = sentence.split()
random.shuffle(words)
new_sent = ' '.join(words)
print()
print('Your Yodenglish sentence:')
print(new_sent.capitalize())
if __name__ == '__main__':
print('Your English sentence:')
sentence = str(input())
speak_like_yoda(sentence)