Giter Club home page Giter Club logo

codesquad's Introduction

import random

def createAnswer(): result = [] num = ['0','1','2','3','4','5','6','7','8','9'] for i in range(3): select = random.choice(num) result.append(select) num.remove(select) return ''.join(result)

def checkStrike(answer, number): result = 0 for i in range(3): if number[i] == answer[i]: result += 1 return result

def checkBall(answer, number): result = 0 for i in range(3): if number[i] == answer[(i+1)%3]: result += 1 if number[i] == answer[(i+2)%3]: result += 1 return result

def printOut(strike, ball): if strike == 0 and ball == 0: print("낫싱") elif ball == 0: print(strike, "스트라이크") elif strike == 0: print(ball, "볼") else: print(strike, "스트라이크", ball, "볼")

def baseballGame(answer): while True: number = input("숫자를 입력해주세요 ex)123 : ") printOut(checkStrike(answer, number), checkBall(answer, number)) if checkStrike(answer, number) == 3: break print("3개의 숫자를 모두 맞히셨습니다! 게임 종료")

answer = createAnswer() baseballGame(answer)

codesquad's People

Contributors

youngdo212 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.