#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    2

    Need help with 3 following 2 following functions:


    So i have 2 functions that i cant seem to understand.

    Code:
     def finalize_score (puzzle,view,unguessed_consonants,current_score):
        '''(str,str,str,int)->int
    
        Return the final score, which is calculated by adding CONSONANT_BONUS points to the score
        for each unguessed consonant from the puzzle that is HIDDEN in the view.
    
        >>>finalize_score('apple pies', '^^^le ^^e^', 'dfkpqstz', 0)
        8
        >>>finalize_score('banana split', '^a^a^a s^^it', 'bdfklnpqz', 0)
        10
        '''
        #CONSONANT_BONUS * the number of unguessed consonants
        a= 0
        for i in puzzle:
            if i in CONSONANTS:
                a = a+ CONSONANT_BONUS
        return a
    In this first code I need to get the score for the hidden consonants where each CONSONANT_BONUS = 2 so if there are 3 hidden consonants then the CONSONANT-BONUS = 6 and so on, i really need help in this ... the function i wrote return the score for all of the consonants present in the string and not just the hidden PLEASE HELP

    My next code is:

    Code:
    def is_match (puzzle,view):
        '''(str,str)->bool
    
        returns true if and only if puzzle and view match in the place where the letters are hidden
    
        >>>is_match ('apples','^^^^^')
        True
        >>>is_match ('apples-bananas',^^^^^^^^^^^^^')
        False
        '''
    FOr this one i realize the two strings need to be compared but how???????? What this function should return is is the two parameters in puzzle and view match in terms of spaces, consonants, and number of vowels...

    PLEASE HELP, Thanks so much
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    33
    Rep Power
    3
    Originally Posted by emo.vs.elmo
    So i have 2 functions that i cant seem to understand.

    Code:
     def finalize_score (puzzle,view,unguessed_consonants,current_score):
        '''(str,str,str,int)->int
    
        Return the final score, which is calculated by adding CONSONANT_BONUS points to the score
        for each unguessed consonant from the puzzle that is HIDDEN in the view.
    
        >>>finalize_score('apple pies', '^^^le ^^e^', 'dfkpqstz', 0)
        8
        >>>finalize_score('banana split', '^a^a^a s^^it', 'bdfklnpqz', 0)
        10
        '''
        #CONSONANT_BONUS * the number of unguessed consonants
        a= 0
        for i in puzzle:
            if i in CONSONANTS:
                a = a+ CONSONANT_BONUS
        return a
    In this first code I need to get the score for the hidden consonants where each CONSONANT_BONUS = 2 so if there are 3 hidden consonants then the CONSONANT-BONUS = 6 and so on, i really need help in this ... the function i wrote return the score for all of the consonants present in the string and not just the hidden PLEASE HELP

    My next code is:

    Code:
    def is_match (puzzle,view):
        '''(str,str)->bool
    
        returns true if and only if puzzle and view match in the place where the letters are hidden
    
        >>>is_match ('apples','^^^^^')
        True
        >>>is_match ('apples-bananas',^^^^^^^^^^^^^')
        False
        '''
    FOr this one i realize the two strings need to be compared but how???????? What this function should return is is the two parameters in puzzle and view match in terms of spaces, consonants, and number of vowels...

    PLEASE HELP, Thanks so much
    ok so what the first function is doing is it is passed 4 parameters and they are as follows:
    puzzle - this is the full answer i.e. 'apple pie'
    view - this is what the person solving the puzzle sees i.e. '^^^le ^^e^
    unguessed_consonats - a few consonats that could be helpful but must contain the answer
    current_score - a number of type int that could be given a default value 0 unless u specify otherwise

    in the end the score is aquirred by getting the amount of unused consonants and adding a score for the amount of the letters left

    so with this information u can make your program
    list of processes
    show the word with the ^ characters
    show the helpful consonants
    then use a loop to ask the user for a consonant
    if the letter is not in the list of helpful consonants don't add a score and skip the checking process
    if the letter is in the helpful consonants then check the puzzle to see if it is in it
    if it is then u find it position and replace the ^ with the letter in the corresponding index then take the letter out of the helpful consonants
    if not just replace the letter in helpful consonants



    i hope this helps, can't post tested code so the list of processes should help
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    2
    Originally Posted by Purity_Lake
    ok so what the first function is doing is it is passed 4 parameters and they are as follows:
    puzzle - this is the full answer i.e. 'apple pie'
    view - this is what the person solving the puzzle sees i.e. '^^^le ^^e^
    unguessed_consonats - a few consonats that could be helpful but must contain the answer
    current_score - a number of type int that could be given a default value 0 unless u specify otherwise

    in the end the score is aquirred by getting the amount of unused consonants and adding a score for the amount of the letters left

    so with this information u can make your program
    list of processes
    show the word with the ^ characters
    show the helpful consonants
    then use a loop to ask the user for a consonant
    if the letter is not in the list of helpful consonants don't add a score and skip the checking process
    if the letter is in the helpful consonants then check the puzzle to see if it is in it
    if it is then u find it position and replace the ^ with the letter in the corresponding index then take the letter out of the helpful consonants
    if not just replace the letter in helpful consonants



    i hope this helps, can't post tested code so the list of processes should help

    THANK YOU SOOO MUCH@_@

    This works, makes me feel so happy, do you have the solution for the next one???
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    33
    Rep Power
    3
    just use len(var) to get the length of a string, i.e. replace var with any variable

    then compare with if statements that return true if puzzle == view
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Code:
        returns true if and only if puzzle and view match in the place where the letters are hidden
    
        >>>is_match ('apples','^^^^^')
        True
        >>>is_match ('apples-bananas',^^^^^^^^^^^^^')
        False
    Small wonder you're puzzled. The lengths of
    'apples' and '^^^^^'
    don't match.

    The lengths of
    'apples-bananas' and ^^^^^^^^^^^^^'
    don't match.

    ^^^^^^^^^^^^^'
    would be a syntax error if python tried to interpret it.

    And foremost, how would one match unknowns to a known?

    I can't solve this either.
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    33
    Rep Power
    3
    i'd like to know were u got this code puzzle from?

    what are these hidden letters they are on about?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    44
    Rep Power
    2
    Originally Posted by Purity_Lake
    i'd like to know were u got this code puzzle from?

    what are these hidden letters they are on about?
    Oh oops, i made some mistakes in putting the examples in the code before

    Okay so in this q, we are basically supposed to match puzzle with view...

    it makes absolutely no sense to me, because we are supposed to see whether the hidden '^' actually holds a consonant or a vowel...

    these are just some examples:
    >>>is_match ('apples','^pp^^^')
    True
    >>>is_match ('apples-bananas','^^^^^^^^^^^^^')
    False
    >>>is_match ('apples-i', '^^^^^^-^')
    True
    >>>is_match ('apples-i', '^^^^^^^^') <-- '-' should not be hidden...
    False

    So far my code is this

    Code:
    def is_match (puzzle, view):
        a = 0
        for i in range(len(puzzle)):
            if (puzzle[i] == view[i]): #or (view[i] == HIDDEN or        view[i] != puzzle[i].islower()) and (len(puzzle) == len(view)):
                return True
            elif len(puzzle)==len(view) and (puzzle[i] != view[i]):
                return False
            else: 
                return False

IMN logo majestic logo threadwatch logo seochat tools logo