209k views
5 votes
Write some code that assigns True to the variable is_a_member if the value assigned to member_id can be found in the current_members list. Otherwise, assign False to is_a_member. In your code, use only the variables current_members, member_id, and is_a_member.

1 Answer

4 votes

Answer:

current_members = [28, 0, 7, 100]

member_id = 7

if member_id in current_members:

is_a_member = True

else:

is_a_member = False

print(is_a_member)

Step-by-step explanation:

Although it is not required I initialized the current_members list and member_id so that you may check your code.

After initializing those, check if member_id is in the current_members or not using "if else" structure and "in" ("in" allows us to check if a variable is in a list or not). If member_id is in current_members, set the is_a_member as True. Otherwise, set the is_a_member as False.

Print the is_a_member to see the result

In the example above, since 7 is in the list, the is_a_member will be True

User Chealion
by
4.6k points