-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.

2
  • 3
    Are you familiar with != (the "does not equal" operator)? Commented Nov 12, 2019 at 9:18
  • Have you tried Googling Not equal in python? Commented Nov 12, 2019 at 9:19

4 Answers 4

0

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

Sign up to request clarification or add additional context in comments.

Comments

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")))

Comments

0

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

Comments

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")))

1 Comment

of course it was so simple! thanks very much

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.