Question

In: Computer Science

use python 1. Write a program that a. defines a list of countries that are members...

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]

Solutions

Expert Solution

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]


Related Solutions

1. Write a Python program that performs the following: 2. Defines an array of integers from...
1. Write a Python program that performs the following: 2. Defines an array of integers from 1 to 10. The numbers should be filled automatically without the need for user inputs 3. Find the sum of the numbers that are divisible by 3 (i.e., when a number is divided by 3, the remainder is zero) 4. Swap the positions of the maximum and minimum elements in the array. First, you need to find the maximum element as shown in the...
Write a program in python such that There exists a list of emails List Ls =...
Write a program in python such that There exists a list of emails List Ls = ['[email protected]','[email protected]','[email protected]','[email protected]',[email protected]'] Count the number of emails IDS which ends in "ac.in" Write proper program with proper function accepting the argument list of emails and function should print the number of email IDs and also the email IDS ending with ac.in output 2 [email protected] [email protected] ================================= i am trying like this but getting confused len [True for x in Ls if x.endswith('.ac.in')] please write complete...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
Write a python program per the following specifications: 1. Populate an array(list) of size n =...
Write a python program per the following specifications: 1. Populate an array(list) of size n = 50 randomly with only integers 0 and 1 2. Repeat step 1 nn = 1000 times using either a while loop or a for loop see below At this point you should have a total of 50000 observations with either 0 or 1 This is our experimental data which we will compare to the theoretical expected result From Lab06template.py import random temp = -1...
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Write a Python program for the following: A given author will use roughly use the same...
Write a Python program for the following: A given author will use roughly use the same proportion of, say, four-letter words in something she writes this year as she did in whatever she wrote last year. The same holds true for words of any length. BUT, the proportion of four-letter words that Author A consistently uses will very likely be different than the proportion of four-letter words that Author B uses. Theoretically, then, authorship controversies can sometimes be resolved by...
In python write a program that first creates a list with the integers 0 through 9...
In python write a program that first creates a list with the integers 0 through 9 and then traverses that list RECURSIVELY (no for/while loops allowed) and prints out the integers on the list. NOTE: creating the list does not have to be done recursively.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT