✕

Inheritance

Question

Write a method in python to find and display the prime numbers between 2 to N.Pass N as the argument to the method.

Answer

def prime(N):
	for a in range(2,N):
		for I in range(2,a):
			if a%i ==0:
				break
			else:
				print a

Sponsor Area

Some More Questions From Inheritance Chapter

Write two methods in python using concept of Function Overloading (Polymorphism) to perform the following operations:
(i) A function having one argument as Radius, to calculate Area of Circle as 3.14#Radius#Radius
(ii) A function having two arguments as Base and Height, to calculate Area of right-angled triangle as 0.5#Base#Height.

What will be the status of the following list after the First, Second and Third pass of the bubble sort method used for arranging the following elements in ascending order ?

Note: Show the status of all the elements after each pass very clearly underlining the changes.
52, 42, -10, 60, 90, 20

Write Addnew(Member) and Remove(Member) methods in python to Add a new Member and Remove a Member from a List of Members, considering them to act as INSERT and DELETE operations of the data structure Queue.

Write definition of a Method MSEARCH(STATES) to display all the state names from a list of STATES, which are starting with alphabet M.
For example:
If the list STATES contains
['MP','UP','WB','TN','MH','MZ','DL','BH','RJ','HR']
The following should get displayed
MP
MH
MZ

Write a method in python to read lines from a text file MYNOTES.TXT, and display those lines, which are starting with an alphabet ‘K’.

Considering the following definition of class FACTORY, write a method in Python to search and display the content in a pickled file FACTORY.DAT,where FCTID is matching with the value '105'.

class Factory:
	def __init__(self,FID,FNAM):
		self.FCTID = FID # FCTID Factory ID
		self.FCTNM = FNAM # FCTNM Factory Name
		self.PROD = 1000 # PROD Production
	def Display(self):
		print self.FCTID,':',self.FCTNM,':',self.PROD

What will be the status of the following list after the First, Second and Third pass of the insertion sort method used for arranging the following elements in descending order?

22, 24, 64,
34, 80, 43
Note: Show the status of all the elements after each pass very clearly underlining the changes.

For a given list of values in descending order, write a method in python to search for a value with the help of Binary Search method. The method should return the position of the value and should return -1 if the value not present in the list.

Write Insert(Place) and Delete(Place) methods in python to add Place and RemovePlace considering them to act as Insert and Delete operations of the data structure Queue.

Write a method in python to find and display the prime numbers between 2 to N.Pass N as the argument to the method.