What's the coolest thing you've ever done using Python?

+6 votes

Python is a very versatile programming language and can be used in almost any field today. So, unsurprisingly, people all around the world have managed to build extraordinary games, applications, projects, and software on Python.

Edureka community would like to give you the opportunity to showcase your Python knowledge and your ability to build something awesome.

Post your coolest Python code here and get a chance to win the Edureka t-shirt and a self-paced course.

The deadline for submissions is 25th December 2019

Nov 21 in Python by Edureka
• 1,920 points
163 views

4 answers to this question.

+2 votes
I have made a Flask chatbot using python's Chatterbot library that responds to the questions in the template.

I have also made a speech to text, model using the python's speechrecognition library that takes speech as input and also opens a webpage using the query taken from the speech.
answered Nov 22 by Mohammad
• 3,170 points
Hi @Mohammad, can you please share the code or your GitHub repo, wherever the code exists.

You need to either show the code or the screenshots of your app to qualify for this contest.
0 votes

As a kid, I am sure everybody has played the famous snake game. As a matter of fact, it was one of the first mobile games that came into the market. Wouldn’t it be cool to build it by yourself? Hell Yeah! I have used Python’s Turtle Module to build the game from scratch.

There are two elements in this game – snake and food. The player has to move the snake such that it touches(eats) the food and grows in size. The snake dies if it touches its own body or the boundaries of the window. On an obvious note, the player needs to win and hence avoid dying.

import turtle
import time
import random

delay = 0.1

# score
score = 0
high_score = 0

#set up the screen
wn = turtle.Screen()
wn.title("snake game")
wn.bgcolor("blue")
wn.setup(width=600, height=600)
wn.tracer(0)

#Snake Head
head = turtle.Turtle()
head.speed(0)
head.shape("square")
head.color("black")
head.penup()
head.goto(0, 100)
head.direction = "stop"

# Snake food
food = turtle.Turtle()
food.speed(0)
food.shape("circle")
food.color("red")
food.penup()
food.shapesize(0.50, 0.50)
food.goto(0, 0)

segments = []

pen = turtle.Turtle()
pen.speed(0)
pen.shape("square")
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, 260)
pen.write("Score: 0 High Score: {}".format(high_score), align="center", font=("Courier", 24, "normal"))

# Functions

def go_up():
    if head.direction != "down":
        head.direction = "up"

def go_down():
    if head.direction != "up":
        head.direction = "down"

def go_right():
    if head.direction != "left":
        head.direction = "right"

def go_left():
    if head.direction != "right":
        head.direction = "left"


def move():
    if head.direction == "up":
        y = head.ycor() #y coordinate of the turtle
        head.sety(y + 20)

    if head.direction == "down":
        y = head.ycor() #y coordinate of the turtle
        head.sety(y - 20)

    if head.direction == "right":
        x = head.xcor() #y coordinate of the turtle
        head.setx(x + 20)

    if head.direction == "left":
        x = head.xcor() #y coordinate of the turtle
        head.setx(x - 20)

# keyboard bindings
wn.listen()
wn.onkey(go_up, "w")
wn.onkey(go_down, "s")
wn.onkey(go_right, "d")
wn.onkey(go_left, "a")


# Main game loop
while True:
    wn.update()

    # Check for collision
    if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290:
        time.sleep(1)
        head.goto(0, 0)
        head.direction = "stop"

        # Hide the segments
        for segment in segments:
           segment.goto(1000, 1000)

        # clear segment list
        segments = []

        # reset score
        score = 0

        # update score
        pen.clear()
        pen.write("score: {} High Score: {}".format(score, high_score), align="center", font=("Courier", 24, "normal"))

    if head.distance(food) < 15:
        # move the food to a random position on screen
        x = random.randint(-290, 290)
        y = random.randint(-290, 290)
        food.goto(x, y)

        # add a segment
        new_segment = turtle.Turtle()
        new_segment.speed(0)
        new_segment.shape("square")
        new_segment.color("grey")
        new_segment.penup()
        segments.append(new_segment)

        # Increase the score
        score = score+10

        if score > high_score:
            high_score = score

    # move the end segment in reverse order
    for index in range(len(segments)-1, 0, -1):
        x = segments[index-1].xcor()
        y = segments[index-1].ycor()
        segments[index].goto(x, y)

        # Move segment 0 to where the head is
    if len(segments) > 0:
        x = head.xcor()
        y = head.ycor()
        segments[0].goto(x, y)

    move()

    # Check for head collision
    for segment in segments:
        if segment.distance(head) < 20:
            time.sleep(1)
            head.goto(0, 0)
            head.direction = "stop"

    # Hide the segments
            for segment in segments:
                segment.goto(1000, 1000)

    # clear segment list
            segment.clear()

    # reset score
            score = 0

    # update score
            pen.clear()
            pen.write("score: {} High Score: {}".format(score, high_score), align="center", font=("Courier", 24, "normal"))
    time.sleep(delay)
turtle.mainloop()
answered Nov 26 by Kalgi
• 45,740 points
+1 vote

Python is an extremely interesting language. you can experiment and do so much with just few lines of code. I have used python for various projects. One of them was A Text to Speech recognition system which converted the texts into speech. so you could write anything and that would be converted into an audio file. the code was entirely written in python and it was quite simple and less chaotic!

# Requires PyAudio and PySpeech.
import speech_recognition as sr
from time import ctime
import time
import os
from gtts import gTTS
import pyglet
import subprocess
def speak(audioString):
    print(audioString)
    tts = gTTS(text=audioString, lang='en')
    tts.save("audio.mp3")
    #os.system("mpg321 audio.mp3")

    wmp = r"C:\Program Files (x86)\Windows Media Player\wmplayer.exe"
    media_file = os.path.abspath(os.path.realpath("C:\\Users\\sundush_n\\Desktop\\Text2speech\\audio.mp3"))
    p = subprocess.call([wmp, media_file])
def recordAudio():
    # Record Audio
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Say something!")
        audio = r.listen(source)
    # Speech recognition using Google Speech Recognition
    data = ""
    try:
        # Uses the default API key

        # To use another API key: `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
        data = r.recognize_google(audio)
        print("You said: " + data)
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))
    return data
def stan(data):
    if "how are you" in data:
        speak("I am fine")
    if "what time is it" in data:
        speak(ctime())
    if "where is" in data:
        data = data.split(" ")
        location = data[2]
        speak("Hold on Tini, I will show you where " + location + " is.")
        os.system("chromium-browser https://www.google.nl/maps/place/" + location + "/&amp;")

# initialization
time.sleep(2)
speak("Hi Tini, what can I do for you?")
while 1:
   data = recordAudio()
    stan(data)
answered Nov 27 by Tini
0 votes

Well, I've been using Python as a tool for around 2 years. It's pseudocode like syntax is helps you to write short and easy to understand codes. There is one script I have created using google api which was capable of fetching data from my google drive. It is quite easy with all the documentation there: https://developers.google.com/drive/api/v3/quickstart/python. You have to enable the API beforehand: https://developers.google.com/drive/api/v3/enable-drive-api

answered Nov 28 by Sumeet
• 140 points

Related Questions In Python

+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,720 points
2,410 views
0 votes
2 answers

how to print the current time using python?

print(datetime.datetime.today()) READ MORE

answered Feb 14 in Python by Shashank
• 1,350 points
61 views
0 votes
1 answer

What's the canonical way to check for type in Python?

To check if o is an instance ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 56,960 points
49 views
+1 vote
1 answer

What's the difference between eval, exec, and compile in Python?

exec is not an expression: a statement ...READ MORE

answered Aug 28, 2018 in Python by Priyaj
• 56,960 points
672 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 394 views
+4 votes
6 answers
0 votes
1 answer

how do I check the length of an array in a python program?

lets say we have a list mylist = ...READ MORE

answered Mar 12 in Python by Mohammad
• 3,170 points
68 views
0 votes
2 answers

what is the procedure to the version of python in my computer?

Execute the following command on your terminal: python ...READ MORE

answered Mar 19 in Python by Alia
49 views