+ 1
Just taking numbers from list
list=[1,"appel",2,3,"peach",4,5,"orange",6,"carrot",8,"banana",10,"cat"] for number in list: while number<=9: if (number>2): print(number) I just want to see on my output 3,4,5,6,8 these numbers. Where have i done a mistake?
6 Answers
+ 5
Something like this?
https://code.sololearn.com/co8Mz7AGf3Jr/?ref=app
+ 2
Calvin Thomas ,
there are 2 issues in your code sample:
âȘïž isnumeric() is a string function, but numbers in list are integers
âȘïž the result of the code is 1,2,3,4,5,6,8,10 but should be 3,4,5,6,8
+ 1
Remove the while loop, unindent your if statement and print statement... it should work
+ 1
The while loop makes no sense. Its exit condition depends on a variable which doesn't change inside the loop, so it either runs once or it runs forever.
There's no filter to check only numbers.
Things to learn that will help you a lot here:
- break and continue statements - You can end a loop or skip an iteration at arbitrary conditions
- List comprehensions - You can create a new list by filtering an existing one
- join function - Easily formats lists, which helps printing them
0
What is the need of while loop there in for loop . it loops forever. Just use a if condition instead.
And you can check condition like
if type(number) == int :
0
Habib Here's a possible solution:
print(*filter(lambda x: x.isnumeric(), list), sep=',')
# Hope this helps