+ 4

How to write this program in python?

How to write a program to generate values from 1 to 10 and then remove all the odd numbers from the list?

5th May 2019, 5:48 AM
k R :)
k R :) - avatar
6 Respuestas
+ 1
because num1 is iterable, you can for i in num1 in your second loop. and the method for removing an element from a list is remove(). https://code.sololearn.com/c06QcibSjl02/?ref=app
5th May 2019, 6:57 AM
Gordon
Gordon - avatar
+ 4
https://code.sololearn.com/cv57t1pj0gW4/?ref=app Please correct this code
5th May 2019, 6:15 AM
k R :)
k R :) - avatar
+ 4
Thank you, I got the correct output☺
5th May 2019, 6:30 AM
k R :)
k R :) - avatar
+ 2
1. now you have a try. good. this is the right way to ask questions in Q&A. 2. your if statement is wrong if(i1==2%) this is wrong 2.1 odd number is, after divided by 2, remains 1. 2.2 number divided by 2 remainder : num%2 2.3 comparison == 1 2.4 you need colon : to open the code block 2.5 correct logic and syntax : if num%2==1:
5th May 2019, 6:17 AM
Gordon
Gordon - avatar
+ 1
This question looks like for your learning. If we give you answer directly, we ruin your learning. Questions like this is good if it is accompanied with your try. Let us give you some hints: 1. for loop https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2435/ 2. remainder https://www.sololearn.com/learn/Python/2273/ 3. if https://www.sololearn.com/learn/Python/2277/
5th May 2019, 6:02 AM
Gordon
Gordon - avatar
+ 1
https://code.sololearn.com/c06QcibSjl02/?ref=app
5th May 2019, 6:22 AM
Gordon
Gordon - avatar