티스토리 뷰

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import random
while True:
    try:
        MAX_WIN = int(input("몇선승이 승리합니까? : "))
        break
    except:
        print("숫자로 입력해 주세요.\n")
    
player_win = 0
computer_win = 0
draw = 0
result = ""
while True:
    player = input("\n(가위, 바위, 보) 중에서 하나를 선택하세요: ")#입력
    number = random.randint(0,2)#난수 생성
 
    #컴퓨터가 낼거 선택
    if number == 0:
      computer = "가위";
    elif number == 1:
      computer = "바위";
    else:
      computer = "보";
      
    print("사용자 : ", player, "   컴퓨터 : ", computer)#사용자와 컴퓨터가 낸 것 출력
    
    #승패 결과 출력
    
    try:#잘못된 입력 예외처리
        if player == computer:
          print("비겼음!");
          draw+=1
          
        if player == "바위":
          if computer == "보":
            print("컴퓨터가 이겼음!")
            computer_win+=1
          elif computer == "가위":
            print("사용자가 이겼음!")
            player_win+=1
 
            
        if(player == "보"):
          if computer == "바위" :
            print("사용자가 이겼음!")
            player_win +=1
          elif computer == "가위":
            print("컴퓨터가 이겼음!")
            computer_win+=1
 
 
        if player == "가위":
          if computer == "보":
            print("사용자가 이겼음!")
            player_win += 1
          elif computer == "바위":
            print("컴퓨터가 이겼음!")
            computer_win+=1
            
    except:
        print("올바른 형식으로 입력해 주세요.")
    if computer_win is MAX_WIN or player_win is MAX_WIN:
        break;
    print("전적은 {0}승 {1}패 {2}무 입니다.\n".format(player_win,computer_win,draw))
    
if player_win is MAX_WIN:
    result = "승리"
else:
    result = "패배"
    
print("\n컴퓨터와의 대결에서 {0}승 {1}패 {2}무로 {3}하셨습니다.\n".format(player_win,computer_win,draw,result))
 
cs
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함