MST

星途 面试题库

面试题:Python中函数结合while循环实现简单数列生成

编写一个Python函数,该函数接收两个参数start和end,使用while循环生成一个从start开始到end结束(不包含end)的整数列表,并返回该列表。例如,函数接收参数2和5,应返回[2, 3, 4]。
24.7万 热度难度
编程语言Python

知识考点

AI 面试

面试题答案

一键面试
def generate_list(start, end):
    result = []
    while start < end:
        result.append(start)
        start += 1
    return result