From 044dba77e4a965db864fc14742ba016ff1735d26 Mon Sep 17 00:00:00 2001 From: Bertoncelli Giovanni Date: Thu, 24 May 2018 15:51:59 +0200 Subject: [PATCH] Update 100+ Python challenging programming exercises.txt --- 100+ Python challenging programming exercises.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index 97af5aaf..31fe2c18 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -407,14 +407,14 @@ Use a list comprehension to square each odd number in a list. The list is input Suppose the following input is supplied to the program: 1,2,3,4,5,6,7,8,9 Then, the output should be: -1,3,5,7,9 +1, 2, 9, 4, 25, 6, 49, 8, 81 Hints: In case of input data being supplied to the question, it should be assumed to be a console input. Solution: -values = raw_input() -numbers = [x for x in values.split(",") if int(x)%2!=0] +values = raw_input() # input() in python3 +numbers = [int(x)**2 if int(x) % 2 != 0 else int(x) for x in values.split(",")] print ",".join(numbers) #----------------------------------------#