Djazuli Dev
1.17K subscribers
34 photos
120 files
101 links
Berbagi source code
Download Telegram
Snake Game using Turtle in Python ✅ Source Code 👇👇

# import required modules
import turtle
import time
import random

delay = 0.1
score = 0
high_score = 0


# Creating a window screen
wn = turtle.Screen()
wn.title("Snake Game")
wn.bgcolor("blue")
# the width and height can be put as user's choice
wn.setup(width=600, height=600)
wn.tracer(0)

# head of the snake
head = turtle.Turtle()
head.shape("square")
head.color("white")
head.penup()
head.goto(0, 0)
head.direction = "Stop"

# food in the game
food = turtle.Turtle()
colors = random.choice(['red', 'green', 'black'])
shapes = random.choice(['square', 'triangle', 'circle'])
food.speed(0)
food.shape(shapes)
food.color(colors)
food.penup()
food.goto(0, 100)

pen = turtle.Turtle()
pen.speed(0)
pen.shape("square")
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, 250)
pen.write("Score : 0  High Score : 0", align="center",
          font=("candara", 24, "bold"))


# assigning key directions
def group():
    if head.direction != "down":
        head.direction = "up"


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


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


def goright():
    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)


wn.listen()
wn.onkeypress(group, "w")
wn.onkeypress(godown, "s")
wn.onkeypress(goleft, "a")
wn.onkeypress(goright, "d")

segments = []

# By - @pythonnotes1
# Main Gameplay
while True:
    wn.update()
    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"
        colors = random.choice(['red', 'blue', 'green'])
        shapes = random.choice(['square', 'circle'])
        for segment in segments:
            segment.goto(1000, 1000)
        segments.clear()
        score = 0
        delay = 0.1
        pen.clear()
        pen.write("Score : {} High Score : {} ".format(
            score, high_score), align="center", font=("candara", 24, "bold"))
    if head.distance(food) < 20:
        x = random.randint(-270, 270)
        y = random.randint(-270, 270)
        food.goto(x, y)

        # Adding segment
        new_segment = turtle.Turtle()
        new_segment.speed(0)
        new_segment.shape("square")
        new_segment.color("orange")  # tail colour
        new_segment.penup()
        segments.append(new_segment)
        delay -= 0.001
        score += 10
        if score > high_score:
            high_score = score
        pen.clear()
        pen.write("Score : {} High Score : {} ".format(
            score, high_score), align="center", font=("candara", 24, "bold"))
    # Checking for head collisions with body segments
    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()
    for segment in segments:
        if segment.distance(head) < 20:
            time.sleep(1)
            head.goto(0, 0)
            head.direction = "stop"
            colors = random.choice(['red', 'blue', 'green'])
            shapes = random.choice(['square', 'circle'])
            for segment in segments:
                segment.goto(1000, 1000)
            segments.clear()

            score = 0
            delay = 0.1
            pen.clear()
            pen.write("Score : {} High Score : {} ".format(
                score, high_score), align="center", font=("candara", 24, "bold"))
    time.sleep(delay)

wn.mainloop()
--- Indian Flag🇮🇳🇮🇳 Source Code ---

import turtle
from turtle import *

# setting the screen for drawing
scr = turtle.Screen()
# Defining the instance of turtle
ttl = turtle.Turtle()
speed(20)

# keeping the pen up initially
ttl.penup()
ttl.goto(-150, 125)
ttl.pendown(
)
# Drawing the Orange Rectangle first
#and then the white rectangle
ttl.color("orange")
ttl.begin_fill()
ttl.forward(400)
ttl.right(90)
ttl.forward(84)
ttl.right(90)
ttl.forward(400)
ttl.end_fill()
ttl.left(90)
ttl.forward(84)

# now drawing the Green Rectangle
ttl.color("green")
ttl.begin_fill()
ttl.forward(84)
ttl.left(90)
ttl.forward(400)
ttl.left(90)
ttl.forward(84)
ttl.end_fill()

# Drawing the central Big Blue Circle
ttl.penup()
ttl.goto(35, 0)
ttl.pendown()
ttl.color("navy")
ttl.begin_fill()
ttl.circle(35)
ttl.end_fill()

# Drawing the in-circle Big White Circle
ttl.penup()
ttl.goto(30, 0)
ttl.pendown()
ttl.color("white")
ttl.begin_fill()
ttl.circle(30)
ttl.end_fill()

#Drawing the inside Mini Blue Circles of Flag
ttl.penup()
ttl.goto(-27, -4)
ttl.pendown()
ttl.color("navy")
for j in range(24):
ttl.begin_fill()
ttl.circle(2)
ttl.end_fill()
ttl.penup()
ttl.forward(7)
ttl.right(15)
ttl.pendown()

# drawing the Smaller Blue Circle
ttl.color("navy")
ttl.penup()
ttl.goto(10, 0)
ttl.pendown()
ttl.begin_fill()
ttl.circle(10)
ttl.end_fill()

#Drawing the 24 spokes of the Indian Flag
ttl.penup()
ttl.goto(0, 0)
ttl.pendown()
ttl.pensize(1)
for j in range(24):
ttl.forward(30)
ttl.backward(30)
ttl.left(15)

#Drawing the stick of the Indian flag
ttl.color("Brown")
ttl.pensize(10)
ttl.penup()
ttl.goto(-150,125)
ttl.right(180)
ttl.pendown()
ttl.forward(500)

#to hide the turtle pen we used hideturtle
ttl.hideturtle()
#holding the output on the window
turtle.done()

React❤️ on this msg
👨‍💻 "Hello World" in Different Coding Languages 🌍🔥

One of the first things beginners learn in programming is how to display:

"Hello, World!"

Although the output is the same, the syntax can be very different across programming languages.

🐍 Python

print("Hello, World!")

🌐 JavaScript

console.log("Hello, World!");

☕ Java

`java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}


⚡ C++

cpp
#include <iostream>

int main() {
std::cout << "Hello, World!";
return 0;
}


🔵 C

c
#include <stdio.h>

int main() {
printf("Hello, World!");
return 0;
}


💜 C#

csharp
using System;

class Program {
static void Main() {
Console.WriteLine("Hello, World!");
}
}


🦀 Rust

rust
fn main() {
println!("Hello, World!");
}


🐹 Go

go
package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}


💎 Ruby

ruby
puts "Hello, World!"


🟣 PHP

php
<?php
echo "Hello, World!";
?>


🟠 Kotlin

kotlin
fun main() {
println("Hello, World!")
}


🦜 Swift

swift
print("Hello, World!")`


What is your favourite coding language?👨‍💻

❤️ Python

👍 JavaScript

😍 Java

👌 C++

😂 C#

💯 Other
A Website Product Laptop With ScrollTrigger Use HTML Javascript
-6185813888176165800_121.jpg
37.2 KB
import math
from turtle import *

def heart_a(n):
    return 15 * math.sin(n) ** 3

def heart_b(n):
    return 12 * math.cos(n)-5 *\
           math.cos(2*n) - 2 *\
           math.cos(3*n) - \
           math.cos(4*n)

tracer(2)
bgcolor("black")
for i in range(800):
    goto(heart_a(i)*15, heart_b(i)*15)
    for j in range(1):
        color('red')
        hideturtle()
        goto(0, 0)
done()
*🚀 Complete Python Roadmap for Automation & Data Analytics*

Python is one of the most powerful languages for automating repetitive tasks and analyzing data. Whether you're aiming for a Data Analyst, Automation Engineer, or Data Engineer role, this roadmap covers the essential skills.

*🎯 Phase 1: Python Fundamentals*
*Master the basics:*
- Variables & Data Types
- Operators
- Conditional Statements: if, elif, else
- Loops: for, while
- Functions
- Modules & Packages
- Exception Handling
- File Handling

*Practice:*
- Number Guessing Game
- Calculator
- Password Generator
- File Organizer

*🎯 Phase 2: Object-Oriented Programming OOP*
*Learn:*
- Classes & Objects
- Constructors
- Inheritance
- Polymorphism
- Encapsulation
- Abstraction

*Build:*
- Library Management System
- Employee Management System

*🎯 Phase 3: Working with Files*
*Master:*
- Reading Text Files
- Writing Files
- CSV Files
- JSON Files
- Excel Files
- PDF Files

*Libraries:*
- openpyxl
- pandas
- PyPDF2

*Projects:*
- Merge Excel Files
- Convert CSV to Excel
- Extract Data from PDFs

*🎯 Phase 4: Python for Excel Automation*
*Learn:*
- Reading Excel Files
- Creating Workbooks
- Formatting Cells
- Applying Formulas
- Charts
- Pivot Tables
- Multiple Sheet Handling

*Libraries:*
- openpyxl
- XlsxWriter

*Projects:*
- Automated Sales Report
- Attendance Tracker
- Invoice Generator
- Dashboard Report Generator

*🎯 Phase 5: Data Analysis*
*Master:*
- NumPy
- Pandas
- Data Cleaning
- Data Transformation
- Data Aggregation
- Missing Value Handling
- Feature Engineering

*Projects:*
- Sales Analysis
- HR Analytics
- Customer Analysis
- Financial Reports

*🎯 Phase 6: Data Visualization*
*Learn:*
- Line Charts
- Bar Charts
- Pie Charts
- Histograms
- Scatter Plots
- Heatmaps

*Libraries:*
- Matplotlib
- Plotly

*Projects:*
- Interactive Dashboard
- Sales Dashboard
- Marketing Dashboard

*🎯 Phase 7: Database Integration*
*Learn SQL basics:*
- SELECT
- INSERT
- UPDATE
- DELETE
- JOIN
- GROUP BY
- Window Functions

*Connect Python with databases:*
- SQLite
- MySQL
- PostgreSQL

*Projects:*
- Sales Database Analysis
- Employee Database System

*🎯 Phase 8: Web Automation*
*Learn:*
- Browser Automation
- Form Filling
- Data Extraction
- Login Automation
- Report Downloading

*Libraries:*
- Selenium
- Playwright

*Projects:*
- Automated Report Download
- Job Scraper
- Website Monitoring

*🎯 Phase 9: Web Scraping*
*Learn:*
- HTML Basics
- CSS Selectors
- XPath
- Pagination
- API vs Scraping

*Libraries:*
- Beautiful Soup
- Scrapy

*Projects:*
- Product Price Tracker
- News Scraper
- Stock Information Collector

*🎯 Phase 10: API Automation*
*Learn:*
- REST APIs
- GET
- POST
- PUT
- DELETE
- Authentication
- JSON Handling

*Libraries:*
- Requests

*Projects:*
- Weather Dashboard
- Currency Converter
- Employee API Integration

*🎯 Phase 11: Task Automation*
*Automate:*
- Email Sending
- File Renaming
- Folder Organization
- Backup Scripts
- Scheduled Tasks
- Log File Monitoring

*Libraries:*
- os
- shutil
- pathlib
- schedule
- smtplib

*Projects:*
- Automatic Backup Tool
- Daily Report Generator
- Bulk File Renamer

*🎯 Phase 12: Data Processing*
*Learn:*
- Data Validation
- Data Transformation
- ETL Basics
- Batch Processing
- Log Analysis

*Projects:*
- ETL Pipeline
- CSV to Database Loader
- Automated Data Cleaning Pipeline

*🎯 Phase 13: Reporting & Dashboards*
*Generate reports using:*
- Excel
- PDF
- HTML

*Build dashboards using:*
- Streamlit
- Dash

*Projects:*
- KPI Dashboard
- Business Analytics Dashboard
- Financial Dashboard

*🎯 Phase 14: Deployment & Best Practices*
*Learn:*
- Virtual Environments
- Logging
- Configuration Files
- Unit Testing
- Git & GitHub
- Docker Basics

*Deploy applications using:*
- Streamlit
- Docker
- Cloud Platforms

*🏆 Portfolio Projects*
*Beginner:*
- Calculator
- Expense Tracker
- CSV Cleaner
- Password Generator

*Intermediate:*
- Excel Report Automation
- Web Scraper
- API Data Fetcher
- Sales Dashboard