From d23bbfdcf0ce1c80ac11167ef9fc9d4917b4fee9 Mon Sep 17 00:00:00 2001 From: sonniki Date: Sun, 6 Oct 2019 11:36:46 +0200 Subject: [PATCH] add yoda translator add the script to the projects list add requirements --- README.md | 1 + speak_like_yoda/README.md | 10 ++++++++++ speak_like_yoda/requirements.txt | 2 ++ speak_like_yoda/speak_like_yoda.py | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 speak_like_yoda/README.md create mode 100644 speak_like_yoda/requirements.txt create mode 100644 speak_like_yoda/speak_like_yoda.py diff --git a/README.md b/README.md index 77ccb3d..4d602b5 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,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) | |[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) | +|[Yoda-speak Translator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/speak_like_yoda)|[sonniki](https://github.com/sonniki) | ## How to use : diff --git a/speak_like_yoda/README.md b/speak_like_yoda/README.md new file mode 100644 index 0000000..dedbacf --- /dev/null +++ b/speak_like_yoda/README.md @@ -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. \ No newline at end of file diff --git a/speak_like_yoda/requirements.txt b/speak_like_yoda/requirements.txt new file mode 100644 index 0000000..733226a --- /dev/null +++ b/speak_like_yoda/requirements.txt @@ -0,0 +1,2 @@ +random +string \ No newline at end of file diff --git a/speak_like_yoda/speak_like_yoda.py b/speak_like_yoda/speak_like_yoda.py new file mode 100644 index 0000000..09a36c6 --- /dev/null +++ b/speak_like_yoda/speak_like_yoda.py @@ -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)