當我運行下面的代碼時,我似乎'失去了'值,但我不知道爲什麼。還有其他方法可以打印出兩個相鄰的列表嗎?當我在Python 3中使用zip()函數時,我'丟失'了值
我想要做的是從long
的用戶輸入中創建一個整數列表。然後應按升序將它們分爲正值和負值。
原始代碼是:
import numpy as np
import random
print("(This will create a list of integers, UserInput long. Then separate"
"\nthem into positive and negative values in ascending order.)")
userI = input("\nHow many integers would you like, between the values of -100 and 100?: ")
userI = int(userI)
Ints = []
for A in range(userI):
Ints.append(random.randint(-100, 100))
print('\n', len(Ints))
def quad(N):
Ints_pos = []
Ints_neg = []
for B in N:
if B >= 0:
Ints_pos.append(B)
else:
Ints_neg.append(B)
return (Ints_pos, Ints_neg)
pos, neg = quad(N = Ints)
pos = sorted(pos)
neg = sorted(neg, reverse=True)
print('\nPositive', ' Negative'
'\nValues:', ' Values:')
for C, D in zip(pos, neg):
print('-> ', C, ' -> ', D)
input("\nPress 'Enter' to exit")
你是指*失去*嗎? – khelwood