Codewars里的8kyu题目 What is between?
题目说明:
Complete the function that takes two integers (a, b, where a < b) and return an array of all integers between the input parameters, including them.
For example:
a = 1
b = 4
–> [1, 2, 3, 4]
Python解决方法:
采用循环与列表,是每个在a,b中间的数加入进去。
代码:
def between(a, b):
list = []
list.append(a)
i = a+1
while(i>a and i<b):
list.append(i)
i+=1
list.append(b)
return list
a = eval(input("请输入一个整数:"))
b = eval(input("请输入一个整数:"))
print(between(a, b))