Click here to Skip to main content
15,889,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is an array from a piece of code. How do I later on in the array call on it in order to output r1 and r2?

from collections import Counter


def main():
    answers = [3, 3, 4, 4]
    guesses = [3, 5, 6, 4]

    answers_counter = Counter(answers)
    guesses_counter = Counter(guesses)
    diff_counter = answers_counter - guesses_counter
    number_of_all_correct_digits = len(answers) - len(diff_counter.values())

    number_of_correct_digits_in_correct_place = len(
        list(filter(lambda x: x == 0, [a - g for a, g in zip(answers, guesses)])))

    number_of_correct_digits_in_wrong_place = number_of_all_correct_digits - number_of_correct_digits_in_correct_place

    return number_of_correct_digits_in_correct_place, number_of_correct_digits_in_wrong_place

# r1= correct place
# r2 = correct digits in wrong place
if __name__ == "__main__":
    r1, r2 = main()
    print(r1)
    print(r2)


What I have tried:

main() and using the if statement later on but I need it to output with something else
Posted
Comments
PIEBALDconsult 7-Apr-18 13:03pm    
By name?
Member 13672432 8-Apr-18 13:41pm    
Try explaining -.-
Richard MacCutchan 8-Apr-18 3:30am    
You should modify main so it accepts input parameters. You can then call it at any time with different values.
Member 13672432 8-Apr-18 13:41pm    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900