CASE STUDY 1 ( CHAPTER 4)
ANS THIS QUESTION IN GROUP OF TWO
Question 1
Given the list of an animal below, write down a command to add animal name to the list by
using append command.
# animals list
animals = [‘cat’, ‘dog’, ‘rabbit’]
Output
Updated animals list: ['cat', 'dog', 'rabbit', 'guinea pig']
Question 2
Write a program to add list to a list
# flower list
flowers = ['rose', 'vanilla', 'tulip']
# list of wild flowers
wild_flowers = ['lily', 'orchid']
Output
Updated flowers list: ['rose', 'vanilla', 'tulips', ['lily', 'orchid']]
Question 3
Write a program by using the count() method returns the number of times element appears
in the tuple below.
Dengan menggunakan arahan count(), tuliskan program untuk mengira berapa kali element
vowel wujud dalam tuple dibawah.
# vowels tuple
vowels = ('a', 'e', 'i', 'o', 'i', 'u')
Output :
The count of i is: 2
The count of p is: 0
Question 4
Write a Python program to compute the sum of all the elements of each tuple stored
inside a list of tuples.
Tulis program python untuk mengira jumlah element dalam setiap list tuple seperti
dalam paparan pada output.
Original list of tuples:
[(1, 2), (2, 3), (3, 4)]
Output :
Sum of all the elements of each tuple stored inside the said list of tuples:
[3, 5, 7]