-2
nums = []

num = 0
valid_list = []
while num !=  '':
    num = input('Enter numbers :')
    nums.append(num)
nums2 = [(nums[i]) for i in range(0,len(nums))]
for i in range(len(nums2)):
    if int(nums2[i]) < 101 and int(nums2[i]) > 0:
        valid_list.append(nums2[i])

print(valid_list)

Sorry dont really know how to ask question corectly, but i hope those who get my idea will help, Thanks. So i am tryed to make program wich fills list with integers entered by user, than chech if they fit 1-101 and if they fit put those number in valid_list, The problem is while num != '': (BTW inters must be entered one by one, and it must stop when return is hited)

stew
  • 11,276
  • 36
  • 49

1 Answers1

0

Without having actually tested it, I think this is what you want:

nums = []

num = 0
valid_list = []

while true:
    num = input('Enter numbers :')

    if not num:
        break

    nums.append(num)

nums2 = [(nums[i]) for i in range(0,len(nums))]

for i in range(len(nums2)):
    if int(nums2[i]) < 101 and int(nums2[i]) > 0:
        valid_list.append(nums2[i])

print(valid_list)

From Python 'If not' syntax the if not num syntax is explained as executing if num is any kind of zero or empty container, or False.

Community
  • 1
  • 1
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42