Python Code 1Given a variable currentmembers that refers to

Python Code

(1)Given:

a variable  current_members that refers to a list, and

a variable  member_id that has been defined.

Write some code that assigns True to a variable  is_a_member if the value associated with member_id can be found in the list associated with current_members, but that otherwise assigns False to is_a_member. Use only current_members, member_id, and is_a_member.

(2)Given that plist1 and plist2 both refer to lists, write a statement that defines plist3 as a new list that is the concatenation of plist1 and plist2. Do not modify plist1 or plist2.

(3)Given that play_list has been defined to be a list, write an expression that evaluates to a new list containing the elements at index 0 through index 4 play_list. Do not modify play_list.

(4)Given the string, s, and the list, lst, associate the variable  contains with True if every string in lst appears in s (and False otherwise). Thus, given the string Hello world and the list [\"H\", \"wor\", \"o w\"], contains would be associated with True.

Solution

current_members=[1,2,3,4,5]
member_id=eval(input(\"Enter a number\"))
is_a_member=\"false\"
for i in current_members:
if (i==member_id):
print(is_a_member)
print(\"1. is_a_member is \",is_a_member)
plist1=[1,2,3]
plist2=[4,5,6]
plist3=plist1
print(\"2. plist3 \",plist1+plist2)
play_list=[1,2,3,4,5,6]
print(\"3. \",play_list[0:4])

Python Code (1)Given: a variable current_members that refers to a list, and a variable member_id that has been defined. Write some code that assigns True to a v

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site