ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 210322 TIL
    TIL/202103 2021. 3. 22. 23:50

    1.English

    all I only wanna do is see some public facilities so that I can imagine and understand the way of lives of people who have lived there for long time

     

    2.datacamp

    after table has PK, we can designate FK to new column of new table with this way. 

    1)create first table

    2)insert some values to the table

    3)create another table

    4)bring PK function from the first table to second table’s new column as FK

    5)now, they are connected. (only cars with valid and existing manufacturers may be entered into that table

     

    3.algorithm

    translate from what I think to code

    effectiveness - optimization of module and function that I use frequently

    think based on procedure - make my own workflow

    debugging - find errors in process

     

    [Big O notation] - how many times what I code would run? 

     

    time complexity (always should consider the worst)

    -O(1) once

    -O(n) n times

     

    def search(lst, N, K)

    for i in lst

    if i == K: return True

    return false

     

    -O(logN) best example - binary search (up & down game)

     

    keep getting short by half, this means log2N.

    We can detach ‘2’, it turns out logN

     

    [1, 2, 3, 4], 4, 3

     

    def binary_search(lst, N, K):

    lo, hi = 0, N-1. # start from zero

    while lo <= hi: # during hi bigger than zero

    mid = (lo + hi)  // 2 # share

    if lst[mid] == K : return True # completed!

    if lst[mid] > K : lo = mid - 1

    else: lo = mid + 1 # rearrange location of lo

    return False

     

    ## this could work when the list are sorted before ##

     

    4.python bootcamp day4 of udemy

    rock, paper, scissors

    1)question

    2)random result from computer

    3)compare mine with computers’

    4)print result

    import random
    
    mine = int(input("which one would you choose? rock is 0, paper is 1, scissors is 2: "))
    
    com = random.randint(0,2)
    
    row1 = ['draw game', 'you are lost', 'you win']
    row2 = ['you win', 'draw game', 'you are lost']
    row3 = ['you are lost', 'you win', 'draw game']
    
    judgement = [row1, row2, row3]
    
    if mine == 0:
      print(rock)
    elif mine == 1:
      print(paper)
    else:
      print(scissors)
    
    if com == 0:
      print(rock)
    elif com == 1:
      print(paper)
    else:
      print(scissors)
    
    print(judgement[mine][com])
    
    # refactoring by teacher
    
    game_image = [rock, paper, scissors]
    
    user_choice = int(input("what do you choose? Type 0 for Rock, 1 for Paper, or 2 for Scissors \n"))
    computer_choice = random.randint(0,2)
    
    if user_choice >= 3 or user_choice < 0:
      print("you put the invalied number, you lose")
    else:
      print(game_image[user_choice])
      print("computer chose:")
      print(game_image[computer_choice])
    
      if user_choice == 0 and computer_choice == 2:
        print("you win")
      elif computer_choice == 0 and user_choice == 2:
        print("you lose")
      elif user_choice > computer_choice:
        print("you win")
      elif computer_choice > user_choice:
        print("you lose")
    
    

    debugging!!

    'TIL > 202103' 카테고리의 다른 글

    210330 TIL  (0) 2021.03.30
    210324 TIL  (0) 2021.03.25
    210323 TIL  (0) 2021.03.24
    210317 TIL  (0) 2021.03.17
    210311 TIL  (0) 2021.03.12
Designed by Tistory.