728x90
반응형

 

 

 

8.

outFile = None
inFile = None
outStr = ""
inStr = ""
idx = 1

inFile = open("C:/FirstPython/Chapter09/normal.txt", "r", encoding="UTF-8")
outFile = open("C:/FirstPython/Chapter09/normal_line.txt", "w")

while True :
    inStr = inFile.readline()
    if inStr == "" :
        break
    outFile.writelines(str(idx) + " : " + str(inStr))
    idx += 1

inFile.close()
outFile.close()

 

 

 

9.

import turtle
import random

outFile = None
inFile = None
inStr = ""
res = ""
inList = []

outFile = open("C:/FirstPython/Chapter09/turtle.txt", "w")
colorList = ['red', 'blue', 'gray', 'black', 'magenta', 'orange']

turtle.screensize(500,500)
turtle.shape('turtle')
turtle.penup()
turtle.speed(5)

for i in range(50) :
    color = random.choice(colorList)
    size = random.randint(1,4)
    x = random.randint(-250,250)
    y = random.randint(-250,250)
    angle = random.randint(0,360)
    
    res = color + ", " + str(size) + ", " + str(x) + ", " + str(y) + ", " + str(angle) + ", \n"
    outFile.writelines(res)

outFile.close()

inFile = open("C:/FirstPython/Chapter09/turtle.txt", "r", encoding="UTF-8")
inList = inFile.readlines()

for inStr in inList :
    turtle.stamp()
    turtle.fillcolor(inStr.split(", ")[0])
    turtle.pencolor(inStr.split(", ")[0])
    turtle.turtlesize(int(inStr.split(", ")[1]))
    turtle.goto(int(inStr.split(", ")[2]),int(inStr.split(", ")[3]))
    turtle.right(int(inStr.split(", ")[4]))
    

inFile.close()
turtle.done()
728x90
반응형
728x90
반응형

 

 

 

10.

def myFunc() :
    num1 = float(input("숫자 1 ==> "))
    num2 = float(input("숫자 2 ==> "))

    print(num1, "+", num2, "=", num1+num2)
    print(num1, "-", num2, "=", num1-num2)
    print(num1, "*", num2, "=", num1*num2)
    print(num1, "/", num2, "=", num1/num2)

myFunc()

 

 

 

 

11.

import random
import turtle

def writeKorean36(ch, radius, angle) :
    turtle.goto(0,0)
    color = random.choice(colorList)
    turtle.pencolor(color)
    turtle.forward(radius)
    turtle.right(angle)
    turtle.write(ch, font=("맑은고딕", 10, 'bold'))

colorList = ['red', 'blue', 'magenta', 'orange', 'green', 'gray']
koreanStr = """ 나랏말싸미 듕귁에 달아 문짜와로 서르 사맛디 아니할쌔 이런 젼차로 어린 백셩이 니르고
                져 홀 배 이셔도 마참내 제 뜨들 시러 펴디 못할 노미 하니라 내 이랄 위하야 어엿비 너겨 새로
                스믈여듧 짜랄 맹가노니 사람마다 해여 수비 니겨 날로 쑤메 뼌안킈 하고져 할 따라미니라 """

turtle.shape('turtle')
turtle.penup()
turtle.speed(5)

i = 0
radius = 100

for ch in koreanStr :
    
    if ch != " " :
        angle = 0
        i += 1
        angle += 10

        writeKorean36(ch, radius, angle)

        if i%37==0 :
            radius += 50
            
        if angle == 360 :
            angle = 0
        
    
turtle.done()
728x90
반응형
728x90
반응형

 

 

 

 

 

 

 

11.

import random

myList = []
sum = 0

for i in range(0,100) :
    myValue = random.randint(1,6)
    myList.append(myValue)


for v in myList :
    sum += v

avg = sum/100

print("100번 던진 주사위 값의 평균은 ", avg, " 입니다")

 

 

12.

import turtle
import random

turtleList = []
colorList = ['green', 'blue', 'red', 'magenta', 'orange', 'black']

turtle.shape('turtle')
turtle.screensize(500,500)

for i in range(0,100) :
    color = random.choice(colorList)
    x = random.randint(-250, 250)
    y = random.randint(-250, 250)
    myTurtle = (color, x, y)
    turtleList.append(myTurtle)    

for tup in turtleList :
    turtle.color(tup[0])
    turtle.goto(tup[1],tup[2])
    turtle.stamp()

turtle.done()

 

 

728x90
반응형
728x90
반응형

 

 

9.

start = int(input("시작값 ==> "))
end = int(input("끝값 ==> "))
inc = int(input("증가값 ==> "))

sum = 0

for i in range(start, end, inc) :
    sum += i

print(start,"에서", end,"까지 ", inc,"씩 증가한 값의 합 : ", sum)

 

 

10.

import turtle
import random

colors = ['red','green','magenta','blue','black']

turtle.shape('turtle')
turtle.pensize(2)
distance = 0
cnt = 0

while True :

    distance += 10
    if cnt == 50 :
        break
    else :
        cnt += 1
        turtle.forward(distance)
        turtle.color(random.choice(colors))
        turtle.left(90)
        continue
    
turtle.done()

 

 

728x90
반응형
728x90
반응형

 

6.

year = int(input("연도를 입력 ==> "))

if year % 4 == 0 :  
    if year % 100 == 0 : 
        if year % 400 == 0 : 
            print("윤년", end='')
        else :
            print("평년", end='')
    else :
        print("윤년", end='')
else :
    print("평년",end='')

print(" 입니다")

 

 

7.

score = int(input("뽑힌 점수 : "))

if (score >= 0 and score <= 100) :
    if score >= 90 :
        print("장학생입입니다")
    elif score >= 60 :
        print("합격입니다")
    else :
        print("불합격입니다")
else :
    print("0~100점 사이를 입력해주세요")

 

 

8.

import turtle
import random

turtle.shape('turtle')
turtle.pensize(5)

turtle.screensize(300,300)
turtle.setup(330,330)
turtle.pencolor("blue")
cnt = 0

while True :
    angle = random.randint(0,360)
    distance = random.randint(10,100)
    turtle.right(angle)
    turtle.forward(distance)

    curX = turtle.xcor()
    curY = turtle.ycor()

    if (curX <= 150 and curX >= -150 and curY <= 150 and curY >= -150) :
        print("GOOD")
    else :
        cnt += 1
        if cnt == 0 :
            turtle.pencolor("blue")
        elif cnt == 1 :
            turtle.pencolor("green")
        elif cnt == 2 :
            turtle.pencolor("orange")
        elif cnt >= 3 :
            turtle.pencolor("red")

        turtle.goto(0,0)

turtle.done()
728x90
반응형
728x90
반응형

 

 

 

 

 

11.

ss = "파이썬은 재밌어요~~ Python is Funny. ^^"

print("원본 문자열 : ", ss)
print("모두 대문자로 : ", ss.upper())
print("모두 소문자로 : ", ss.lower())
print("Python 글자의 위치 :", ss.find("Python"))

 

 

12.

import turtle

turtle.shape('turtle')
turtle.penup()

while True :
    color = input("펜 색상(red, green, yellow, magenta) ==> ")
    x = int(input("X위치 ==> "))
    y = int(input("Y위치 ==> "))
    text = input("쓰고 싶은 글자 (최대 4글자) ==> ")
    text = text[3]+text[2]+text[1]+text[0]
    text = text.upper()

    turtle.goto(x,y)
    turtle.pencolor(color)
    turtle.write(text, font=("Arial", 30))
    

turtle.done()

 

 

728x90
반응형
728x90
반응형

 

 

 

 

 

 

11.

 

12.

 

728x90
반응형
728x90
반응형

 

 

 

 

10.

 

11.

 

 

728x90
반응형
728x90
반응형

 

  1. 변수 정의 및 input함수를 이용한 값 입력받기

 

 

728x90
반응형
728x90
반응형

 

 

 

 

 

728x90
반응형

+ Recent posts