파이썬 GUI, 넘파이 연습
1. 움직이는 애니메이션 공 프로그램을 작성하시오. ''' 움직이는 애니메이션 공 프로그램을 작성하시오. ''' from tkinter import* import random import time window = Tk() canvas = Canvas(window, width=600, height=400) canvas.pack() class Ball(): def __init__(self, color, size): self.id = canvas.create_oval(0, 0, size, size, fill=color) self.dy = random.randint(1,10) self.dx = random.randint(1, 10) self.dz = random.randint(1, 10) ball1 = Ball..
더보기
Python 클래스, 객체, GUI
● 파이썬 클래스, 객체 개념, 코드 연습 class Television: def __init__(self, channel, volume, on): self.channel = channel self.volume = volume self.on = on def show(self): print(self.channel,self.volume, self.on) def setChannel(self, channel): self.channel = channel def getChannel(self): return self.channel t = Television(9, 10, True) t.show() t.setChannel(90) t.show() ''' 원을 클래스로 구현하시오. 클래스 이름은 Circle로 한다. - 생..
더보기
Python set, 객체 개념 정리
# 집합(Set) 자료형 (순서X, 중복X) # 집합(Set) 자료형 (순서X, 중복X) # 선언 a = set() b = set([1, 2, 3, 4]) c = set([1, 4, 5, 5]) d = set([1, 2, 'pen', 'seoul', 'air']) print('a : ', type(a), a) print('b : ', type(b), b) print('c : ', type(c), c) print('d : ', type(d), d) # 튜플 변환 t = tuple(b) print('t : ', type(t), t) print('t : ', t[0], t[1:3]) #리스트 변환 l = list(c) print('l : ', type(l), l) print('l : ', l[0], l[1:3..
더보기
파이썬 statistics 모듈 활용, set, 가위바위보 게임 프로그램
1. 리스트 안 통계치 (평균, 최빈값, 중간값, 표준편차 등) 구하기 import statistics sample = [2, 3, 4, 5, 6, 7, 8, 7, 7] print(f"입력 리스트={sample}") print(f"평균={statistics.mean(sample)}") print(f"중간값={statistics.median(sample)}") print(f"최빈값={statistics.mode(sample)}") print(f"표준편차={statistics.stdev(sample)}") 2. set s = set() s = {1, 2, 5} #추가 s.add(10) s.add(3) print(s) #삭제 s.discard(5) print(s) s.remove(1) print(s) #s.r..
더보기
Python matplotlib이란 무엇인가?
1. 시각화의 필요성 - 데이터를 효과적으로 보여주는 방법 - 데이터들의 분포를 표를 이용하여 정리할 수 있음(직관적이진 않음) - 데이터들의 분포를 한눈에 알아볼 수 있도록 시각화 import matplotlib as mpl import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('y label') plt.xlabel('x label') plt.show() 2. 막대그래프 import matplotlib.pyplot as plt x = ['A', 'B', 'C', 'D', 'E'] y = [10, 7, 15, 8, 12] plt.bar(x, y) plt.xlabel('x label') plt.ylabel('y label') plt.show() 주..
더보기
파이썬 딕셔너리 연습
딕셔너리. 사전에서 뭘 꺼낸다. key값과 value 값을 꺼낸다. 둘은 한 쌍이다. # 딕셔너리 자료형 선언 a = {'name': 'earth', 'phone': '01023459393', 'birth': '20100101'} b = { 0: 'hello Earth!'} c = {'arr': [1,2,3,4,5]} print('a : ', type(a), a) print('b : ', type(b), b) print('c : ', type(c), c) #출력 print('a : ', a['name']) #존재X => 에러발생 print('a : ', a.get('phone')) #존재X => None 처리 print('b : ', b[0]) print('b : ', b.get(0)) print('c ..
더보기
Python으로 환전 프로그램 만들기
def exchange(money, country): if country in country_list: code = country_list.index(country) else: print("해당 국가 정보가 없습니다.") return result = round(money / rate[code], 2) print(money, "원은", result, unit[code], "입니다") country_list = ['중국', '미국', '유럽', '일본'] unit = ['위안', '달러', '유로', '엔'] rate = [190.36, 1330.00, 1432.15, 979.96] money = int(input("환전 금액(원)을 입력하세요 :")) country = input("국가를 입력하세요 :")..
더보기