In: Computer Science
use python
1. Write a program that a. defines a list of countries that are members of BRICS (Brazil, Russia, India, China, Sri Lanka) b. Check whether a country is a member of BRICS or not Program run Enter the name of country: Pakistan Pakistan is not a member of BRICS Enter the name of country : India India is a member of BRICS
2. Write a program to create a list of numbers in the range of 1 to 10. Then delete all the even numbers from the list and print the final list. def makeList() – function to create the list of numbers from 1 to 10 def delEven() – function to delete even numbers from list def main()‐ call the above functions and print Original List – [1,2,3,4,5,6,7,8,9,10] List after deleting even numbers: [1,3,5,7,9]
1)
#define countries
countries=['Brazil','Russia','India','China','Sri Lanka']
#input country name
countryName=input("Enter the name of country: ")
if countryName in countries:
print(countryName,"is a member of BRICS")
else:
print(countryName,"is not a member of BRICS")
Output
Enter the name of country: Pakistan
Pakistan is not a member of BRICS
Enter the name of country: India
India is a member of BRICS
2)
def makeList():
l=[]
for i in range(1,11):
l.append(i)
return l
def delEven(l):
i=0
while i<len(l):
if l[i]%2==0:
l.remove(l[i])
i+=1
return l
l=makeList()
print("Original List -",l)
print("List after deleting even numbers:",delEven(l))
Output
Original List - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
List after deleting even numbers: [1, 3, 5, 7, 9]