💻Programming/Python

[Python/파이썬] 분기문 ( if 문 : 홀짝, 가위바위보)

horang_dev 2021. 3. 17. 12:31

1. 분기문 ( if 문 )  

if 1 > 0 :
    print('참')
else : 
    print('거짓')
    
#출력 결과
참

------------------------------------------------

#90점 이상이면 수, 80점 이상이면 우, 70점 이상이면 미, 60점 이상이면 양, 그 이하면 가

if score >= 90 :
   print('수')
elif score >= 80 :
   print('우')
elif score >= 70 :
   print('미')
elif score >= 60 :
   print('양')
else :
   print('가')

------------------------------------------------

# 홀짝 맞추기

import random
mine = input("홀/짝을 입력하세요.") #Console에서 홀짝입력받기

rnd = random.random() #랜덤으로 값 지정

com = ""
if rnd > 0.5 :
    com = "홀"
else :
    com = "짝"
    
result = ""
if com == mine :
    result = "이김"
else :
    result = "짐"
    
------------------------------------------------

#가위바위보

import random
mine = input("가위/바위/보를 입력하세요.")

rnd = random.random()

com = ""
if rnd > 0.66 :
    com = "가위"
elif rnd > 0.33 :
    com = "바위"
else:
    com = "보"
  
result = ""
if com == mine :
    result = "비김"
elif com == "가위" and mine=="바위" or com=="보" and mine == "가위" or com=="바위" and mine=="보":
    result = "이김"
else :  
    result = "짐" 
반응형