Skip to content

Instantly share code, notes, and snippets.

@NimJ
Created March 30, 2017 10:21
Show Gist options
  • Select an option

  • Save NimJ/45ccfb541439e882988a079cd3e8b195 to your computer and use it in GitHub Desktop.

Select an option

Save NimJ/45ccfb541439e882988a079cd3e8b195 to your computer and use it in GitHub Desktop.

Revisions

  1. NimJ created this gist Mar 30, 2017.
    23 changes: 23 additions & 0 deletions Cow_bull_game.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    Class a:
    def cow_bull(self):
    import random
    cowbull = [0,0]
    count = 1
    x = random.sample([1,2,3,4,5,6,7,8,9,0],4)
    y = list(input('input 4 digits seperated by spaces \n '))
    while x != y:
    for i in range(3):
    if y[i] in x:
    if y[i] == x[i]:
    cowbull[0] += 1
    else:
    cowbull[1] += 1
    print '{0} cows and {1} bulls'.format(cowbull[0], cowbull[1])
    y = list(input('input 4 digits seperated by comma \n '))
    cowbull = [0, 0]
    count += 1
    print 'you won with {0} guesses'.format(count)

    if __name__ == '__main__':
    a = A()
    a.cow_bull()