编写具有1个参数num(不大于100的正整数)的函数oddEven(num)。此函数返回两列,一列为正整数,一列为负整数 我不知道在最后一行代码之后要做什么才能得到两列。 随机导入
def oddEven(num):
x=num
a,b=[],[]
for i in range(x):
o= b.append(random.randomint(-50,50))
if o % 2 == 0:
a.append(o)
else:
b.append(o)
a.sort()
b.sort()
return a,b
def main():
y=eval(input('What # of integers would you like in this list?:'))
list1, list2 = oddeven(y)
print('even','odd')
for i in range (min(len(odd),len(even)):
print(odd[i],even[i])
if len(odd) != len(even):
您需要的函数是
random.randint
而不是random.randomint
您需要对
代码逻辑进行主要编辑:我的代码:
输出:
您描述的代码的简单示例
相关问题 更多 >
编程相关推荐