-1

`Create a Python procedural function(procedure) named square_odd_numbers that takes a list of numbers as its argument. The procedure should print a new list containing the squares of only the odd numbers from the input list.

use a while loop in the answer.

Example:

Input: [1, 2, 3, 4, 5]

Output (printed to the console): [1, 9, 25]

Call the procedure using the above data as input.

For example: Test >>>>>>>>>>> Result

#only your code >>>>>> [1, 9, 25]

test_list = [111, 62, 35, 47, 5]>>>>>>>>[12321, 1225, 2209, 25] square_odd_numbers(test_list)

def square_odd_numbers():
    a = [1, 2, 3, 4, 5]
    i = 1
    while i <= 6:
    if i%2 != 0:
        print(i ** 2)
    i += 1
square_odd_numbers()

Test program is not accepting what I did. Can someone explain to me? It is python programming.`

1
  • 2
    Not that anyone here knows anything about the test program, but task states ... that takes a list of numbers as its argument, your function does not take anything as an argument. I'd start with that. Also it doesn't print a list, but rather separate values. Commented Sep 4, 2023 at 20:54

1 Answer 1

0

Solution:

Your function needs to accept a list as input. Your function needs to process the items in that list.

Here is an example of how that would work. You have the basic idea, though.

def square_odd_numbers(input_list):
    
    for value in input_list:
        
        if value%2 != 0:
            print(value ** 2)

test_list = [111, 62, 35, 47, 5]
square_odd_numbers(test_list)

# 12321
# 1225
# 2209
# 25
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.