1. Write a Python program to find whether a given number (accept from the user) is prime or not,print out an appropriate message to the user.?
n=int(input('Enter Number'))
if n<0:
print("Given Number is Negative")
elif n==2:
print(n,"is prime")
else:
for i in range(2,n):
if (n%i)==0:
print(n,"is not prime")
break
else:
print(n,"is prime number")
2. Write a Python program which accept the radius of a circle from the user and compute the area.
from math import pi
r = float(input ("Enter the Radius of circle: "))
print ("The area of the circle is" + str(r) + " is: " + str(pi * r**2))
3. Write a Python program to print all even numbers from a given list of numbers. The list is terminated by -99999.
list= [1, 2, 3, 4, 5, 6, 7, 8, 9, -99999]
print("Even Numbers are")
for x in list:
if not x % 2:
print(x,end=' ')
4. Write a Python program to find the occurrence of a given number in a given list of numbers.
list = [1,2,3,1,4,1,2,5,1,2,3,1]
print("Number Of occurrence of given number is",list.count(1))
5. Write a Python program that accept a word from the user and reverse it.
word = input("Give A Word to Reverse: ")
print(word[char], end="")
6. Write a Python program that accept a number and prints the reverse of it.
n = int(input("Please Give A Number: "))
R = 0
while(n > 0):
Reminder = n %10
R = (R *10) + Reminder
n = n //10
print("Reverse of Given Number is = %d" %R)
7. Write a Python program that accept a number and finds the summation of the digits in the number.
Number = int(input("Please Give A Number: "))
Sum = 0
while(Number > 0):
Reminder = Number % 10
Sum = Sum + Reminder
Number = Number //10
print("Sum of the digits of Given Number = %d" %Sum)
8. Write a Python program to copy the content
of a given file to another. Take the file names as input from user.
filename=input("Enter Filename ,")
to_readfile=open("ex.py",
"r")
try:
reading_file=to_readfile.read()
writefile=open(filename, "w")
print("Succefully Copied afile")
try:
writefile.write(reading_file)
finally:
writefile.close()
finally:
to_readfile.close()
9. Define a class student with attributes roll
number, name and score and methods to find grade. Grade is ‘A’ if score
>=80, grade is ‘B’ if score >=60 and score<80, grade is ‘C’ if score
>=50 and score<60 otherwise ‘F’.
class Student_Grade:
def
__init__(self, RollNo,Name,Score):
self.RollNo = RollNo
self.Name = Name
self.Score = Score
def
grade(self):
print("Roll No Of the Student is:",self.RollNo)
print("Name Of the Student is:",self.Name)
if(self.Score>=80 and self.Score<=100):
print("Your Grade is A")
elif(self.Score>=50 and self.Score<=60):
print("Your Grade is B")
else:
print("Your Grade is F")
return None
while True:
print("Enter
Roll Number, Name, Score of the Student: ")
rollnumber
= input()
name
= input()
score
= int(input())
r=Student_Grade(rollnumber,name,score)
r.grade()
break
10. Define a class named Circle constructed by
a radius and two methods which will compute the area and the perimeter of a
circle and one more method which will check whether the area is greater than a
given value or not.
from math import pi
class Circle:
def
__init__(self,r):
self.r = r
def
area(self):
return pi * self.r * self.r
def
perimeter(self):
return 2 * pi * self.r
def
check(self,area):
if area > self.r:
print("Area is Greater than Given Ridus")
r=Circle(5)
a=r.area()
print("Circle area is:",a)
print("Perimetere is:",r.perimeter())
r.check(a)
11. Define a class Shape with its sub class
Square . The Square has an initialize function which takes as argument a
length. Both classes have a function findArea which can print the area of the
shape where Shape's area is 0 by default.
class Shape:
def
area(side):
print("Area form Shape class:",side * side)
class Square(Shape):
def __init__(self,side):
self.side = side
def area(self,area=0):
print("Area from Square class:",self.side * self.side)
Shape.area(self.side)
Square(5).area()
12. Define a class Item and its two child
classes: Perishable and NonPerishable. All classes have attribute price a
method "calculateSalePrice" which can print "price + (price * .1)
" for nonperishable class and "price + 500" for perishable
class.
class
Pershable:
def calculateSalePrice(price):
print("Pershable Price
:",price+500)
class
NonPershable(Pershable):
def __init__(self,price):
self.price = price
def calculateSalePrice(self):
print("Nonpershable Price
:",self.price + (self.price * .1))
Pershable.calculateSalePrice(self.price)
x=NonPershable(100)
x.calculateSalePrice()
#!/usr/bin/python
# python program for items and its two child classes perishable and non
perishable
class Items(object):
def __init__(self,price):
self.price = price
def
CalculateSalePrice(self):
pass
class Perishable(Items):
def __init__(self,price):
self.price = price
def
CalculateSalePrice(price):
print('The price
is:',(price+500))
class NonPerishable(Items):
def __init__(self,price):
self.price = price
def
CalculateSalePrice(price):
print('The price
is:',(price+(price * 0.1)))
i = Items(10)
i.CalculateSalePrice()
i.CalculateSalePrice()
what type of questions will be asked in python assessment ?
ReplyDeleteJust basics of python like this http://tcstechlounge.blogspot.in/2017/11/tcs-aspire-python-questions-answers.html
DeleteDefine a class named Circle constructed by a radius and two methods which will compute the area and the perimeter of a circle and one more method which will check whether the area is greater than a given value or not.
Deletepython projects for final year students
Deep Learning Projects for Final Year Students
Machine Learning Projects For Final Year
#!/usr/bin/python
ReplyDelete# python program for items and its two child classes perishable and non perishable
class Items(object):
def __init__(self,price):
self.price = price
def CalculateSalePrice(self):
pass
class Perishable(Items):
def __init__(self,price):
self.price = price
def CalculateSalePrice(price):
print('The price is:',(price+500))
class NonPerishable(Items):
def __init__(self,price):
self.price = price
def CalculateSalePrice(price):
print('The price is:',(price+(price * 0.1)))
i = Items(10)
i.CalculateSalePrice()
i.CalculateSalePrice()
its running but not showing the output
It should be,
Deleteclass Items:
def __init__(self,price):
self.price = price
def CalculateSalePrice(self):
pass
class Perishable(Items):
def __init__(self,price):
self.price = price
def CalculateSalePrice(self):
print('The price is:',(self.price + 500))
class NonPerishable(Items):
def __init__(self,price):
self.price = price
def CalculateSalePrice(self):
print('The price is:',(self.price+(self.price * 0.1)))
obj1 = Perishable(1000)
obj2 = NonPerishable(1000)
obj1.CalculateSalePrice()
obj2.CalculateSalePrice()
This comment has been removed by the author.
ReplyDeletethis information is unique really thank you for sharing this information
ReplyDeletepython training in Hyderabad the best career
the solution for the 8th problem is not working. does anyone have one that does?
ReplyDeleteOpen a txt file in the python directory and add some text. the name of the txt file is your input. then the below code does the work.
ReplyDeleten=raw_input("Enter the name of the file")
f1=open(n,"r+")
f2=open("tha20.txt","w+")
f2.write(f1.read())
f2.close()
f1.close()
Thank you for your information.it is very nice article.
ReplyDeletePython Training in Pune
I really enjoyed reading your blog. I really appreciate your information which you shared with us. Best Python Online Training || Learn Python Course
ReplyDeleteSuch an interesting and informative piece of guidance imparted by you. I am glad to discover this information here and I am sure that this might be beneficial for us.
ReplyDeleteWeb delopment company in India
Admiring the time and effort you put into your blog and detailed information you offer!.. python training institute in pune
ReplyDeleteThanks for sharing this informative content , Great work
ReplyDeleteRead this PSM vs CSM blog from Leanpitch to get a better conclusion : PSM vs CSM
Trainingicon is offering Python training in Delhi NCR. We are a training institute in Delhi and Noida.We provide industrial training in programming like Python, PHP, Web designing, R Programming etc so if any body is looking to get trained into any skills, just let us know.following is the link to get enrilled into python batch
ReplyDeletePython Training in Noida
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete