Category: Python

  • Javascript Privacy Policy

    Welcome to Learn Javascript. This Privacy Policy explains how we collect, use, and protect your information when you use our application.

    Information We Collect

    We do not collect personally identifiable information (such as name, email, phone number) directly from users. “

    “However, our app uses third-party services (such as Unity Ads and Google Play Services) which may collect data automatically for analytics, personalization, and advertising purposes. “

    “This may include device information, IP address, usage statistics, and ad interactions.

    How We Use Information

    The information collected is used to: \n”

    “- Provide and improve the app experience\n”

    “- Show relevant ads using Unity Ads\n”

    “- Monitor performance and fix issues\n”

    “- Ensure compliance with Play Store policies

    Third-Party Services

    Our app uses third-party services that may collect information to identify you. These include:\n”

    “- Unity Ads (for monetization and personalized ads)\n”

    “- Google Play Services (for app distribution and analytics)

    Data Security

    We take appropriate measures to protect your information. However, please note that no method of transmission over the internet or method of electronic storage is 100% secure.

    Children’s Privacy

    Our app is intended for a general audience and does not knowingly collect personal data from children under 13. “

    “If you believe we have collected such data, please contact us and we will take steps to delete it.

    Your Choices

    You may limit personalized advertising through your device settings. “

    “For example, you can reset your advertising ID or opt out of interest-based ads.

    Changes to This Policy

    We may update this Privacy Policy from time to time. Any changes will be posted within the app with an updated effective date.

    Contact Us

    If you have any questions or concerns about this Privacy Policy, you can contact us at:\n”

    “Email: [email protected]

  • Python Privacy Policy

    1. Introduction

    Welcome to Learn Python Programming This Privacy Policy explains how we collect, use, and protect your information when you use our application.

    2. Information We Collect

    We do not collect personally identifiable information (such as name, email, phone number) directly from users.

    However, our app uses third-party services (such as Unity Ads and Google Play Services) which may collect data automatically for analytics, personalization, and advertising purposes. This may include:

    • Device information
    • IP address
    • Usage statistics
    • Ad interactions

    3. How We Use Information

    The information collected is used to:

    • Provide and improve the app experience
    • Show relevant ads using Unity Ads
    • Monitor performance and fix issues
    • Ensure compliance with Play Store policies

    4. Third-Party Services

    Our app uses third-party services that may collect information to identify you. These include:

    • Unity Ads (for monetization and personalized ads)
    • Google Play Services (for app distribution and analytics)

    5. Data Security

    We take appropriate measures to protect your information. However, please note that no method of transmission over the internet or method of electronic storage is 100% secure.

    6. Children’s Privacy

    Our app is intended for a general audience and does not knowingly collect personal data from children under 13. If you believe we have collected such data, please contact us and we will take steps to delete it.

    7. Your Choices

    You may limit personalized advertising through your device settings. For example, you can reset your advertising ID or opt out of interest-based ads.

    8. Changes to This Policy

    We may update this Privacy Policy from time to time. Any changes will be posted within the app with an updated effective date.

    9. Contact Us

    If you have any questions or concerns about this Privacy Policy, you can contact us at:

    📧 Email: [email protected]

  • Active Storage

    In this chapter, you will learn about the Active Storage framework in Ruby on Rails. Active Storage was introduced in the version 6.1 of Rails. Active Storage enables uploading and attaching files (e.g., images, videos, PDFs) to the Rails models. It supports storing files on local disk as well in the cloud like Amazon S3, Google Cloud Storage, etc.

    Active Storage handles tasks such as −

    • Uploading files from forms
    • Attaching files to models (has_one_attached / has_many_attached)
    • Serving, previewing, and transforming files

    Note that you may have to install other gems such as poppler or muPDF for PDF previews, or ImageMagick for image transformations (for example creating thumbnails). Image analysis and transformations also require the image_processing gem.

    To enable the Active Storage support in a Rails application, you need to install the component and run the migrations to create the required tables.

    Set up Active Storage

    Let us start by creating a new Rails app

    rails newUploaderApp
    cd UploaderApp

    As you enter the application folder, install active_Storage component and run migration.

    rails active_storage:installCopied migration 20250408064642_create_active_storage_tables.active_storage.rb from active_storage
    rails db:migrate

    The terminal shows that the following tables are created:

    ========20250408064642CreateActiveStorageTables: migrating ==============-- create_table(:active_storage_blobs,{:id=>:primary_key})->0.0045s
    -- create_table(:active_storage_attachments,{:id=>:primary_key})->0.0033s
    -- create_table(:active_storage_variant_records,{:id=>:primary_key})->0.0022s
    ======20250408064642CreateActiveStorageTables: migrated (0.0134s)======

    Tables Created Due to Migration

    Following tables are created as a result of the migration:

    • active_storage_blobs – This table Stores metadata and unique references to uploaded files (like a pointer to the file stored on disk or in cloud). Each row represents a unique file. The fields in this table include filename, content_type and byte_size along with the Timestamp of creation.
    • active_storage_attachments – This table is used to join your model (like User) to the actual file (Blob). Each row represents one attachment between a model and a file.
    • active_storage_variant_records – The purpose of this table is to Cache the image variants (like thumbnails or resized images).

    The process of reading/writing is taken care of by Rails by providing abstractions in the form of methods like user.profile_picture.attach(…) or display image_tag user.profile_picture.

    Rails stores uploaded files in the storage subfolder of the application folder in development and test environments in production, the config/storage/production.yml file is used to specify the corresponding bucket or container of the provider such as Amazon, Google or Azure etc.

    Scaffold a User model

    To demonstrate how Rails performs file uploading, let us quickly scaffold a User resource with username and email as the model attributes.

    rails generate scaffold User username:string email:string
    db:migrate

    Edit the User model to add profile_picture attribute (in app/models/user.rb)

    classUser<ApplicationRecord
    	has_one_attached :profile_pictureend

    To permit File Parameter in Controller, update UsersController in user_params method:

    # Only allow a list of trusted parameters through.defuser_params
    	params.require(:user).permit(:username,:email,:profile_picture)end

    Edit the views

    The scaffolding has already created a form to enter a new user. You will need to add a file input type to it:

    <%= form_with(model: user) do |form| %>
      <% if user.errors.any? %>
    
    &lt;div style="color: red"&gt;&lt;h2&gt;&lt;%= pluralize(user.errors.count, "error") %&gt; prohibited this user from being saved:&lt;/h2&gt;
      &lt;ul&gt;
        &lt;% user.errors.each do |error| %&gt;
          &lt;li&gt;&lt;%= error.full_message %&gt;&lt;/li&gt;&lt;%end%&gt;
      &lt;/ul&gt;&lt;/div&gt;&lt;%end%&gt;
    <div><%= form.label :username, style: "display: block" %>
    &lt;%= form.text_field :username%&gt;
    </div><div><%= form.label :email, style: "display: block" %>
    &lt;%= form.text_field :email%&gt;
    </div><div><%= form.label :profile_picture, style: "display: block" %>
    &lt;%= form.file_field :profile_picture%&gt;
    </div><div><%= form.submit %> </div><%end%>

    The code shown in bold needs to be added.

    You must make changes to the show view too. Make sure that the show.html.erb file in app/views/users folder has the following code:

    <p style="color: green"><%= notice %></p><p><strong>Username:</strong>
      <%= @user.username %>
    </p><p><strong>Email:</strong>
      <%= @user.email %>
    </p>
    
    <% if @user.profile_picture.attached? %> <%# for Active Storage %>
      <p><strong>Profile Picture:</strong><br>
    
    &lt;%= image_tag @user.profile_picture %&gt;
    </p> <% end %> <div> <%= link_to "Edit this user", edit_user_path(@user) %> | <%= link_to "Back to users", users_path %> <%= button_to "Destroy this user", @user, method: :delete %> </div>

    And that’s it. Incorporate all the changes suggested above and run the Rails server. The /users/new URL opens up a form to add a new user.

    run the Rails server

    Click on the Choose File button, navigate to the desired file and then click the Create User button. Rails responds with a confirmation page, displaying the profile picture you uploaded.

    run the Rails servers
  • Data Layout

    COBOL layout is the description of use of each field and the values present in it. Following are the data description entries used in COBOL −

    • Redefines Clause
    • Renames Clause
    • Usage Clause
    • Copybooks

    Redefines Clause

    Redefines clause is used to define a storage with different data description. If one or more data items are not used simultaneously, then the same storage can be utilized for another data item. So the same storage can be referred with different data items.

    Syntax

    Following is the syntax for Redefines clause −

    01 WS-OLD PIC X(10).
    01 WS-NEW1 REDEFINES WS-OLD PIC 9(8).
    01 WS-NEW2 REDEFINES WS-OLD PIC A(10).
    

    Following are the details of the used parameters −

    • WS-OLD is Redefined Item
    • WS-NEW1 and WS-NEW2 are Redefining Item

    Level numbers of redefined item and redefining item must be the same and it cannot be 66 or 88 level number. Do not use VALUE clause with a redefining item. In File Section, do not use a redefines clause with 01 level number. Redefines definition must be the next data description you want to redefine. A redefining item will always have the same value as a redefined item.

    Example

    IDENTIFICATIONDIVISION.PROGRAM-ID. HELLO.DATADIVISION.WORKING-STORAGESECTION.01 WS-DESCRIPTION.05 WS-DATE1 VALUE'20140831'.10 WS-YEAR PICX(4).10 WS-MONTH PICX(2).10 WS-DATE PICX(2).05 WS-DATE2 REDEFINES WS-DATE1 PIC9(8).PROCEDUREDIVISION.DISPLAY"WS-DATE1 : "WS-DATE1.DISPLAY"WS-DATE2 : "WS-DATE2.STOPRUN.

    JCL to execute the above COBOL program −

    //SAMPLE JOB(TESTJCL,XXXXXX),CLASS= A,MSGCLASS = C
    //STEP1 EXEC PGM = HELLO
    

    When you compile and execute the above program it produces the following result −

    WS-DATE1 : 20140831
    WS-DATE2 : 20140831
    

    Renames Clause

    Renames clause is used to give different names to existing data items. It is used to re-group the data names and give a new name to them. The new data names can rename across groups or elementary items. Level number 66 is reserved for renames.

    Syntax

    Following is the syntax for Renames clause −

    01 WS-OLD.
    10 WS-A PIC 9(12).
    10 WS-B PIC X(20).
    10 WS-C PIC A(25).
    10 WS-D PIC X(12).
    66 WS-NEW RENAMES WS-A THRU WS-C.
    

    Renaming is possible at same level only. In the above example, WS-A, WS-B, and WS-C are at the same level. Renames definition must be the next data description you want to rename. Do not use Renames with the level numbers 01 or, 77. The data names used for renames must come in sequence. Data items with occur clause cannot be renamed.

    Example

    IDENTIFICATIONDIVISION.PROGRAM-ID. HELLO.DATADIVISION.WORKING-STORAGESECTION.01 WS-DESCRIPTION.05 WS-NUM.10 WS-NUM1 PIC9(2)VALUE20.10 WS-NUM2 PIC9(2)VALUE56.05 WS-CHAR.10 WS-CHAR1 PICX(2)VALUE'AA'.10 WS-CHAR2 PICX(2)VALUE'BB'.66 WS-RENAME RENAMES WS-NUM2 THRU WS-CHAR2.PROCEDUREDIVISION.DISPLAY"WS-RENAME : " WS-RENAME.STOPRUN.

    JCL to execute the above COBOL program −

    //SAMPLE JOB(TESTJCL,XXXXXX),CLASS= A,MSGCLASS = C
    //STEP1 EXEC PGM = HELLO
    

    When you compile and execute the above program, it produces the following result −

    WS-RENAME : 56AABB
    

    Usage Clause

    Usage clause specifies the operating system in which the format data is stored. It cannot be used with level numbers 66 or 88. If usage clause is specified on a group, then all the elementary items will have the same usage clause. The different options available with Usage clause are as follows −

    Display

    Data item is stored in ASCII format and each character will take 1 byte. It is default usage.

    The following example calculates the number of bytes required −

    01 WS-NUM PICS9(5)V9(3)USAGEISDISPLAY.
    It requires 8 bytes assignand decimal doesn't require any byte.01 WS-NUM PIC9(5)USAGEISDISPLAY.
    It requires 5 bytes assign.

    COMPUTATIONAL / COMP

    Data item is stored in binary format. Here, data items must be integer.

    The following example calculates the number of bytes required −

    01 WS-NUM PICS9(n)USAGEISCOMP.If'n'=1to4, it takes 2 bytes.If'n'=5to9, it takes 4 bytes.If'n'=10to18, it takes 8 bytes.

    COMP-1

    Data item is similar to Real or Float and is represented as a single precision floating point number. Internally, data is stored in hexadecimal format. COMP-1 does not accept PIC clause. Here 1 word is equal to 4 bytes.

    COMP-2

    Data item is similar to Long or Double and is represented as double precision floating point number. Internally, data is stored in hexadecimal format. COMP-2 does not specify PIC clause. Here 2 word is equal to 8 bytes.

    COMP-3

    Data item is stored in packed decimal format. Each digit occupies half a byte (1 nibble) and the sign is stored at the rightmost nibble.

    The following example calculates the number of bytes required −

    01 WS-NUM PIC9(n)USAGEISCOMP.Numberof bytes = n/2(If n is even)Numberof bytes = n/2+1(If n is odd, consider only integer part)01 WS-NUM PIC9(4)USAGEISCOMP-3VALUE21.
    It requires 2 bytes of storage as each digit occupies half a byte.01 WS-NUM PIC9(5)USAGEISCOMP-3VALUE21.
    It requires 3 bytes of storage as each digit occupies half a byte.

    Copybooks

    A COBOL copybook is a selection of code that defines data structures. If a particular data structure is used in many programs, then instead of writing the same data structure again, we can use copybooks. We use the COPY statement to include a copybook in a program. COPY statement is used in the WorkingStorage Section.

    The following example includes a copybook inside a COBOL program −

    DATADIVISION.WORKING-STORAGESECTION.COPY ABC.

    Here ABC is the copybook name. The following data items in ABC copybook can be used inside a program.

    01 WS-DESCRIPTION.
    05 WS-NUM.
    10 WS-NUM1 PIC 9(2) VALUE 20.
    10 WS-NUM2 PIC 9(2) VALUE 56.
    05 WS-CHAR.
    10 WS-CHAR1 PIC X(2) VALUE ‘AA’.
    10 WS-CHAR2 PIC X(2) VALUE ‘BB’.

  • Simple Website

    A basic website built with Flask, a Python web framework. When you open it in the browser, it shows a message. You can expand it into blogs, portfolios, or web apps.

    • Basics of web frameworks.
    • Creating routes (URLs) and responses.
    • Running your own web server.
    • This introduces you to web development with Python.
    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route("/")
    def home():
    
    return "Hello, this is my first Flask website!"
    if __name__ == "__main__":
    app.run(debug=True)
  • Weather App (using API)

    This project fetches real-time weather data from the internet (using the OpenWeatherMap API). You type a city, and it shows the current temperature and conditions.

    • Using APIs (connecting your program to online services).
    • Sending HTTP requests with the requests library.
    • Handling JSON data in Python.
      This teaches you how Python interacts with the web.
    import requests
    
    city = input("Enter city name: ")
    api_key = "your_api_key_here"  # get free key from openweathermap.org
    url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
    
    response = requests.get(url).json()
    print(f"Weather in {city}: {response['main']['temp']}°C, {response['weather'][0]['description']}")
    
  • Password Generator

    Generates random strong passwords A tool that generates strong random passwords using letters, numbers, and symbols. You can choose the password length.

    Security basics (importance of strong passwords).
    It’s practical—you can actually use this in real life.

    Using libraries (string, random).

    Working with lists and strings.

    import random
    import string
    
    def generate_password(length=10):
    
    characters = string.ascii_letters + string.digits + string.punctuation
    password = "".join(random.choice(characters) for i in range(length))
    return password
    print("Generated password:", generate_password(12))
  • Calculator App

    Simple Calculator

    • Create a command-line calculator where users can input mathematical operations (addition, subtraction, multiplication, division), and the program will compute the result
    • A simple program that performs addition, subtraction, multiplication, and division.

      def calculator(): num1 = float(input("Enter first number: ")) op = input("Enter operator (+, -, *, /): ") num2 = float(input("Enter second number: ")) if op == '+': print("Result:", num1 + num2) elif op == '-': print("Result:", num1 - num2) elif op == '*': print("Result:", num1 * num2) elif op == '/': print("Result:", num1 / num2) else: print("Invalid operator!") calculator()

    1. To-Do List
      • Build a to-do list program where users can add tasks, mark them as complete, and delete them. You can store tasks in a file or in memory.
    2. Basic Alarm Clock
      • Build a simple alarm clock where the user can set a time, and the program will notify them once the time is reached.
    3. Currency Converter
      • Create a currency converter that uses exchange rates from an API (like ExchangeRate-API) to convert one currency to another.

  • Dynamically typed

    Dynamic typing is another potential drawback of using Python in a work environment. Python allows you to change the data type of a variable at runtime, without the need for explicit type declarations. While this can make code more flexible and easier to write, it can also lead to errors and unexpected behavior.

    For example, if you assign a string value to a variable and later try to perform a mathematical operation on that variable, Python will raise a TypeError. This can be frustrating for developers who are used to more strict type checking in other languages.

    In addition, dynamic typing can make it more difficult to debug and maintain code, as it may not be immediately clear what data types are being used in a particular section of code. This can lead to subtle bugs and performance issues that are difficult to diagnose and fix.

  • Not ideal work environment

    One potential drawback of using Python in a work environment is that it may not be the best fit for all types of projects or teams. For example, if a project requires high performance or low-level system access, a language like C++ may be a better choice.

    Moreover, Python’s dynamic nature and lack of strong typing can make it more difficult to maintain and debug code as projects grow larger and more complex. This can lead to increased development time and costs, as well as potential errors or security vulnerabilities.