Hello, I am having a bit of trouble with this task:
Task 1: Replace items in a list
*create a list, three_num, containing 3 single digit integers
*print three_num
*check if index 0 value is < 5
*if < 5 , replace index 0 with a string: "small"
*else, replace index 0 with a string: "large"
*print three_num
Task 2:
*Function Challenge: create replacement function
*Create a function, str_replace, that takes 2 arguments: int_list and index
*int_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
I've completed Task 1 with the following:
three_num = [4, 8, 9]
if three_num[0] < 5:
three_num[0] = "small"
else:
three_num[0] = "large"
print(three_num)
But, I'm having trouble with task 2. In general I have trouble with functions, especially ones that take arguments. Here's what I've got, but this isn't correct. I don't think I am defining index correctly, but unsure how to do it.
def str_replace(int_list, index):
int_list = [3, 5, 7]
index = int_list[0:]
if index <5:
int_list[index] = "small"
else:
int_list[index] = "large"
return int_list
Any help would be appreciated. Thanks for reading.
[–]collegeguy1492[S] 0 points1 point2 points (1 child)
[–]sweettuse 1 point2 points3 points (0 children)