+ 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
8 odpowiedzi
+ 3
numbers = [x**x for x in...]
+ 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
+ 2
odd_numbers = [1,3,5,7]
square_nums = []
for number in odd_numbers:
square_nums.append(number**2)
print(square_nums)
0
Show your attempt. then we help
0
x**x this not supporting for that code. Because it contains separated commas
0
nums = input('nums: )
list_int = [int(x)**2 for x in nums.split(',')]
print(list_int)
- 1
Hey guys