-3

So theres a small chunk of code im working on for a school project but im not sure if this while command is possile:

array = []


list_amount = int(input("Enter how many numbers will be in the list"))

while len(array) == list_amount:
    array.append(int(input("Enter a number")))

In the line, while len(array) == list_amount: I want it to be not equal to

So that it will keep letting you add numbers until the length of the array and the amount you entered are the same then the loop will break.

Sayandip Dutta
  • 15,602
  • 4
  • 23
  • 52
C Plant
  • 1
  • 1

4 Answers4

0

Replace == with !=. != is a python syntax for "not equal to".

Corsaka
  • 364
  • 3
  • 15
0

Use the != operator:

array = []

list_amount = int(input("Enter how many numbers will be in the list"))

while len(array) != list_amount:
    array.append(int(input("Enter a number")))
Sid
  • 2,174
  • 1
  • 13
  • 29
0

Just do != instead of ==. It means not equal to and is basically the opposite of ==.

THess
  • 1,003
  • 1
  • 13
  • 21
0
array = []

list_amount = int(input("Enter how many numbers will be in the list"))

for i in range(list_amount):
    array.append(int(input("Enter a number")))
Dorin
  • 1,016
  • 1
  • 11
  • 15