๐Python/๐ฉ๐ซclass
๐ฉ๐ซclass : โจ14week(์ํ ์์ ๋ฌธ์ ๋ฐ ์ค์ต ํ์)
4:Bee
2023. 12. 9. 06:28
728x90
continue ์ด์ฉํ๊ธฐ
for n in range(1,6) :
if n == 4 :
#4๋ฅผ ์ ์ธํ๊ณ (์ฆ,ํ์ฑํ ๋ continue๋ก ์ธํด์ ์๋ print๋ฅผ ์๋ต) ์ถ
continue
print(n, end=' ') #1 2 3 5
print('The End')
for n in range(1,21):
if n%3 == 0 :
continue
print(n,end=' ') #1 2 4 5 7 8 10 11 13 14 16 17 19 20
์ด์ค ํจ์๋ฅผ ์ฌ์ฉํ 3์ ๋ฐฐ์ ๋ง๋ค๊ธฐ
def threeMultiple(n):
if(n % 3 == 0) :
return True #boolen์ผ๋ก ๊ฐ์ ๋ฐํ
else:
return False
#three = threeMultiple(4)
#print(three)
def threeMuls2(num):
for n in range(1,num) :
if threeMultiple(n): #3์ ๋ฐฐ์๋ง ์ฒ๋ฆฌํ๋ ํจ์๋ฅผ ์ด์ฉํด if๋ฌธ ์ฒ๋ฆฌ
print(n, end = ' ')
print()
threeMuls2(31)
ํจ์์ ์ฌํ์ฉ์ผ๋ก ์ฌ๋ฌ ์ํ ๋ง๋ค๊ธฐ
import turtle as t
def draw_circle(x,y,radius):
t.up()
t.goto(x,y)
t.down()
t.circle(radius)
draw_circle(100,50,100)
draw_circle(-100,50,40)
draw_circle(100,-50,30)
draw_circle(-100,-50,70)

onclick์ ์ด์ฉํด ์ํ ๊ทธ๋ฆฌ๊ธฐ
import turtle as t
sc = t.Screen()
def draw_circle(x,y):
t.up()
t.goto(x,y)
t.down()
t.circle(100)
sc.onclick(draw_circle)
sc.mainloop()

onscreenclick์ผ๋ก ํด๋ฆญํ ์์น์ ๋ณ ๋ง๋ค๊ธฐ -> forward์ goto์ ์ฐจ์ด๋ฅผ ์ฐพ์๋ณด์ (event_star.py)
import turtle as turtle
t = turtle.Turtle()
turtle.bgcolor("black")
def star(length):
for n in range(5):
t.forward(length) #forward์ goto์ฐจ์ด๋?
t.left(144)
def s_draw(x,y):
t.up()
t.goto(x,y)
t.down()
t.color("yellow")
t.begin_fill()
star(50)
t.end_fill()
scr = turtle.Screen()
scr.onscreenclick(s_draw)

ํด๋น ์ฝ๋์ ์๋ forward์ goto์ ์ฐจ์ด๋ฅผ ์๊ฐํด๋ณด๊ณ ์ฐพ์๋ณด์.
input์ผ๋ก ๊ณ์ฐ๊ธฐ ๋ง๋ค๊ธฐ -> ๊ณ์ฐ๊ธฐ ๋ง๋ค๊ธฐ ์ค์ต (evnet_op.py)
#ํ๋์ ํจ์๋ก ํตํฉํด๋ณด๋ผ
def add(n1,n2):
return n1+n2
def subtract(n1,n2):
return n1-n2
def multiply(n1,n2):
return n1*n2
def divide(n1,n2):
return n1/n2
num1 = int(input("์ฒซ ๋ฒ์งธ ์ ์ : "))
num2 = int(input("๋ ๋ฒ์งธ ์ ์ : "))
op = input("์ฐ์ฐ์ ์
๋ ฅ : ")
if op == "+":
res = add(num1, num2)
elif op == "-":
res = subtract(num1, num2)
elif op == "*":
res = multiply(num1, num2)
elif op == "/":
res = divide(num1, num2)
else : print(op + "๋ ์๋ชป๋ ์ฐ์ฐ์ ์
๋๋ค.")
print(num1, op, num2, '=', res)
ํด๋น ์ฝ๋๋ฅผ ๊ฐ์ง๊ณ UI๋ฅผ ์ง์ ์ ์ํด์ ๊ณ์ฐ๊ธฐ๋ฅผ ๋ง๋ค์ด๋ณด์.
728x90