5

May I please have a little help? (entry level python. not hard for non noobs I swear)

view full story
linux-howto

http://www.daniweb.com – Now...when done. the output should look like this: >>> main() Welcome to the game of BULLS and COWS. The objective in this game is for you to guess a 4-digit number The computer responds with how close your guess is to the target BULLS = # common digits with exact matches and COWS = # common digits in wrong position. Enter guess number 1: 1876 Bulls = 1 Cows = 1 Enter guess number 2: 1183 Your guess should not contain repeating digits Enter guess number 2: 1596 Bulls = 1 Cows = 2 Enter guess number 3: 1956 Bulls = 3 Cows = 0 Enter guess number 4: 1954 Bulls = 3 Cows = 0 Enter guess number 5: 1958 Bulls = 4 Cows = 0 Congratulations You Won!! and Welcome to the game of BULLS and COWS. The objective in this game is for you to guess a 4-digit number The computer responds with how close your guess is to the target BULLS = # common digits with exact matches and COWS = # common digits in wrong position. Enter guess number 1: 1234 Bulls = 0 Cows = 1 Enter guess number 2: 2345 Bulls = 0 Cows = 0 Enter guess number 3: 1678 Bulls = 0 Cows = 3 Enter guess number 4: 1679 Bulls = 0 Cows = 3 Enter guess number 5: 1670 Bulls = 0 Cows = 4 Enter guess number 6: 6170 Bulls = 0 Cows = 4 Enter guess number 7: 6710 Bulls = 1 Cows = 3 Enter guess number 8: 7610 Bulls = 2 Cows = 2 Enter guess number 9: 7601 Bulls = 1 Cows = 3 Enter guess number 10: 6701 Bulls = 0 Cows = 4 Sorry You ran out of guesses!! The correct number was: 7016 I already have the smaller programs needed to run the main...I just don't know how to set up the main function to make it work. this is what I have so far. from myro import * from Bulls import * def extractDigits(num): return [(num/1000)%10,(num/100)%10,(num/10)%10,… def numberOfBulls(num1, num2): c3,c2,c1,c0 = extractDigits(num1) d3,d2,d1,d0 = extractDigits(num2) bulls = 0 if(d3 == c3): bulls = bulls + 1 if (d2 == c2): bulls = bulls + 1 if (d1 == c1): bulls = bulls + 1 if (d0 == c0): bulls = bulls + 1 return bulls def numberOfCows (num1,num2): c3,c2,c1,c0 = extractDigits(num1) d3,d2,d1,d0 = extractDigits(num2) cows = 0 if ((d3 == c2)or(d3 == c1)or(d3 == c0)): cows = cows + 1 if ((d2 == c3)or(d2 == c1)or(d2 == c0)): cows = cows + 1 if ((d1 == c3)or(d1 == c2)or(d1 == c0)): cows = cows + 1 if ((d0 == c3)or(d0 == c2)or(d0 == c1)): cows = cows + 1 return cows def noRepeatingDigits(num): d3 = (num / 1000) % 10 d2 = (num / 100) % 10 d1 = (num / 10) % 10 d0 = (num / 1) % 10 return ((d3 != d2) and (d3 != d1) and (d3 != d0) and (d2 != d1) and (d2 != d0) and (d1 != d0)) def produceTarget(): while True: num = randint (1000,9999) if (numberOfBulls(num1, num2)): break return num def welcomeMessage(): print "Welcome to the game of BULLS and COWS." print "The Objective in this game is for you to guess a 4-digit number" print "The computer responds with how close your guess is to the target" print "BULLS = # common digits with exact matches and" print "COWS = common digits in wrong position." def main(): maxTurns = 10 turns = 1 guess = input("Enter guess number", turns,": " ) welcomeMessage() while turns != maxTurns: noRepeatingDigits(produceTarget()) if guess if numberOfBulls != 4: turns = turns + 1 see? my main functions kind of a little sketchy to even start out with...can you guys please help me? (General)