Skip to content

Commit

Permalink
Merge pull request #107 from rishabhgupta03/CONTRIBUTION
Browse files Browse the repository at this point in the history
Contribution
  • Loading branch information
rishabhgupta03 authored Oct 4, 2020
2 parents e667292 + c16d4b0 commit e2b8563
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 1 deletion.
2 changes: 1 addition & 1 deletion HTML/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Java is a class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.
HTML (HyperText Markup Language) is a standard markup language for documents designed to be displayed in a web browser.
105 changes: 105 additions & 0 deletions Python/Translator/Translator.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Install translate from pip by running following command"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"pip install translate\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter the sentence you would like to translate : I love eating pizza\n",
"Enter the language to which you want sentence to be translated : hindi\n",
"मुझे पिज्जा खाना बहुत पसंद है\n"
]
}
],
"source": [
"#importing Translator \n",
"from translate import Translator\n",
"#taking inputs of sentence and language\n",
"sentence = input(\"Enter the sentence you would like to translate : \")\n",
"language = input(\"Enter the language to which you want sentence to be translated : \")\n",
"#creating Translator object\n",
"translator = Translator(to_lang= language)\n",
"translation = translator.translate(sentence)\n",
"#printing the translated sentence\n",
"print(translation)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Checking our translator with different language."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter the sentence you would like to translate : I love eating pizza\n",
"Enter the language to which you want sentence to be translated : german\n",
"Ich liebe es Pizza zu essen\n"
]
}
],
"source": [
"from translate import Translator\n",
"sentence = input(\"Enter the sentence you would like to translate : \")\n",
"language = input(\"Enter the language to which you want sentence to be translated : \")\n",
"translator = Translator(to_lang= language)\n",
"translation = translator.translate(sentence)\n",
"print(translation)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***You can test this translator by typing different languages***"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
5 changes: 5 additions & 0 deletions Python/Translator/Translator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**This Python code is about translating texts from english(by default) to various different languages with the help of Translate tool.**

**Translate is a simple but powerful translation tool written in python with support for multiple translation providers.**

**For detail study of translate tool, refer this [link](https://pypi.org/project/py-translate/)**.
23 changes: 23 additions & 0 deletions Python/fabonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Program to display the Fibonacci sequence up to n-th term

nterms = int(input("How many terms? "))

# first two terms
n1, n2 = 0, 1
count = 0

# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
25 changes: 25 additions & 0 deletions Python/hourglass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
arr = []

for _ in range(6):
arr.append(list(map(int, input().rstrip().split())))
maximum = -9 * 7

for i in range(6):
for j in range(6):
if j + 2 < 6 and i + 2 < 6:
result = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2]
if result > maximum:
maximum = result

print(maximum)
22 changes: 22 additions & 0 deletions Python/longest palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
t= int(input())
for k in range(t):
str=input()
substring=[]
for i in range(len(str)):
for j in range(i+1,len(str)+1):
substring.append(str[i:j])
pal=[]
for i in range(0,len(substring)):
temp=substring[i]
temp1=temp[::-1]
if (temp==temp1):
pal.append(temp)
max=""
for i in range(0,len(pal)):
if((len(pal[i])>len(max)) and (len(pal[i])>1)):
max=pal[i]
elif(len(max)<=1):
max=pal[0] #max=str[:1]
print(max)
substring.clear()
pal.clear()
19 changes: 19 additions & 0 deletions Python/web Socket/WebSocketClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import asyncio
import websockets

# method to send and reveive from the server
async def message():
async with websockets.connect("ws://localhost:1234") as socket:
while True:
msg = input("please say something")
await socket.send(msg)
reply = await socket.recv()
print(reply)
if 'ok closing' in reply:
break

asyncio.get_event_loop().run_until_complete(message())
#asyncio.get_event_loop().run_forever()



19 changes: 19 additions & 0 deletions Python/web Socket/WebSocketServer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import asyncio
import websockets

#crearing the method to receive the message and returns the reverse of the message
async def response(websocket, path):
while True:
message = await websocket.recv()
print(f"We got the message from the client: {message}")
if message == 'ok bye':
await websocket.send("ok closing")
break
await websocket.send(message[::-1])

# server starts in localhost at port 1234
start_server = websockets.serve(response, 'localhost', 1234)

#asyncio methods to start server and run forever
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()

0 comments on commit e2b8563

Please sign in to comment.