U E D R , A S I H C RSS

열파참/금요일 (rev. 1.44)

열파참/금요일

개요

4월 25일

범위

  • Ch. 1 ~ Ch. 4 중간

5월 2일

범위

  • Ch. 4
    • 4.1. if Statements
    • 4.2. for Statements
    • 4.3. The range() Function
    • 4.4. break and continue Statements, and else Clauses on Loops
    • 4.5. pass Statements
    • 4.6. Defining Functions
    • 4.7. More on Defining Functions
    • 4.8. Intermezzo: Coding Style

가장 기억에 남는 부분

  • 박희정: 전반적으로 싱기방기.
  • 원준연: arguments 관련해서 기능이 굉장히 많아서 편리한 언어라고 느낌.
  • 이원준: for / else가 너무 강렬했다.
  • 조영준: function 호출할 때 기본값이 있거나, 어느 인자에 넣을 것인지 명시하는게 신기했음.

5월 9일

범위

  • 5. Data Structures
    • 5.1. More on Lists
    • 5.2. The del statement
    • 5.3. Tuples and Sequences
    • 5.4. Sets
    • 5.5. Dictionaries
    • 5.6. Looping Techniques
    • 5.7. More on Conditions
    • 5.8. Comparing Sequences and Other Types

가장 기억에 남는 부분

  • 조영준: import를 하지 않고 다양한 data structures를 사용할 수 있다는게 신기. python의 정신(?)이 돋보인다고 해야 하나.
  • 이원준: List Comprehensions과 unpacking이 신기하고 짜증
  • 원준연: iterater가 생각보다 다양하고, 다양한 만큼 하나하나가 깐깐? 하다 느낌
  • 박희정: 개발자 편의가 물신물신 느껴짐.

5월 16일

범위

  • 6. Modules
    • 6.1. More on Modules
    • 6.2. Standard Modules
    • 6.3. The dir() Function
    • 6.4. Packages
  • 7. Input and Output
    • 7.1. Fancier Output Formatting

가장 기억에 남는 부분

  • Python님 아름다우세요! Python님 감사합니다! Python님 위대하시네요! 그런데 왜 2.0이랑 3,4랑 천지차이세요! - 원준연

5월 23일

범위

  • 7. Input and Output
    • 7.1. Fancier Output Formatting
    • 7.2. Reading and Writing Files

내용

  • 형식을 바꿔서 읽고 그 자리에서 정리하기로.
  • 새로운 참가자도 있고 방식도 바꿨으니 뒷 내용 복습.

5월 30일

범위

  • 2.8. Errors and Exceptions

실험

import sys
dir(sys) #를 심심해서 했는데 stderr를 발견.
sys.stderr = open('error.txt', 'w')

#이 다음부터 발생한 error는 콘솔에 출력되지 않고 파일로 기록됨
#stderr, stdout, stdin 등등도 가능.

7월 2일

long time no see!

내용

오랜만에 하니 문서 읽는게 아니라 코드 짜면서 워밍 업!

조영준

open("result.txt","w").write(open("source.txt").readline()[::-1])
#skywave
import sys

#set size
if len(sys.argv) == 1:
	ySize = 3
	xSize = 3
elif len(sys.argv) == 3:
	ySize, xSize = [int(x) for x in sys.argv[1:]]
else:
	print("wrong argument number(s) (arg(s) with 0 or 2 length is allowed)")
	exit()

if min(xSize, ySize) < 1:
	print("wrong list size - size should be positive")
	exit()

totalSize = ySize * xSize

#get input
userInput = [int(x) for x in input("type {0} numbers:".format(totalSize)).split()]

if len(userInput) != totalSize:
	print("wrong number of items ({0} instead of {1})".format(len(userInput), totalSize))
	exit()

#find max
intList = []
for i in range(int(len(userInput) / xSize)):
	intList.append(userInput[i * xSize:(i + 1) * xSize])
	intList[-1].append(max(intList[-1]))

intList.append([])

for i in range(xSize + 1):
	intList[-1].append(max([x[i] for x in intList[:-1]]))

#print
print(intList)

안미리

f1 = open('source.txt','r')
f2 = open('result.txt','w')

string = f1.read()
size = len(string)
nstring = string[size::-1]

f2.write(nstring)

f1.close()
f2.close()
nums1 = [0,0,0,0]
nums2 = [0,0,0,0]
nums3 = [0,0,0,0]

for i in range(0,3) :
	number = input()
	nums1[i] = int(number)

for i in range(0,3) :
	number = input()
	nums2[i] = int(number)

for i in range(0,3) :
	number = input()
	nums3[i] = int(number)

for i in range(0,3) :
	bignum = nums1[0]
	if nums1[i]>bignum:
		bignum = nums1[i]
nums1[3] = bignum

for i in range(0,3) :
	bignum = nums2[0]
	if nums2[i]>bignum :
		bignum = nums2[i]
nums2[3] = bignum

for i in range(0,3) :
	bignum = nums3[0]
	if nums3[i]>bignum :
		bignum = nums3[i]
nums3[3] = bignum

square = [nums1,nums2,nums3,[0,0,0,0]]

for i in range(0,4) :
	bignum = square[0][i]
	for j in range(0,4) :
		if square[j][i]>bignum :
			bignum = square[j][i]
	square[3][i] = bignum

for i in range(0,4) :
	for j in range(0,4) :
		bignum = square[0][0]
		if square[i][j]>bignum :
			bignum = square[i][j]

square[3][3] = bignum

for i in range(0,4) :
	print(square[i][0],square[i][1],square[i][2],square[i][3])

박희정

source = open('source.txt', 'r')
result = open('result.txt', 'w')

for line in source:
	result.write(line[::-1])

source.close()
result.close()
size = 3
result = []

for i in range(0, size):
	tempList = []
	for j in range(0, size):
		tempList.append(input("result: "))
	tempList.append(max(tempList))
	result.append(tempList)

lastList = []
for i in range(0, size):
	tempList = []
	for j in range(0, size):
		tempList.append(result[j][i])
	lastList.append(max(tempList))

lastList.append(max(lastList))

result.append(lastList)

print(result)

이원준

matrix = []

for i in range(3):
	row_max = 0
	row = []
	for j in input().split(" "):
		inputed_number = int(j)
		row.append(inputed_number)
	row.append(max(row))
	matrix.append(row)

row = []

for i in range(4):
	row.append(max(matrix[j][i] for j in range(3)))

row[-1] = max(row)

matrix.append(row)

for row in matrix:
	print(row)

7월 9일

범위


  • 9.1. A Word About Names and Objects
  • 9.2. Python Scopes and Namespaces
    • 9.2.1. Scopes and Namespaces Example
  • 9.3. A First Look at Classes
    • 9.3.1. Class Definition Syntax
    • 9.3.2. Class Objects
    • 9.3.3. Instance Objects
    • 9.3.4. Method Objects
    • 9.3.5. Class and Instance Variables

7월 16일

범위


  • 9.4. Random Remarks
  • 9.5. Inheritance
    • 9.5.1. Multiple Inheritance
  • 9.6. Private Variables
  • 9.7. Odds and Ends
  • 9.8. Exceptions Are Classes Too
  • 9.9. Iterators
  • 9.10. Generators
  • 9.11. Generator Expressions

7월 23일

범위

  • 10. Brief Tour of the Standard Library
    • 10.1. Operating System Interface
    • 10.2. File Wildcards
    • 10.3. Command Line Arguments
    • 10.4. Error Output Redirection and Program Termination
    • 10.5. String Pattern Matching
    • 10.6. Mathematics
    • 10.7. Internet Access
    • 10.8. Dates and Times
    • 10.9. Data Compression
    • 10.10. Performance Measurement
    • 10.11. Quality Control
    • 10.12. Batteries Included

7월 30일

범위

  • 11. Brief Tour of the Standard Library – Part II
    • 11.1. Output Formatting
    • 11.2. Templating
    • 11.3. Working with Binary Data Record Layouts
    • 11.4. Multi-threading
    • 11.5. Logging
    • 11.6. Weak References
    • 11.7. Tools for Working with Lists
    • 11.8. Decimal Floating Point Arithmetic

8월 6일

한 것

  • Ch. 4 ~ 6 정리
  • 간단한 회의
    • 다음 2주 동안에는 간단한 프로그래밍 연습
    • 방학 전 주에는 프로젝트 준비 시작
      • 프로젝트는 크지는 않더라도 확장이 용이해야 하며, 참가자들의 모두의 흥미를 끌 수 있는 주제로
      • 프로젝트 아이디어
        • GAE + Django + Twitter API?

8월 13일

참가자

한 것

조영준

symbol_1 = ['I', 'X', 'C', 'M']
symbol_5 = ['V', 'L', 'D']

while True:
    try:
        user_input = int(input('Input a number (1 ~ 998, 999 to exit)'))
    except Exception:
        print('not valid input')
        continue

    if user_input == 999:
        print('good bye')
        exit()

    if user_input < 1 or user_input > 998:
        print('not valid input (must be 1 ~ 998)')
        continue

    stack = []
    digit = 0
    while user_input > 0:
        current_number = user_input % 10
        current_string = ''
        user_input = int(user_input / 10)

        if current_number % 5 == 4:
            current_string += symbol_1[digit]

            if current_number == 4:
                current_string += symbol_5[digit]
            else:
                current_string += symbol_1[digit + 1]

        else:
            if current_number > 4:
                current_number -= 5
                current_string += symbol_5[digit]

            current_string += symbol_1[digit] * current_number

        stack.append(current_string)
        digit += 1

    while stack:
        print(stack.pop(), end='')

    print()

while True:
    try:
        user_input = int(input('Input a number (input < 1 to exit)'))
    except Exception:
        print('not valid input')
        continue

    if user_input < 1:
        print('good bye')
        exit()

    user_input -= 1
    result = ['0', '1']
    
    while user_input > 0:
        length = len(result)
        result *= 2

        for i in range(length):
            result[i] = '0' + result[i]
            result[i + length] = '1' + result[i + length]
        
        user_input -= 1


    print(result)

원준연

source = open('source.txt','r')
result = open('result.txt','w')

for line in source:
    romanNum=''
    isEmpty = line
    if isEmpty=='':break
    temp=int(isEmpty)
    if temp<=0:
        print('Too Small!')

    elif temp>999:
        print('Too Big!')

    elif temp==999:
        exit()

    else:
        while temp>=500:
            temp-=500
            romanNum+='D'

        while temp>=100:
            temp-=100
            romanNum+='C'

        while temp>=50:
            temp-=50
            romanNum+='L'
    
        while temp>=10:
            temp-=10
            romanNum+='X'

        if temp==1:
            romanNum+='I'
        elif temp==2:
            romanNum+='II'
        elif temp==3:
            romanNum+='III'
        elif temp==4:
            romanNum+='IV'
        elif temp==5:
            romanNum+='V'
        elif temp==6:
            romanNum+='VI'
        elif temp==7:
            romanNum+='VII'
        elif temp==8:
            romanNum+='VIII'
        elif temp==9:
            romanNum+='IX'
        romanNum+='\n'

    result.write(romanNum)

source.close()
result.close()

8월 20일

풀이

조영준

import random

def cowsnbulls(answer_length):
    if type(answer_length) != int:
        print('answer_length must be a number')
        return

    if not 1 <= answer_length <= 10:
        print('answer_length must be between 1 and 10')
        return
    
    answer = []
    numbers = list(range(10))
    playing = True

    while len(answer) < answer_length:
        answer.append(numbers.pop(random.randrange(len(numbers))))

    print(answer)
    print('Welcome to the Cows Bulls Game!')
    print('Enter a number:')

    while playing:
        try:
            user_input = [int(x) for x in list(input('>>> '))]
        except Exception:
            print('try again')
            continue

        if len(user_input) != answer_length:
            print('try again')
            continue

        if len([True for x in user_input for y in user_input if x == y]) != answer_length:
            print('try again')
            continue

        cows = len([True for x, y in zip(user_input, answer) if x == y])
        bulls = len([True for x, y in enumerate(user_input) for z, w in enumerate(answer) if y == w and x != z])

        print('{0} cow{1}, {2} bull{3}'.format(cows, 's' if cows > 1 else '', bulls, 's' if bulls > 1 else ''))

        if bulls == answer_length:
            playing = False

if __name__ == '__main__':
    cowsnbulls(4)

안미리

import random

answer = random.sample(range(10),4)
while True:
	guess = []
	error = 0
	cow = 0
	bull = 0

	nums = input("Enter a number ")

	for x in nums:
		guess.append(int(x))

	if len(guess) != 4:
		print("Wrong lenth")
		continue

	for n in range(0,4):
		for m in range(n+1,4):
			if guess[n] == guess[m]:
				error += 1

	if error > 0:
		print("Wrong number")
		continue

	for x in range(0,4):
		if answer[x] == guess[x]:
			cow += 1
	for n in range(0,4):
		for m in range(0,4):
			if n==m:
				continue
			if guess[n] == answer[m]:
				bull += 1

	if cow>1:
		print(cow,'cows'+' ')
	else:
		print(cow,'cow'+' ')

	if bull>1:
		print(bull,'bulls'+' ')
	else:
		print(bull,'bull'+' ')
	
	if cow == 4:
		print('Win')
		break

이원준

import random

print("Welcome to the Cows and Bulls Game!")
answer = random.sample(range(10), 4)

while(True):
	try:
		input_list = list(map(int, list(input("Enter a number : "))))
	except ValueError:
		continue
	finally:
		pass

	if len(input_list) != 4:
		continue
		
	cow = 0
	bull = 0

	if answer == input_list:
		print("good, kids.")
		break
	else:
		for i in range(4):
			if input_list[i] == answer[i]:
				cow+=1
			elif input_list[i] in answer:
				bull+=1

	print("your input : ", input_list)
	print("cow : ", cow, " bull : ", bull)

print(answer)
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:24
Processing time 0.0408 sec