In: Computer Science
Python
Question 5 (Multiple Choice)
msg1 = "My favorite number is " + str(fav_num) + "." msg2 = "My
favorite number is "+str(fav_num)+"." Why would msg1 be preferred
over msg2
(a)The user output is easier to read
(b)The code is easier to read. (c)Both a and b
Question 6
Given this list: pets = ['teddy', 'jessie', 'skippy'] Be sure to refer to the list element by its index Write the python statement whose output is: Hello SKIPPY; you are a fine parrot!
Note: print("Hello SKIPPY; you are a fine parrot!") is incorrect
Question 7
Using the list in Question 6
Write the python statement to add 'spot' to the list between
'teddy' and 'jessie'.
Question 8
Using the list updated in Question 7
Write the python statement to remove 'jessie' from the list.
Question 5:
Answer :(b)The code is easier to read.
Explanation :
Below screen show the demonstration
*************************************************
Question 6 :
Answer :print("Hello "+pets[2].upper()+"; you are a fine parrot!")
Explanation :
Demonstration :Below screen shows the demonstration
***************************************************
Question 7 :
Answer :pets.insert(1,'spot')
Explanation :Insert() method is used to insert an element into the list at given index
Demonstration :Below screen shows the output
********************************************
Question 8:
Answer :pets.remove('jessie')
Explanation :remove() method is used to remove an element from the list
Demonstration :Below screen shows the code and output