Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Debug Script

$
0
0
Questions:

pad_names:
(list of str, int) -> int
The first parameter is a list of names of various lengths. The second parameter is a minimum length. For any name whose length is less than the minimum, replace that item of the list with a new string containing the name with space(s) added to the right-hand side to achieve the minimum length. For example, if the list contains the name "Sue" and the minimum length is 5, then that item would be replaced with the name padded with 2 spaces: "Sue ". Any names that are already the minimum length or longer are unchanged. Return the number of names that are longer than the minimum length.


get_most_popular:
(list of str, dict of {str: list of str}) -> list of str
The first parameter is a list of movies that are currently in stock at a movie store. The second parameter is a dictionary where each key is the name of a customer and each value is a list of that customer's favourite movies ordered from most to least favourite. It is possible for a customer to have a favourite movie that is not in stock at the store. Return a list of all in-stock movies that are the first- or second-favourite movie of at least one customer. The movies in the returned list must be in the same order as in the first parameter and the returned list must not contain duplicates. The parameters are not changed by the function.


daily_percent_by_district:
(list of list of str, str) -> list of int
A small business owner asks each customer for their postal code in order to find out where they live. A postal code is 6 characters (e.g., 'H0H0H0') and the first three characters represent a district.

The first parameter is a list of list of postal codes, where each inner list contains the postal codes of customers for one business day. The second parameter is a three-letter code for a district. Return a list where each element is the percentage of customers from that district for the business day at the corresponding position in the list of list of postal codes.

Each percentage is to be an integer between 0 and 100. Floating point values are to be truncated to the integer below. For example, if on a particular business day, there were three postal codes and two of them were from the district of interest, the corresponding element in the returned list would be 66.
Precondition: each inner list in the list of list of postal codes has at least one element


import math
def pad_names(words, value_minimum):
    new_list = []
    count = 0
    for names in words:
        if len(names) < value_minimum:
            count += 1 
            new_name = names + ((value_minimum - len(names)) * ' ')
            new_list.append(new_name)
        else:
            count += 0
            new_name = names
            new_list.append(new_name)
    return count  

        
             
def get_most_popular(movies_stock, favorite_movies):
    fav_list = []
    fav_movies = list(favorite_movies.values()) # returns the values as a list      
    for movies in fav_movies:
        for movie in movies[:2]:
            if movie in movies_stock:
                fav_list.append(movie)
                break 
    return fav_list 

def daily_percent_by_district(postal_code, district):
    count_code = []
    count = 0
    for codes in postal_code:
        for letters in codes:
            if letters[:3] == district:
                count += 1 
            else:
                count += 0
        letter_code = (count/len(codes)) * 100
        L = math.floor(letter_code)
        count_code.append(L)
    return count_code 

 


Hello,
I don't know what the problem is, but each function fails for complex test cases.
Especially the last function, it doesn't work for the following test cases:
[['A1A2B2'], ['H0H0H0', 'A1A2B2']],'A1A'
[['A1A2B2'], ['HOHOHO'], ['A1A5A4', 'H0H0H0', 'A1A2B2']], 'A1A'

I don't know what the problem is. Please help!. Thank you

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>