본문 바로가기

프로그램/Python 1000제341

Python 317제] 두근두근 파이썬(개정판) CHAPTER 11 도전문제(2) p346 출처 : 반크_독도2023 참고풀이]import os arr = os.listdir() for f in arr:     infile = open(f, "r", encoding="utf-8")     L=[]     for line in infile:         e = line.rstrip() #오른쪽 줄바꿈을 삭제한다.         L.append(line)     infile.close()     outfile= open(f, "w", encoding="utf-8")     L.insert(0,"#define _CRT_SECURE_NO_WARNINGS\n")     for line in L:         outfile.write(line)     outfile.close()      참고풀이 결.. 2024. 10. 7.
Python 316제] 두근두근 파이썬(개정판) CHAPTER 11 도전문제(1) p346 출처 : 반크_독도2023 참고풀이]import os arr = os.listdir() count=0 for f in arr:     infile = open(f, "r", encoding="utf-8")     for line in infile:         count+=1         e = line.rstrip()         if "Python" in e:             print(f, count, ":", e)     infile.close() 참고풀이 결과]file.py가 저장된 디렉토리 안에 있는 파일들)실행결과)     대한민국의 아름다운 영토, 독도의 가을 2024. 10. 7.
Python 315제] 두근두근 파이썬(개정판) CHAPTER 10 연습문제 7 p334 출처 : 반크_독도2023 참고풀이]from tkinter import * import random pCount=0 cCount=0 L=["바위","보","가위"] cSu=random.randrange(3) comChk=L[cSu] def Print(p,c,S):     global pCount, cCount, cSu, comChk     Str1="사용자 점수 : " + str(pCount)     Str2="컴퓨터 점수 : " + str(cCount)     if p != c:         Str3="사용자=" + str(p) + ", 컴퓨터=" + str(c) + " " + S + " 승리!!!"     else:         Str3="사용자=" + str(p) + ", 컴퓨터=" + str(.. 2024. 10. 7.
Python 314제] 두근두근 파이썬(개정판) CHAPTER 10 연습문제 4 p333 출처 : 반크_독도2023 참고풀이]from tkinter import * import random ex=random.randrange(100) def Process():     ans=int(e1.get())     if ex>ans:         l2.config(text="Low!!", fg="blue")     elif ex        l2.config(text="High!", fg="red")     else:         l2.config(text="축하 합니다.", fg="purple")     e1.delete(0, END)      def Delete():     ex=random.randrange(100)     l2.config(text="")     e1.delete(0,END.. 2024. 9. 30.
Python 313제] 두근두근 파이썬(개정판) CHAPTER 10 연습문제 3 p332 출처 : 반크_독도2023 참고풀이]from tkinter import * import random cs=["blue","red","yellow","light blue","green","gray","pink","purple","violet"] window=Tk() window.geometry("800x700") canvas=Canvas(window, width=780, height=680) canvas.pack() for i in range(20):     x1=random.randint(0, 700)     y1=random.randint(0, 600)     size=random.randint(20, 150)     col=random.choice(cs)     canvas.create_oval(x1.. 2024. 9. 30.
Python 312제] 두근두근 파이썬(개정판) CHAPTER 10 연습문제 2 p332 출처 : 반크_독도2023 참고풀이]from tkinter import * def Process():     mile=int(e1.get())     km=mile*1.609     e2.insert(0,str(km)+"Km") window=Tk() l0=Label(window) l1=Label(window, text="마일:", anchor="w", font=("",15,"")) l2=Label(window, text="킬로미터:", anchor="w", font=("",15,"")) l3=Label(window, width=5) l4=Label(window, width=5) l5=Label(window, width=5) e1=Entry(window, width=15, font=("",15,"bold".. 2024. 9. 30.
Python 311제] 두근두근 파이썬(개정판) CHAPTER 10 연습문제 1 p332 출처 : 반크_독도2023 참고풀이]from tkinter import * window=Tk() l1=Label(window, text="이름", font=("",15,"")) l2=Label(window, text="직업", font=("",15,"")) l3=Label(window, text="국적", font=("",15,"")) e1=Entry(window) e2=Entry(window) e3=Entry(window) b1=Button(window, text="Show", font=("",15,"bold")) b2=Button(window, text="Quit", font=("",15,"bold")) l1.grid(row=0, column=0, columnspan=2) l2.grid(row=1, .. 2024. 9. 30.
Python 310제] 두근두근 파이썬(개정판) CHAPTER 10 도전문제 p330 출처 : 반크_독도2023 참고풀이]from tkinter import * window=Tk() window.title("My Calculator") display=Entry(window, width=33, bg="yellow", font=("", 15, "bold")) display.grid(row=0, column=0, columnspan=5, padx=2, pady=10) button_list = [     '7', '8', '9', '/', 'C',     '4', '5', '6', '*', '%',     '1', '2', '3', '-', ' ',     '0', '.', '=', '+', ' '] def click(key):     if key == "=":         result = e.. 2024. 9. 30.
Python 309제] 두근두근 파이썬(개정판) CHAPTER 10 도전문제 p319 출처 : 반크_독도2023 참고풀이]from tkinter import * mycolor="blue" def paint(event):     x1, y1 = (event.x-1), (event.y+1)     x2, y2 = (event.x-1), (event.y+1)     canvas.create_oval(x1, y1, x2, y2, fill=mycolor, outline=mycolor) def change_color1():     global mycolor     mycolor="blue" def change_color2():     global mycolor     mycolor="red" def change_color3():     global mycolor     mycolor="yellow".. 2024. 9. 30.
Python 308제] 두근두근 파이썬(개정판) CHAPTER 10 도전문제 p316 출처 : 반크_독도2023 참고풀이]from tkinter import * window=Tk() photo1=PhotoImage(file="dokdo01.png") photo2=PhotoImage(file="dokdo02.png") photo3=PhotoImage(file="sun01.png") photo4=PhotoImage(file="sun02.png") photo5=PhotoImage(file="rose02.png") photo6=PhotoImage(file="rose02.png") il1=Label(window, height=300, width=400, image=photo1) il2=Label(window, height=300, width=400, image=photo2) il3=Label(wi.. 2024. 9. 30.
Python 307제] 두근두근 파이썬(개정판) CHAPTER 10 도전문제 p315 출처 : 반크_독도2023 참고풀이]from tkinter import * window=Tk() window.geometry("260x240") w=Button(window, text="버튼 #1", bg="blue", fg="white") w.place(x=10, y=0) w=Button(window, text="버튼 #2", bg="purple", fg="white") w.place(x=200, y=0) w=Button(window, text="버튼 #3", bg="red", fg="white") w.place(x=10, y=200) w=Button(window, text="버튼 #4", bg="gray", fg="white") w.place(x=200, y=200) w=Button(window, t.. 2024. 9. 23.
Python 306제] 두근두근 파이썬(개정판) CHAPTER 10 도전문제 p313 출처 : 반크_독도2023 참고풀이]from tkinter import * def process1(): #화씨를 섭씨로     e2.delete(0,END)     temperature=float(e1.get())     mytemp=(temperature-32)*5/9     e2.insert(0,str(mytemp)) def process2(): #섭씨를 화씨로     e1.delete(0,END)     celsius=float(e2.get())     mytemp=celsius*9/5+32     e1.insert(0,str(mytemp)) window=Tk() l1=Label(window, text="화  씨", font="굴림 12") l2=Label(window, text="섭  씨", fo.. 2024. 9. 23.
반응형