Inside the Alokverse

Learn Python Right Now!!

Introduction

Why is Python everywhere? Because it’s short to write, easy to learn, and powerful to use. If you’re reading this, take it as your sign—yes, you should definitely learn Python right now.

Now, I’m writing this because most of the devs I’ve met keep saying the same thing: “Goddammit, begin with Python” or “Learn Python right now.” And by devs, I don’t mean some rookie clankers, I mean the high-earning devs who actually know what they’re doing.

PS: Yes, Python was the first programming language I started learning way back in my ninth grade. It felt pretty cool learning a programming language when everyone around me was doing absolutely nothing.

So, let’s dive in.

What is Python?

In simple words, Python is a high level(human friendly) programming language. It’s clean, readable, and beginner-friendly, yet powerful enough to run some of the world’s biggest applications.
PS: Well I’m not even a expert of this language so even i had to go through some searches on the internet to gather some info, but now I feel like Guido van Rossum, btw he created Python in 1991

Why Learn Python?

Core Concepts of Python

Popular Python Libraries You Must Know

How to Learn Python Effectively

Sample Code: Snake Game in Python

Here’s a fun one. A simple snake game from my textbook which you can run right now. Copy, paste in your code editor, run, and enjoy.

import turtle
import time
import random

# Delay
delay = 0.1

# Score
score = 0
high_score = 0

# Set up the screen
wn = turtle.Screen()
wn.title("Snake Game")
wn.bgcolor("black")
wn.setup(width=600, height=600)
wn.tracer(0)

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

# Food
food = turtle.Turtle()
food.speed(0)
food.shape("circle")
food.color("red")
food.penup()
food.goto(0,100)

segments = []

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

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

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

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

def move():
    if head.direction == "up":
        y = head.ycor()
        head.sety(y + 20)
    if head.direction == "down":
        y = head.ycor()
        head.sety(y - 20)
    if head.direction == "left":
        x = head.xcor()
        head.setx(x - 20)
    if head.direction == "right":
        x = head.xcor()
        head.setx(x + 20)

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

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

    # Check for border 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 segments
        for segment in segments:
            segment.goto(1000, 1000)
        segments.clear()

    # Check for food collision
    if head.distance(food) < 20:
        x = random.randint(-290, 290)
        y = random.randint(-290, 290)
        food.goto(x,y)

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

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

    if len(segments) > 0:
        x = head.xcor()
        y = head.ycor()
        segments[0].goto(x, y)

    move()

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

            for segment in segments:
                segment.goto(1000, 1000)
            segments.clear()

    time.sleep(delay)

wn.mainloop()

Conclusion

If you don’t start learning Python now, don’t blame me when your fridge starts coding and replaces you,lol. Just start, it’s a solid language, and I’m just encouraging you to upgrade yourself. Nothing much.

See you in the next one❤️.