+ 5

Write a program to square each odd number in a list. The list is input by a sequence of comma-separated numbers.

Write a program to square each odd number in a list. The list is input by a sequence of comma-separated numbers. Suppose the following input is supplied to the program: 1,2,3,4,5,6,7,8,9 Then, the output should be: 1,9,25,49,81

3rd Sep 2022, 5:04 AM
Mani Sankar Pasala
Mani Sankar Pasala - avatar
8 ответов
+ 3
numbers = [x**x for x in...]
3rd Sep 2022, 6:28 AM
Slick
Slick - avatar
+ 2
values = input() numbers = [x for x in values.split(",") if int(x)%2!=0] print(",".join(numbers)) # this is printing only odd numbers. But i need square of odd numbers
3rd Sep 2022, 5:17 AM
Mani Sankar Pasala
Mani Sankar Pasala - avatar
+ 2
odd_numbers = [1,3,5,7] square_nums = [] for number in odd_numbers: square_nums.append(number**2) print(square_nums)
3rd Sep 2022, 9:56 PM
bakeery
0
Show your attempt. then we help
3rd Sep 2022, 5:13 AM
MATOVU CALEB
MATOVU CALEB - avatar
0
x**x this not supporting for that code. Because it contains separated commas
3rd Sep 2022, 3:58 PM
Mani Sankar Pasala
Mani Sankar Pasala - avatar
0
nums = input('nums: ) list_int = [int(x)**2 for x in nums.split(',')] print(list_int)
7th Sep 2022, 6:10 AM
bakeery
- 1
Hey guys
4th Sep 2022, 5:11 PM
Daniel Onyekachi Victor
Daniel Onyekachi Victor - avatar