Last active
December 6, 2018 15:45
-
-
Save hanjae-jea/2ba561734ab8136e5dbc71de9653646e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
from tkinter import messagebox | |
class Person: | |
def __init__(self, heightV, weightV, nameV): | |
self.height = heightV | |
self.weight = weightV | |
self.name = weightV | |
self.dist = 0 | |
def earn(self, salary): | |
print("한달에 {}은 {} 용돈을 받습니다".format(self.name, salary)) | |
def speaking(self, *args): | |
print(' '.join([arg for arg in args])) | |
def walking(self, distance): | |
self.dist = distance | |
class Student(Person): | |
def __init__(self, height, weight, nameV, school): | |
self.school = school | |
super().__init__(height, weight, nameV) | |
def earn(self, salary): | |
print("한달에 {}은 {} 용돈을 받습니다".format(self.name, salary)) | |
def goSchool(self): | |
print("{}은 {} 학교에 월요일부터 금요일까지 다닙니다".format(self.name, self.school)) | |
def __add__(self, other): | |
return self.dist + other.dist | |
def quit(): | |
window.quit() | |
window.destroy() | |
def info(): | |
messagebox.showinfo("INFORMATION", "누적합, 누적곱, 제곱값을 구하는 프로그램\n2018년 12월 작성\nby 컴퓨터학과 14학번 제한재") | |
def calc(): | |
try: | |
mini = int(tEntry1.get()) | |
maxi = int(tEntry2.get()) | |
if not 0 <= mini <= 10: | |
messagebox.showinfo("Error", "최솟값이 0보다 작거나 10보다 큽니다") | |
elif not 3 <= maxi <= 20: | |
messagebox.showinfo("Error", "최댓값이 3보다 작거나 20보다 큽니다") | |
else: | |
r = 0 | |
if rbk.get() is 1: | |
r = 0 | |
for i in range(mini, maxi+1): | |
r += i | |
elif rbk.get() is 2: | |
r = 1 | |
for i in range(mini, maxi+1): | |
r *= i | |
elif rbk.get() is 3: | |
r = 1 | |
for i in range(maxi): | |
r *= mini | |
res.set(str(r)) | |
return | |
finally: # 변환 실패 or | |
rem() | |
def rem(): | |
tEntry1.delete(0, 'end') | |
tEntry2.delete(0, 'end') | |
res.set('계산 결과:') | |
if __name__ != '__main__': | |
yuna = Student(160, 50, 'Yuna', 'Korea') | |
hong = Student(170, 60, 'Gil-Dong', 'Anam') | |
print("{}은 키가 {},몸무게는 {} 입니다 ".format(yuna.name, yuna.height, yuna.weight)) | |
yuna.earn(200000) | |
yuna.goSchool() | |
yuna.speaking('안녕하세요', '유나입니다', '반갑습니다') | |
hong.speaking('저는 길동입니다', '반갑습니다') | |
print() | |
print("{}은 키가 {}, 몸무게는 {} 입니다".format(hong.name, hong.height, hong.weight)) | |
print() | |
yuna.walking(200) | |
hong.walking(300) | |
print('Yuna와 Gil-Dong 이 걸은 총 거리는 ', yuna + hong) | |
if __name__ == '__main__': | |
window = Tk() | |
window.title('Calculation Program') | |
window.geometry('400x300') | |
# Menu | |
menu = Menu(window) | |
fileMenu = Menu(menu, tearoff=0) | |
fileMenu.add_separator() | |
fileMenu.add_command(label="Exit", command=quit) | |
menu.add_cascade(label="File", menu=fileMenu) | |
helpMenu = Menu(menu, tearoff=0) | |
helpMenu.add_separator() | |
helpMenu.add_command(label="info", command=info) | |
menu.add_cascade(label="Help", menu=helpMenu) | |
window.config(menu=menu) | |
rbk = IntVar() | |
tt = ["누적합", "누적곱", "지수값"] | |
rb = [] | |
for idx,t in enumerate(tt): | |
rb.append(Radiobutton(window, text=t, variable=rbk, value=idx+1, width=10)) # 누적합 | |
rb[-1].grid(row=1, column=idx, padx=5, pady=5) | |
Label1 = Label(window, text="최솟, 최댓값 입력", fg="red") | |
Label1.grid(row=2) | |
tLabel1 = Label(window, text="최솟값(1-10)입력:") | |
tLabel1.grid(row=3, column=0, padx=5) | |
tEntry1 = Entry(window, bd=3, width=20) | |
tEntry1.grid(row=3, column=1, padx=5, sticky=E) | |
tLabel2 = Label(window, text="최댓값(3-20)입력:") | |
tLabel2.grid(row=4, column=0, padx=5) | |
tEntry2 = Entry(window, bd=3, width=20) | |
tEntry2.grid(row=4, column=1, padx=5, sticky=E) | |
res = StringVar() | |
res.set('계산 결과:') | |
Label2 = Label(window, textvariable=res, fg='red') | |
Label2.grid(row=5) | |
btn1 = Button(window, text='계산', fg='blue', command=calc) | |
btn2 = Button(window, text='삭제', fg='blue', command=rem) | |
btn1.grid(row=6, column=1) | |
btn2.grid(row=6, column=2) | |
window.mainloop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1 | |
tt = int(input()) | |
print("%d시간 %d분 %d초" % (tt/3600, tt/60%60, tt%60)) | |
# 2 | |
print("임진왜란은\n1592년(선조 25년)부터\n1598년까지 2차에 걸친\n'왜군의 침략'으로\n일어난 전쟁이다.") | |
# 3 | |
f = int(input("첫번째 정수 입력>> ")) | |
s = int(input("두번째 정수 입력>> ")) | |
print("덧셈, 뺄셈, 곱셈, 나눗셈, 나누기의 몫, 나누기의 나머지 계산\n") | |
print("{:6d} +{:6d} = {:10d}".format(f, s, f+s)) | |
print("{:6d} -{:6d} = {:10d}".format(f, s, f-s)) | |
print("{:6d} *{:6d} = {:10d}".format(f, s, f*s)) | |
print("{:6d} /{:6d} = {:10.2f}".format(f, s, f/s)) | |
print("{:6d} +{:6d}의 몫:{:8d}".format(f, s, f//s)) | |
print("{:6d} +{:6d}의 나머지:{:5d}".format(f, s, f%s)) | |
# 4 | |
pi = 3.14159 | |
print("{:010.3f}".format(pi)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1 | |
while True: | |
yy = int(input("연도를 입력하세요: ")) | |
if yy < 0: | |
print("program end!") | |
break | |
if yy % 400 == 0 or yy % 4 == 0 and yy % 100 != 0: | |
print("%d년은 윤년입니다." % yy) | |
else: | |
print("%d년은 평년입니다." % yy) | |
# 2 | |
n = int(input("정수를 입력하세요")) | |
res = [] | |
for i in range(1, n+1): | |
if n % i == 0: | |
res.append(i) | |
print(res) | |
# 3 | |
matrixA = [[i*3+j for j in range(1, 4)] for i in range(3)] | |
matrixB = [[(i*3+j)*2 for j in range(1, 4)] for i in range(3)] | |
res = [] | |
for i in range(3): | |
res.append([]) | |
for j in range(3): | |
res[-1].append(0) | |
for k in range(3): | |
res[-1][-1] += matrixA[i][k] * matrixB[k][j] | |
print(matrixA, matrixB, res) | |
# 4 | |
import random | |
res = random.randint(1, 20) | |
chance = 3 | |
inp = [] | |
while chance > 0: | |
inp.append(int(input("1~20사이의 정수 입력 >> "))) | |
if res == inp[-1]: | |
print("You Win!!") | |
break | |
chance = chance - 1 | |
if chance == 0: | |
print("You Lose!!") | |
print("Your input number : " , inp) | |
print("computer random number: %d" % res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment