Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

[Python] Basic Encoder/Decoder with Caesar CIpher


def CaesarCiper(str_,DeEn, key): a_=[] for i in str_: if(DeEn == "D"): a_.append(ord(i) - key) else: a_.append(ord(i) + key) def_="" for j in a_: def_ = def_ + chr(j) return def_


>>> a = CaesarCiper("This is a test with long sentence for Decode/Encode the message","E",2) >>> a 'Vjku"ku"c"vguv"ykvj"nqpi"ugpvgpeg"hqt"Fgeqfg1Gpeqfg"vjg"oguucig' >>> b = CaesarCiper(a,"D",2) >>> b 'This is a test with long sentence for Decode/Encode the message'

[Python 1] Basic Python

Assuming that the traits of a person can be determined by a number which is a summarization of the values in their name. For example, if a = 1, b = 2, c = 3, etc. then, the name Mathhoang would be 87.

A small snippet python can be:


1
2
3
4
5
6
def calTraits():
 input_ = input("enter name: ").lower()
 sum_ = 0
 for i in input_:
  sum_ = sum_ + (ord(i) - 96)
 return sum_
another way for it:
1
 sum([(ord(i) - 96) for i in input("enter name:").lower()])

The examples show that we can use python in many differnt ways to implement your ideas!

[Python] Inheritance

Python is an object-oriented programming language, so it also has inheritance, overloading, overriding, etc. Below is one of the simple examples of how inheritance is implemented in Python.

By looking at below example, it is easy to learn how a class inherits from other classes and how a class is declared, defined and used in Python.

--------------------------------
Python là một ngôn ngữ lập trình hướng đối tượng! bên dưới là một ví dụ đơn giản về tính thừa kế trong Python.

[Python] Small Python program applying Skeleton

This is an example of how to apply skeleton in the previous post.
This program is just the simplest calculator in the world. The purpose is just to prove how efficient to apply the skeleton into your project. It makes the project have a good look and well-organized.

--------------------
Chương trình máy tính python đơn giản. Cách áp dụng coding style ở bài trước
--------------------

[Python] Skeleton

A good programming habit is to have a skeleton for every new project. Below is a simple skeleton Python project which can be served as an entry point for a initial start of writing your own skeleton:

----------
Bộ khung mẫu của một chương trình trong python! Nó sẽ giúp ích trong việc tổ chức code
----------

import sys
def main():
    func1()
    func2()
    pass

def func1():
    # doing your work
    pass

def func2():
    # doing your work
    pass
    
if __name__ == '__main__':
    sys.exit(main())
Related Posts Plugin for WordPress, Blogger...