178k views
3 votes
Create a function, str_replace, that takes 2 arguments: int list and index in list is a list of single digit integers index is the index that will be checked - such as with int_list[index] Function replicates purpose of task "replace items in a list" above and replaces an integer with a string "small" or "large" return int_list

User Cocotton
by
4.3k points

1 Answer

1 vote

Answer:

def str_replace(int_list, index):

if int_list[index] < 7:

int_list[index] = "small"

elif int_list[index] > 7:

int_list[index] = "large"

return int_list

Step-by-step explanation:

I believe you forgot to mention the comparison value. I checked if the integer at the given index is smaller/greater than 7. If that is not your number to check, you may just change the value.

Create a function called def str_replace that takes two parameters, an integer list and an index

Check if the number in given index is smaller than 7. If it is replace the number with "small".

Check if the number in given index is greater than 7. If it is replace the number with "large".

Return the list

User EGOrecords
by
5.8k points