본문 바로가기
프로그램/Python 1000제

Python 227제] 두근두근 파이썬(개정판) CHAPTER 5 연습문제 p157

by 건티 2023. 11. 27.
728x90

출처 : 반크_반크 20년 백서

 

12.

참고풀이]

N=int(input("출생년도를 입력하시오 : "))

if N%10==0 or N%10==5:
    chk="월"
elif N%10==1 or N%10==6:
    chk="화"
elif N%10==2 or N%10==7:
    chk="수"
elif N%10==3 or N%10==8:
    chk="목"
else:
    chk="금"

print("\n"+chk+"요일에 접종가능합니다.")

 

참고풀이 결과]

 

 

13.

참고풀이1]

import random

com=random.randrange(3)
#0:가위, 1:바위, 2:보로 정한다.
player=input("가위, 바위, 보를 입력하시오 : ")

if com==0:
    computer="가위"
elif com==1:
    computer="바위"
else:
    computer="보"

print("컴퓨터 : "+computer)
if player=="가위" and computer=="보":
    print("컴퓨터가 졌습니다.")
elif player=="가위" and computer=="바위":
    print("사용자가 졌습니다.")
elif player=="바위" and computer=="가위":
    print("컴퓨터가 졌습니다.")
elif player=="바위" and computer=="보":
    print("사용자가 졌습니다.")
elif player=="보" and computer=="바위":
    print("컴퓨터가 졌습니다.")
elif player=="보" and computer=="가위":
    print("사용자가 졌습니다.")
else:
    print("사용자와 컴퓨터는 비겼습니다.")

참고풀이 결과1]

 

 

참고풀이2]

import random

com=random.randrange(3)
#0:가위, 1:바위, 2:보로 정한다.
player=input("가위, 바위, 보를 입력하시오 : ")

if player=="가위":
    pla=0
elif player=="바위":
    pla=1
else:
    pla=2

if com==0:
    computer="가위"
elif com==1:
    computer="바위"
else:
    computer="보"

#결과출력
print("컴퓨터 : "+computer)

if pla>com:
    if pla==2 and com==0:
        print("사용자가 졌습니다.")
    else:
        print("컴퓨터가 졌습니다.")
elif pla==com:
    print("사용자와 컴퓨터는 비겼습니다.")
else:
    if pla==0 and com==2:
        print("컴퓨터가 졌습니다.")
    else:
        print("사용자가 졌습니다.")

참고풀이2 결과]

 

 

 

 

 

 

대한민국의 아름다운 영토, 독도의 겨울

 

반응형

댓글