Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Break the Code
#1
I am struggling with an assignment for my python class. He hasn't taught us how to do these things, so I am stuck on how create a function that would perform it correctly.

Here is Part 1 of my assignment:
Part 1: Utility Functions (35 points)
For the three utility functions, you can run python four_b_tests.py, which if you did everything correct, should print
3/3 get_score_matches tests correct.
4/4 get_first_guess tests correct.
6/6 get_score_counts tests correct.
A. get_score_matches - 15 points This function has four parameters:
1. codes - A list of Code objects 2. guess - A single Code object 3. green - An integer
4. yellow - An integer
This function should return a list of Code objects that is a subset of codes where the green/yellow lights would match the given guess. For example, if codes = [AA, AB, BA, BB], guess=AA and green=1, yellow=0 guess vs AA is 2/0 so that doesn't match
guess vs AB is 1/0 so that matches
guess vs BA is 1/0 so that matches
guess vs BB is 0/0 so that doesn't match
so get_score_matches should return [AB, BA]
####I was thinking of doing something like if guess[0]==code[0], then add one to codegreen; then if guess[1]==code[1], add one to codegreen. And if codegreen == green, then matches.append(code)
However, this doesn't work when I run it. Does anyone know if I am on the right track? Or should I be doing this a different way?



B. get_first_guess - 10 points This function has two parameters,
1. num_letters - An integer
2. available_letters - A string of available letters
A good first guess is sometimes half one letter and half another. This function should return a Code object where the code is num_letters long, and the first num_letters / 2 are the first available letter, and the rest are the last available letter.
For example, if num_letters was 4 and the available_letters were ABCDE the first_guess should be the code AAEE.
If num_letters is odd, you end up with unequal amounts. However, since the integer division will round down, there will be more of the last letter, i.e. num_letters=5 would result in AAEEE.

C. get_score_counts - 10 points
One useful strategy would be to figure out what scores might result if you made a certain guess. This function takes 2 parameters:
1. codes - A list of Code objects
2. guess - A single Code object
The function should return a dictionary where the values are integer counts and keys are a string of the overall score.
For each code in codes, get the number of exact matches and misplacements when comparing code to guess.
For the key, make a string
key = str(exact) + '/' + str(misplacements)
Then if key is in the dictionary, add one to the value, otherwise set the value to one.
For example, if codes = [AA, AB, BA, BB], guess=AA guess vs AA is 2/0
guess vs AB is 1/0
guess vs BA is 1/0
guess vs BB is 0/0
So it would return {'2/0': 1, '1/0': 2, '0/0': 1}
i.e. 2/0 appeared once, 1/0 appeared twice and 0/0 appeared once.
Reply
#2
What does your current code look like? We'll help you fix you're problems but we won't do your homework for you.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020