What is wrong with this code ? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

What is wrong with this code ?

#List all the even numbers from an unknown value to 800 num = input('Enter a number') if num%2==0: even_nums = list(range(num, 801, 2)) print(even_nums) else: print('Enter a even number')

30th Apr 2018, 7:31 AM
Titash Sinha
Titash Sinha - avatar
5 Respuestas
+ 2
input() gets you the input as a String always even if you enter a number so you must explicitly convert the input to an int num = int(input('Enter a number'))
30th Apr 2018, 7:37 AM
cyk
cyk - avatar
+ 2
You are very welcome! ☺
30th Apr 2018, 7:47 AM
cyk
cyk - avatar
+ 1
Now, if you also want to give the user the option to start with both an odd number you can use list comprehension like I did in the code below https://code.sololearn.com/cFFHMPQu6qMQ/?ref=app
30th Apr 2018, 7:42 AM
cyk
cyk - avatar
+ 1
thanks man
30th Apr 2018, 7:46 AM
Titash Sinha
Titash Sinha - avatar
0
it's working now
30th Apr 2018, 7:46 AM
Titash Sinha
Titash Sinha - avatar