lundi 4 janvier 2016

why my code do not display anything wher is my mistake?

i have this PYTHON script that ask the user to guess the number generate randomly by the system.

if the user guess the right place of number the system display the word cow if not id display the word bull at the end the system display the numbers of cows and bulls like this:

Welcome to the Cows and Bulls Game! 
  Enter a number: 
  >>> 1234
  2 cows, 0 bulls 

can anyone help me with my script to fix the problem ?

cows&Bulls.py

#!/usr/bin/python

import random

guessingNum = random.randint(1,4)
countC = 0
countB = 0 



def guess(num):

    for i in guessingNum:
        if i[0]==num[0]:
            print "cow"
            countC+=1
        elif i[1] == num[1]:
            print "cow"
            countC+=1
        elif i[2] == num[2]:
            print "cow"
            countC+=1
        elif i[3] == num[3]:
            print "cow"
            countC+=1
        else:
            print "Bull"
            countB +=1
    print (countC + "cows" + countB + "bulls")  


    if __name__ == "__main__":
        user = int(raw_input("guess the numbers form 1 to 4 "))
        print guess(user)

Aucun commentaire:

Enregistrer un commentaire