mianshi

柿子 2 2024-04-17

                     数据开发实习生笔试

 

一、分析

问题定位

我们产品分为基础服务和会员增值服务(周包、月包、年包),我们在产品的某些位置会提供会员增值服务的导购页,最近我们的会员销售额有逐渐降低的趋势,如何定位问题?

答:

通过数据分析:

分析用户在导购页的行为,如访问量、停留时间、转换率等,了解用户的喜好,找出原因。

分析用户流失率判断是否是因为用户减少导致;

分析竞品定价与自己的产品定价对比,查看是否因为价格原因;

分析用户评价数据,查看具体用户不满意的地方;

 

 

 

 

 

 

二、SQL

计算留存

表a为用户每日活跃表,共包含2个字段username和date

请写出一条SQL计算2015-10-12日的次日留存率

答:

select

round(sum(if (a2.date = ‘2015-10-13’, 1, 0)) * 100/count(1), 4) as rate

from a a1 left join a2

on a1.username = a2.username and a1.date = ‘2015-10-12’ and a2.date = ‘2015-10-13’

 

 

 

 

 

 

 

 

 

 

 

三、对齐

使用Python实现,给定单词组text和长度maxLen,已知单词短于maxLen。实现两端对齐,如某一行词的空格无法均匀分配,则右侧的空格数要多于左侧。文本的最后一行应左对齐,且单词之间不插入额外的空格。

 

示例:

 

 

 

答:

 

def justify_text(text, max_len):

    words = text.split()

    lines = []

    current_line = []

    current_length = 0

   

    for word in words:

        if current_length + len(word) + len(current_line) <= max_len:

            current_line.append(word)

            current_length += len(word)

        else:

            lines.append(current_line)

            current_line = [word]

            current_length = len(word)

   

    lines.append(current_line)

   

    justified_lines = []

    for line in lines[:-1]:

        num_words = len(line)

        total_spaces = max_len - sum(len(word) for word in line)

        spaces_per_word = total_spaces // (num_words - 1) if num_words > 1 else total_spaces

        extra_spaces = total_spaces % (num_words - 1) if num_words > 1 else 0

       

        justified_line = ''

        for i, word in enumerate(line):

            justified_line += word

            if i < num_words - 1:

                justified_line += ' ' * spaces_per_word

                if i < extra_spaces:

                    justified_line += ' '

       

        justified_lines.append(justified_line)

   

    # 左对齐最后一行

    last_line = ' '.join(lines[-1])

    justified_lines.append(last_line)

   

    return justified_lines

 

justified_text = justify_text(text, max_len)

for line in justified_text:

    print(line)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

四、进制转换

 

使用Python实现,但尽量不使用语言的标准库及第三方库。

解析给定的一个字符串,判断该字符串是否为一个合法的10/16进制数,如果合法,请转换为10进制输出,如果不合法,请输出ERROR。

 

答:

def is_valid(s):

    valid_chars = set('0123456789abcdefABCDEF')

    for char in s:

        if char not in valid_chars:

            return False

    return True

 

def sixteen_to_ten(s):

    hex_digits = '0123456789abcdef'

    ten_value = 0

    power = len(s) - 1

    for char in s:

        if char.isdigit():

            ten_value += int(char) (16 * power)

        else:

            ten_value += hex_digits.index(char.lower()) (16 * power)

        power -= 1

    return ten_value

 

def parse_hex(s):

    if s.startswith('0x') or s.startswith('0X'):

        s = s[2:]

    if not s:

        return "ERROR"

    if is_valid(s):

        return sixteen_to_ten(s)

    else:

        return "ERROR"

 

str = input("请输入数字")

result = parse_hex(str)

print(result)