파이썬 가위바위보
조회수 1859회
from tkinter import *
import random
com = {'가위','바위','보'}
user = {'가위', '바위', '보'}
def rcp_game( ) :
com = random.choice(['가위', '바위', '보'])
user =(['가위', '바위', '보'])
if (user=='가위' and com=='보') or (user=='바위' and com =='가위')or(user=='보' and com=='바위') :
lbl2.configure(text="사용자 승")
lbl3 = Label(root, image = photo1)
lbl3.place(x=100, y=30)
elif (user=='가위' and com=='가위') or (user=='바위' and com =='바위') or(user=='보' and com=='보') :
lbl2.configure(text="무승부")
lbl3 = Label(root, image = photo2)
lbl3.place(x=100, y=30)
elif (user=='가위' and com=='바위') or (user=='바위' and com =='보') or(user=='보' and com=='가위') :
lbl2.configure(text="컴퓨터 승")
lbl3 = Label(root, image = photo3)
lbl3.place(x=100, y=30)
else:
lbl2.configure(text="다시 입력")
lbl3 = Label(root, image = photo2)
lbl3.place(x=100, y=30)
root = Tk()
root.title("가위바위보")
root.geometry("230x120")
photo1 = PhotoImage(file = "smile.png")
photo2 = PhotoImage(file = "try.png")
photo3 = PhotoImage(file = "cry.png")
lbl1 =Label(root, text="사용자")
ent =Entry(root)
lbl2 = Label(root, text ="승패결과")
btn = Button(root, text = "확인", command= rcp_game)
lbl1.place(x= 10, y=10)
ent.place(x=50, y=10)
btn.place(x=50, y=40)
lbl2.place(x=50, y=80)
root.mainloop()
여기서 else부분만 실행이 돼요. 그냥 프로그램 작동이 안 한다는 소리겠죠. 왜 그럴까요?
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
1 답변
-
네 맞습니다. 현재로서는
rcp_game()
의 어떤 if 구간도 실행되지 않아요. 왜냐?def rcp_game( ) : com = random.choice(['가위', '바위', '보']) user =(['가위', '바위', '보']) # 이 시점에서 user 는 그냥 튜플 if (user=='가위' and com=='보') or (user=='바위' and com =='가위')or(user=='보' and com=='바위') : # 이 시점에서도 user 는 그냥 튜플이므로 문자열 '가위' 따위와 비교해 보아야 참이 될 수 없음
rcp_game()
이 사용자의 선택(가위냐 바위냐 등)을 인자로 받아야 할걸요.rcp_game(userInput)
하는 식으로요.다시 시도해 보세요.
- 'rcp_game()이 사용자의 선택(가위냐 바위냐 등)을 인자로 받아야 할걸요'이거를 할 줄 몰라요...ㅠㅠㅠㅠ매개변수를 받는 식으로 하는 건가요? 어떻게 해야 하는지 모르겠어요... 알 수 없는 사용자 2020.5.10 15:39
- 네 매개변수를 받는 식으로요. 아무튼 사용자의 입력을 이용해서 if 문이 실행되게 해주세요. 엽토군 2020.5.11 09:55
댓글 입력