Tagged: python Toggle Comment Threads | Keyboard Shortcuts

  • Pleosin 8:30 AM on July 28, 2019 Permalink | Reply
    Tags: , python   

    পাইথনের ভাগ নিয়ে সিম্পল কিছু আলোচনা। সাধারণত পাইথনে যখন ভাগ করা হয় তখন ভাগফল floating point আকারে প্রকাশ পায়। যেমন নিচের কোডটিকে যদি আমরা রান করি

    x = 10
    y = 2
    result = x / y

    তাহলে ভাগফল আসবে 5.0 এখন আমরা যদি চাই ভাগফলে দশমিকের পরে শূণ্য আসবে না, পূর্ণ 5 সংখ্যাটাই আসবে তাহলে সেটাকে integar নাম্বার হিসেবে সিলেট করে দিতে হবে। সেটা কীভাবে?

    x = 10
    y = 2
    result = int( x / y )

    এবার কোডটিকে রান করলে সেটা পূর্ণ সংখ্যা 5 হিসেবে প্রকাশ পাবে।

    ভাগশেষ বের করতে হলে % ব্যবহার করতে হয়। যেমন, 10/3 এর ভাগশেষ জানতে হলে নিচের কোড রান করতে হবে

    x = 10
    y = 3
    result = x % y

    কোডটি রান করে দেখুন, ভাগশেষ দেখাচ্ছে 1

    আপনি যদি পাইথনে ভাগফল এবং ভাগশেষ দুটো একইসাথে দেখতে চান তাহলে সেটা হবে divmod দিয়ে। যেমন নিচের কোডটি রান করুন

    x = 10
    y = 3
    result = divmod (x, y)

    এবার দেখুন ভাগফল এবং ভাগশেষ একইসাথে (3, 1) আকারে দেখাচ্ছে।

  • Pleosin 10:03 PM on July 20, 2019 Permalink | Reply
    Tags: , python   

    Django 2 Cheat Sheet

    Creating a new project
    django-admin startproject projectname

    Add an app to a project
    python manage.py startapp appname

    Starting the server
    python manage.py runserver

    Creating migrations
    python manage.py makemigrations

    Migrate the database
    python manage.py migrate

    Creating a Super User for the admin panel
    python manage.py createsuperuser

    Collecting static files into one folder
    python manage.py collectstatic

  • Pleosin 7:33 PM on July 19, 2019 Permalink | Reply
    Tags: , , , python   

    Create simple hello world application in Django 

    At first check out how to install Django!

    (More …)

  • Pleosin 5:04 PM on July 19, 2019 Permalink | Reply
    Tags: , , , python   

    How To Install Django on Windows 10 | Use Django with ATOM 

    This tutorial will not only help you answer the how to install Django on Windows 10 question but also help you install Django if you have Windows 7, Windows 8 or Windows 8.1.

    You can follow the same steps for all the windows versions mentioned above. (More …)

  • Pleosin 2:52 PM on July 16, 2019 Permalink | Reply
    Tags: , , python   

    Debugging Python Applications with pdb 

    Debugging Python Applications with pdb

    Debugging isn’t a new trick – most developers actively use it in their work. Of course, everyone has their own approach to debugging, but I’ve seen too many specialists try to spot bugs using basic things like print instead of actual debugging tools. Or even if they did use a debugging tool, they only used a small set of features and didn’t dig deeper into the wide range of opportunities good debuggers offer. And which could have saved those specialists a lot of time. (More …)

  • Pleosin 9:03 AM on July 16, 2019 Permalink | Reply
    Tags: , lists, python, sets   

    Basic data types and structures practice in python 

    ## Problem 1 ##

    ## Given the string:
    s = ‘django’
    (More …)

  • Pleosin 2:35 PM on July 15, 2019 Permalink | Reply
    Tags: , python, school, scripting, timetable   

    Build a school timetable with python 

    Today, we’ll learn how with a simple script, we can create a program which helps us to build a school timetable.

    We suppose that as a school manager, we want to make easy the way to establish a school timetable for each class. (More …)

  • Pleosin 8:48 PM on June 27, 2019 Permalink | Reply
    Tags: , python   

    Previous exercises, we created this function:

    >>> def string_length(mystring):
    ...    return len(mystring)

    Calling the function with a string as the value for the argument mystring will return the length of that string.

    If an integer is passed as an argument value:


    that would generate an error since the len() function doesn’t work for integers.

    We have to modify the function so that when an integer is passed as input, the function should output a message like “Sorry integers don’t have length.”

    So, How we do it?

    >>> def string_length(mystring):
    ...    if type(mystring) == int:
    ...        return "Sorry, integers don't have length"
    ...    else:
    ...        return len(mystring)
    >>> string_length(10)
    "Sorry integers don't have length."

    That’s it!

  • Pleosin 8:18 PM on June 27, 2019 Permalink | Reply
    Tags: , python   

    Create a function that takes any string as an argument and returns the length of that string.

    So, the code is:

    >>> def string_length(mystring):
    ...    return len(mystring)
    >>> print(string_length("Hello")) 
  • Pleosin 7:41 PM on June 27, 2019 Permalink | Reply
    Tags: , python   

    Create a function that converts Celsius degrees to Fahrenheit. The formula to convert Celsius to Fahrenheit is F = C × 9/5 + 32.

    Here goes the code:

    >>> def cel_to_far(celsius):
    ...   fahrenheit = celsius *9/5+32
    ...   return fahrenheit
    >>> print(cel_to_far(10))

    That’s it. here you go!

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc
Create your website with WordPress.com
Get started
%d bloggers like this: