Tagged: পাইথন Toggle Comment Threads | Keyboard Shortcuts

  • Joker 2:35 PM on July 15, 2019 Permalink | Reply
    Tags: পাইথন, , 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 …)

     
  • Joker 8:48 PM on June 27, 2019 Permalink | Reply
    Tags: পাইথন,   

    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:

    string_length(10)

    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!

     
  • Joker 8:18 PM on June 27, 2019 Permalink | Reply
    Tags: পাইথন,   

    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")) 
    5
    
     
  • Joker 7:41 PM on June 27, 2019 Permalink | Reply
    Tags: পাইথন,   

    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))
    50.0
    

    That’s it. here you go!

     
  • Joker 7:15 PM on June 27, 2019 Permalink | Reply
    Tags: পাইথন,   

    if you want to clear your python console, just type

    import os
    os.system('cls')
    

    and press enter. this is for windows user only.

     
  • Joker 1:03 PM on June 24, 2019 Permalink | Reply
    Tags: পাইথন,   

    input function always produces a string output. If you want to output an integer you have to use int. example

    If you want to number output from this below code

    user_input = input("enter a number: ")
    print(user_input ** 2)
    

    it’ll show error like

    Traceback (most recent call last):                                                                                                                  
      File "try_input.py", line 2, in <module>                                                                                                          
        print(user_input ** 2)
    

    So, you have to convert that string to an integer.

    user_input = input("enter a number: ")
    print(int(user_input) ** 2)
    

    If you try this now under 10, you’ll get 100.

    enter a number: 10
    100
    
     
  • Joker 12:36 PM on June 24, 2019 Permalink | Reply
    Tags: পাইথন,   

    Mapping two lists to a dictionary:

    keys = ["a","b","c"]
    values = [1, 2, 3]
    mydicts = dict(zip(keys, values))
    mydicts
    {'a': 1, 'b': 2, 'c': 3}
    
     
  • Joker 12:22 PM on June 24, 2019 Permalink | Reply
    Tags: পাইথন,   

    Python lists only contain one value divided by comma, dictionaries contain two values. Also, lists use [ ] third bracket and dictionaries use { } second bracket.

     
  • Joker 12:06 PM on June 24, 2019 Permalink | Reply
    Tags: পাইথন,   

    পাইথনের built in functions এর লিস্ট জানতে হলে পাইথন শেলে টাইপ করতে হবে

    dir(__builtins__)
    

    এন্টার দিলে বিল্ট ইন ফাংশনের লিস্ট চলে আসবে, লিস্টগুলো নিচে দেয়া হলোঃ

    ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'Child
    ProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ell
    ipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'I
    OError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt',
     'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError',
     'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'Runt
    imeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'Timeou
    tError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarn
    ing', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__na
    me__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod',
     'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format',
     'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'l
    ist', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'rev
    ersed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
    
     
  • Joker 4:04 AM on June 24, 2019 Permalink | Reply
    Tags: পাইথন,   

    The definition of a list is a data type that contains multiple items

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
Create your website at WordPress.com
Get started
%d bloggers like this: