วันพฤหัสบดีที่ 18 สิงหาคม พ.ศ. 2559

argument

รับค่าจาก command line

factorial


import sys
def setup():
    number = int(sys.argv[1])
    print factorial(number)

def factorial(a):
    if a == 1:
        return 1
    else:
        return a * factorial(a-1)
    

setup()

วันอังคารที่ 16 สิงหาคม พ.ศ. 2559

Python

Odd Or Even
Ask the user for a number. Depending on whether the number is even or odd, print out an appropriate message to the user. Hint: how does an even / odd number react differently when divided by 2?
code:
def setup():
    num = int(input("Please enter num:"))
    if num%2==0:
        print(num,"is even")
    else:
        print(num,"is odd")
setup()

Guessing Game One
Generate a random number between 1 and 9 (including 1 and 9). Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right.

code:
import random
def setup():
    count=0
    number = random.randint(1,9)
    while True:
        num = int(input("Please guess num between 1-9:"))
        if num==number:
            print(num," is correct")
            print("your guess count is ",count)
            break
        else:
            count+=1
            if num>number:
                print("it's too high")
            else:
                print("it's too low")
setup()



วันจันทร์ที่ 15 สิงหาคม พ.ศ. 2559

Basic Python

ทบทวน Python

def setup():
    a = [-1,-2,3,5,8,4,10]
    print(calc_postive_sum(a))


def calc_postive_sum(a):
    sum = 0
    for i in a:
        if(i > 0):
            sum+=i
     
    return sum

setup()


การใช้ Class

class Person:
    def __init__(self,name,age):
        self.name=name
        self.age=age
    def display(self):
        print("Name:",self.name)
        print("Age:",self.age)

def setup():
    person1 = Person("John",20)
    person2 = Person("Jan",19)
    people = [person1,person2]
    for i in people:
        i.display()
setup()
     


built-in data structure
List


Sets
def setup():
   a = [5,2,3,5,5,6,8,6,5,2]
   a = remove_duplicate(a)
   print(a)
   
def remove_duplicate(a):
   return list(set(a))
setup()


commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...