While using a return and print statement in the same function can be done, it's a bit confusing, particularly in the same if/else control block. I'm not sure if the seven parameter is supposed to represent your list but I would approach the solution like this.
llist = [1,2,3,4,5,6,7,8,9]
def check(llist):
for x in llist:
if(x == 7):
return "Seven is in the List"
return "Seven is not in the list"
seven = check(llist)
print(seven)
- I use a for loop inside the function, where x takes on each successive value in the llist, which is passed as a parameter.
- The if condition is inside the loop and the return string for finding seven is in that scope as well. Once a return statement is executed, it will automatically exit the function, so we don't need to worry about the 2nd return statement running in this case.
- In case 7 is not found, the second return string, which is outside the for loop scope, is sent out of the function.
- Whichever return statement is sent out of the function and stored in the variable seven, can then be passed to print and the string will be output.