#python #code #game #updowngame #개발 #부트캠프 #스파르타코딩 #웹개발 #파이썬
-
파이썬으로 업다운 게임 만들기Python 2024. 7. 2. 22:57
업다운 게임 코드 짜기 일단 컴퓨터가 유저가 맞출 숫자를 하나 랜덤으로 뽑아야 하니 random 모듈을 import 했다.게임이 시작될 때마다 1부터 100사이의 숫자 하나를 뽑는 건 계속 반복되는 일이니까 제일 먼저 함수로 만들어두고.import randomdef up_down_game(): return random.randint(1, 100) attempts는 시도 횟수 때문에 만들어줬는데, 처음에는 그냥 attempts = 0 이렇게만 했다. 근데 만들고보니 총 시도 횟수를 구해야 해서 나중에 total_attempts 리스트를 추가했다. 컴퓨터가 랜덤으로 숫자를 뽑는게 게임의 가장 첫번째 순서이기 때문에total_attempts = []print("UpDown 게임을 시작합니다.")while..