jeudi 12 juillet 2018

Why is bulls() not giving expected output?

''' this is a code for the game 'cows and bulls' which is still under development but the bulls() is not working properly.It's somehow not giving correct output and the logic there seems to be correct to me...please tell me the problem
'''

import random

import sys

def random_generator():

    ran=[]
    for i in range(4):
        ran.append(random.randint(0,9))
    return str(ran)

def get_guess():

    print("Enter your 4 digit guess ")
    guess=input()
    return guess

def cows(ran,guess,bul):

    cow=0
    for i in range(4):
        for j in range(4):
            if ran[i]==guess[j]:
                cow+=1
    print("cows:",cow," Bulls:",bul)

def bulls(ran,guess):

    count=0
    for i in range(len(guess)):
        if ran[i]==guess[i]:
            count+=1
        else:
            continue
    if count==4:
        print("You guessed it right!")
    else:
        cows(ran,guess,count)
print("Welcome to the Cows and Bulls game!")    
ran=random_generator()

while True:

    guess=get_guess()
    bulls(ran,guess)




Aucun commentaire:

Enregistrer un commentaire