카테고리 없음

#3.6 Python Casino

규지니어스 2022. 9. 9. 11:20

while문과 게임을 합치기
(if, else, elif 복습)

from random import randint, uniform

print("Welcome to Python Casino")
pc_choice = randint(1, 100)

playing = True

while playing:
  user_choice = int(input("Choose number(1-100) > "))
  if user_choice == pc_choice:
    print("You Won!")

    playing = False 
  elif user_choice > pc_choice:
    print("Lower!")
  elif user_choice < pc_choice:
    print("Higher!")

> 게임 실행 결과

Welcome to Python Casino
Choose number(1-100) > 50
Higher!
Choose number(1-100) > 70
Higher!
Choose number(1-100) > 80
Lower!
Choose number(1-100) > 75
You Won!


----------------------------------------------
from random import randint, uniform

1.컴퓨터 먼저 출력하기 
print("Welcome to Python Casino")
pc_choice = randint(1, 50)

playing = True

2. 유저가 이길 때 까지 반복(탭 이용)
while playing:
  user_choice = int(input("Choose number > "))
  if user_choice == pc_choice:
    print("You Won!")
    playing = False // false가 될 때 까지 게임진행
                   //playing은 게임이 True일 때만 진행
  elif user_choice > pc_choice:
    print("Lower! Computer chose", pc_choice)
    //pc가 선택한 값 모르도록, pc_choice 삭제하기
  elif user_choice < pc_choice:
    print("Higher! Computer chose", pc_choice)


잘한점: 파이썬 게임하기!