본문 바로가기

분류 전체보기680

[파워 유저를 위한 파이썬express] 12장 프로그래밍 programming 솔루션 답지 1. class Point(object): def __init__(self,x,y): self.x=x self.y=y def __str__(self) : return "(%d, %d)" % (self.x, self.y) class Point3D(Point): def __init__(self,x,y,z): super().__init__(x, y) self.z=z def __str__(self) : return "(%d, %d, %d)" % (self.x, self.y, self.z) my_point=Point3D(1,2,3) print(my_point) 3. import cmath # complex math 모듈 class Function: def __init__(self): pass def value(s.. 2023. 1. 8.
[파워 유저를 위한 파이썬express] 11장 프로그래밍 programming 솔루션 답지 1. count = sum([ 1 for k in range(1, 101) if k%3 == 0]) print(count) 3. subject_marks = [('국어', 88), ('수학', 90), ('영어', 99), ('자연', 82)] print("원래의 리스트:") print(subject_marks) subject_marks.sort(key = lambda x: x[1]) print("\n정렬된 리스트:") print(subject_marks) 5. nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print("원래 리스트:") print(nums) print("세제곱된 값:") cube_nums = list(map(lambda x: x ** 3, nums)) print(.. 2023. 1. 8.
[파워 유저를 위한 파이썬express] 10장 프로그래밍 programming 솔루션 답지 1. f = open("proverbs.txt","r") for i in range(3): print(f.readline()) f.close() 3. import random def random_line(fname): lines = open(fname).read().splitlines() return random.choice(lines) print(random_line('proverbs.txt')) 5. f = open('proverbs.txt' , 'r') content = f.read() f.close() mylist = content.split() mylist.insert(1, "line 2-1") f = open('myfile.txt' , 'w') for line in mylist: f.write.. 2023. 1. 8.
[파워 유저를 위한 파이썬express] 9장 프로그래밍 programming 솔루션 답지 1. from tkinter import * window = Tk() window.title("Welcome to tkinter") window.geometry('200x40') lbl = Label(window, text="Hi!") lbl.grid(column=0, row=0) def clicked(): lbl.configure(text="clicked") btn = Button(window, text="click me", command=clicked) btn.grid(column=1, row=0) window.mainloop() 3. import tkinter as tk window = tk.Tk() for i in range(3): for j in range(10): button = tk.Butt.. 2023. 1. 8.