본문 바로가기

솔루션모음/파워 유저를 위한 파이썬 express 실습문제14

[파워 유저를 위한 파이썬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.
[파워 유저를 위한 파이썬express] 8장 프로그래밍 programming 솔루션 답지 1. class Cat: def __init__(self, name, age): self.__name = name self.__age = age def setName(self, name): self.__name = name def getName(self): return self.__name def setAge(self, age): self.__age = age def getAge(self): return self.__age missy = Cat('Missy', 3) lucky = Cat('Lucky', 5) print (missy.getName(), missy.getAge()) print (lucky.getName(), lucky.getAge()) 3. class Box(): def __init__(se.. 2023. 1. 8.
[파워 유저를 위한 파이썬express] 7장 프로그래밍 programming 솔루션 답지 1. def unique_sort(lst): return sorted(set(lst)) lst = [80, 20, 20, 30, 60, 30] print("주어진 리스트", lst) newLst = unique_sort(lst) print("정렬된 리스트", newLst) 3. d = {"Apple": 1, "Banana": 2, "Grape": 3} for key, value in d.items(): print(key, "-> ", d[key]) 5. myDict = {"옷": 100, "컴퓨터": 2000, "모니터": 320} print("총합계=", sum(myDict.values())) 7. mydict = {} for i in range(2): date = input("날짜를 입력하시오: ").. 2023. 1. 8.