SlideShare a Scribd company logo
1 of 47
Download to read offline
- Sasin Nisar
- Class 12/B
INDEX
Sr.no CONTENT REMARKS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Sr.no CONTENT REMARKS
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#1
OBJECTIVE:-
Write a program to input any choice and to
implement the following.
Choice Find
1. Area of square
2. Area of rectangle
3. Area of triangle
CODE:-
print 'Choicet Find'
print '1.t Area of square'
print '2.t Area of rectangle'
print '3.t Area of triangle'
c = input ("nEnter any Choice: ")
if(c==1):
s = input("nEnter any side of the square: ")
a = s*s
print"Area = ",a
elif(c==2):
l = input("nEnter length: ")
b = input("Enter breadth: ")
a = l*b
print"Area = ",a
elif(c==3):
x = input("nEnter first side of triangle: ")
y = input("enter second side of triangle: ")
z = input("enter third side of triangle: ")
s = (x+y+z)/2.0
A = ((s-x)*(s-y)*(s-z))**0.5
print"Area=",A
else:
print "Wrong input"
INPUT:-
Choice Find
1. Area of square
2. Area of rectangle
3. Area of triangle
Enter any Choice:1
Enter any side of square: 7
OUTPUT:-
Area=49
#2
OBJECTIVE:-
Write a program to input any number
and to print all natural numbers up to given
number.
CODE:-
n = input("Enter any number: ")
for i in range(1,n+1):
print i,
INPUT:-
Enter any number: 7
OUTPUT:-
1 2 3 4 5 6 7
#3
OBJECTIVE:-
Write a program to input any number
and to find sum of all natural numbers up to given
number.
CODE:-
n = input("Enter any number")
sum= 0
for i in range(1,n+1):
sum = sum+i
print "sum=",sum
INPUT:-
Enter any number: 11
OUTPUT:-
Sum=66
#4
OBJECTIVE:-
Write a program to input any
number and to find reverse of that
number.
CODE:-
n = input("Enter any number: ")
r = 0
while(n>0):
r = r*10+n%10
n = n/10
print "reverse number is", r
INPUT:-
Enter any number: 76655456
OUTPUT:-
reverse number is 65455667
#5
OBJECTIVE:-
Write a function which take one parameter and
return binary number equivalent to that number.
CODE:-
def binary_converter(x):
if x==0:
return 0
else:
bit=[]
while x:
bit.append(x%2)
x=x/2
return bit[::-1]
INPUT:-
binary_converter(112)
OUTPUT:-
[1, 1, 1, 0, 0, 0, 0]
#6
OBJECTIVE:-
Write a program to read a number.if the number
is even then print half the number otherwise print the
next number. End your program by printing 'Thank
you!
CODE:-
n=input('Enter number: ')
if n%2==0:
print 'the number is even:'
print 'the half number is: ',n/2.0
else:
print 'the number is odd: '
print 'the next number is: ',n+1
print 'Thank you!!!'
INPUT:-
Enter number: 44
OUTPUT:-
the number is even:
the half number is: 22.0
Thank you!!!
#7
OBJECTIVE:-
Write a program to compute tax payable by a person
according to his salary as per following rates:
salary tax rate
less than 10000 0%
10000<=salary<20000 5%
20000<=salary<40000 10%
40000 or higher 12%
CODE:-
salary=input('Enter salary: ')
if salary<10000:
rate=0.0
elif salary<20000:
rate=0.05
elif salary<40000:
rate=0.10
else:
rate=0.12
print 'you must pay',rate*salary,'as taxes'
INPUT:-Enter salary: 20000
OUTPUT:-you must pay 2000 as taxes
#8
OBJECTIVE:-
Write a program to print sum of all natural numbers
between 1 to 7.
CODE:-
sum=0
for i in range(1,8):
sum+=i
print 'sum of natural number from 1 to 7 is: ',sum
INPUT:-
OUTPUT:-
Sum of natural number from 1 to 7 is: 28
#9
OBJECTIVE:-
Write a program to input some numbers repeatedly
and print their sum. The program ends when user say
no more to enter( normal termination) or program
aborts when the number entered is less than zero.
CODE:-
count=sum=0
ans='y'
while ans=='y':
num=input('Enter number: ')
if num<0:
print 'Number entred is below zero.Aborting!!!'
break
sum+=num
count+=1
ans=raw_input('Want to enter more
numbers?(y/n)..')
else:
print 'you entered',count,' numbers so for.'
print 'Sum of numbers entered ',sum
INPUT:-
Y
Enter number: (8)
Want to enter more numbers?(y/n).. y
Enter number:-1
OUTPUT:-
Number entred is below zero.Aborting!!!
Sum of numbers entered 8
#10
OBJECTIVE:-
Write a short program to print the following series.
(i) 1 4 7 10 ........... 40
(ii) 1 -4 7 -10...........-40
CODE:-
#(i)
for i in range(1,41,3):
print i,
#(ii)
for i in range(1,41,3):
if i%2==0:
print i*(-1),
else:
print i,
INPUT:-
OUTPUT:-
(i)
1 4 7 10 13 16 19 22 25 28 31 34 37 40
(ii)
1 -4 7 -10 13 -16 19 -22 25 -28 31 -34 37 -40
#11
OBJECTIVE:-
Write a short program to find average of list of
numbers entered through keyboard.
CODE:-
sum=0
count=0
end=''
while end!='end':
number=raw_input('Enter a number: ')
if number.lower()=='end':
break
sum+=float(number)
count+=1
print 'the average of given numbers is: ',sum/count
INPUT:-
Enter a number: 1
Enter a number: 3
Enter a number: 5
Enter a number: 7
Enter a number: 9
Enter a number: end
OUTPUT:-
the average of given numbers is 5.0
#12
OBJECTIVE:-
Write a Short program to find largest number of a list
of numbers entered through keyboard.
CODE:-
max=0
while True:
number=raw_input('Enter a Number: ')
if number.lower()=='end':
break
if float(number)>max:
max=float(number)
print 'Maximum number among all numbers is: ',max
INPUT:-
Enter a Number: 23145564234
Enter a Number: 123453
Enter a Number: end
OUTPUT:-
Maximum number among all numbers is: 23145564234
#13
OBJECTIVE:-
Write a program to check whether a given number is
palindrome or not.
CODE:-
num=input('Enter a number: ')
tem=num
rev=0
while(num>0):
digit=num%10
num=num/10
rev=rev*10+digit
if rev==tem:
print "The number is a palindrome!"
else:
print "The number isn't a palindrome!"
INPUT:-
Enter a number:1221
OUTPUT:-
The number is a palindrome!
#14
OBJECTIVE:-
Write a python program to sum of the given
sequences:
(i) 2/9 - 5/13 + 8/17+.......
(ii)1**2+3**2+5**2+.......+n**2
CODE:-
#(i)
number=input('Enter number: ')
num=2.0
den=9.0
sum=num/den
sign=-1
for i in range(2,number+1):
num=num+3
den=den+4
sum=sum+(num)/(den)*sign
sign*=-1
print 'sum of series up to: ',number, ' is: ',sum
#(ii)
sum=0
num=input('Enter a Number: ')
for i in range(1,2*num+1,2):
sum+=i**2
print 'the sum of series up to ',num,' term is: ',sum
INPUT:-
(i) Enter number: 21314
(ii) Enter number: 21314
OUTPUT:-
(i) sum of series up to: 21314 is: -0.318093834875
(ii) the sum of series up to 21314 term is:
12910219335754
#15
OBJECTIVE:-
Write a python program to sum the sequence
a)1 + 1/1! + 1/2! + 1/3! + ...........
b)x + x**2/2 + x**3/3 + ........... x**n/n
CODE:-
a)
import math
num=input('Enter a number: ')
sum=1.0
for i in range(1,num):
sum=sum+1.0/math.factorial(i)
print 'the sum of series up to ',num,' term: ',sum
b)
X=input('Enter value of X: ')
N=input('Enter value of N: ')
sum=X
for i in range(2,N+1):
sum+=float(X**i)/i
print 'the sum of series up to ',N,' with value ',X,' is:
',sum
INPUT:-
a)Enter a number: 48
b)Enter value of X: 48
Enter value of N: 2
OUTPUT:-
a) the sum of series up to 48 term: 2.71828182846
b) the sum of series up to 2 with value 48 is: 1200.0
#16
OBJECTIVE:-
Write a program input four digit year and find entered
year is leap year or not.
CODE:-
year =input('Enter 4 digit year: ')
if (( year%400 == 0)or (( year%4 == 0 ) and ( year%100
!= 0))):
print year , ' is leap year'
else:
print year ,' is not leap year '
INPUT:-
Enter 4 digit year: 2009
OUTPUT:-
2009 is not a leap year
#17
OBJECTIVE:-
Write a program using nested loop to produce the
following pattern
A
A B
A B C
A B C D
A B C D E
A B C D E F
CODE:-
for i in range(65,71):
for j in range(65,i+1):
print chr(j),
print
INPUT:-
OUTPUT:-
A
A B
A B C
A B C D
A B C D E
#18
OBJECTIVE:-
Write a program using nested loops to produce a
rectangle of *s with 6 rows and 20 *s per row.
CODE:-
for i in range(6):
for i in range(20):
print '*',
print
INPUT:-
OUTPUT:-
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
#19
OBJECTIVE:-
Write a short program to input a digit and print it in
word.
CODE:-
digit=input('Enter a digit: ')
inword=''
if digit==1:
inword='one'
elif digit==2:
inword='two'
elif digit==3:
inword='three'
elif digit==4:
inword='four'
elif digit==5:
inword='five'
elif digit==6:
inword='six'
elif digit==7:
inword='seven'
elif digit==8:
inword='eight'
elif digit==9:
inword='nine'
elif digit==0:
inword='zero'
else:
print 'invalid digit entry: '
print 'Digit ',digit,' in word is: ',inword
INPUT:-
Enter a digit: 9
OUTPUT:-
Digit 9 in word is: nine
#20
OBJECTIVE:-
Write a short program to check whether square root of
given number prime or not.
CODE:-
from math import sqrt
number=input('Enter a Number: ')
sqr_number=sqrt(number)
limit=int(sqrt(sqr_number))+1
for i in range(2,limit):
if sqr_number%i==0:
print 'Square root of given number is not Prime!!'
break
else:
print 'Square root of given number is Prime!!'
INPUT:-
Enter a Number: 49
OUTPUT:-
Square root of given number is Prime!!
#21
OBJECTIVE:-
Write a program to print first n odd number in
descending order.
CODE:-
number=input('Enter a Number: ')
for i in range(number,0,-1):
if i%2!=0:
print i,
INPUT:-
Enter a Number:12
OUTPUT:-
11 9 7 5 3 1
#22
OBJECTIVE:-Write a program to print the following
using a single loop.(no nested loop)
1
11
111
1111
11111
CODE:-
n=1
for a in range(5):
print n
n=n*10+1
INPUT:-
OUTPUT:-
1
11
111
1111
11111
#23
OBJECTIVE:-
Write a Python script to calculate sum of following
series:
S = (1)+(1+2)+(1+2+3)+.......+(1+2+3+.........+n)
CODE:-
sum=1
n=input("How many term ? ")
for a in range(2,n+1):
for b in range(1,a+1):
sum+=b
print 'Sum of ',n,' term is: ',sum
INPUT:-
How many term? 9
OUTPUT:-
Sum of 9 term is: 165
#24
OBJECTIVE:-
Write a program to find sum of series:
s=1+x+x**2+x**3+x**n
CODE:-
x=input("Enter value of X: ")
n=input("Enter value of n: ")
sum=0
for a in range(n):
sum+=x**a
print "Sum of first ",n,' term is: ',sum
INPUT:-
Enter value of X: 9
Enter value of n: 5
OUTPUT:-
Sum of first 5 term is: 7381
#25
#25
OBJECTIVE:-
Write a program to input two numbers and print their
LCM (least common factor) and GCD (greatest common
divisor)
CODE:-
def gcd(n1,n2):
if n1>n2:
m=n2
else:
m=n1
for i in range(m,0,-1):
if n1%i==0 and n2%i==0:
gd=i
break
return gd
def lcm(n1,n2):
prod=n1*n2
lm=prod/gcd(n1,n2)
return lm
number1=input('Enter first number: ')
number2=input('Enter second number: ')
print 'LCM of ',number1,' and ',number2,' is
',lcm(number1,number2)
print 'GCD of ',number1,' and ',number2,' is
',gcd(number1,number2)
INPUT:-
Enter first number: 5
Enter second number: 4
OUTPUT:-
LCM of 5 and 4 is 20
GCD of 5 and 4 is 1
#26
OBJECTIVE:-
Write python script to print following pattern.
1
1 3
1 3 5
1 3 5 7
CODE:-
for a in range(3,10,2):
for b in range(1,a,2):
print b,
print
INPUT:-
OUTPUT:-
1
1 3
1 3 5
1 3 5 7
#27
OBJECTIVE:-
Numbers in form 2**n-1 are call Mersenne Numbers,
e.g. 2**1-1=1, 2**2-1=3,2**3-1=7. Write a python
script that displays first ten Mersenne.
CODE:-
def Mersenne(n):
return 2**n-1
print 'First ten Mersenne numbers: '
for i in range(1,11):
print Mersenne(i),
INPUT:-
OUTPUT:-
First ten Mersenne numbers:
1 3 7 15 31 63 127 255 511 1023
#28
OBJECTIVE:-
Write a python script to generate divisors of a number.
CODE:-
import math
num=input('Enter an integer: ')
print 'Divisors of numbers are: '
mid=int(math.sqrt(num))
for a in range(2,mid+1):
if num%a==0:
print a,
INPUT:-
Enter an integer: 54
OUTPUT:-
Divisors of numbers are:
2 3 6
#29
OBJECTIVE:-
Write a python script to read an integer >1000 and
reverse the number
CODE:-
num=input('Enter an integer(>1000): ')
tnum=num
reverse=0
while tnum:
digit=tnum%10
tnum=tnum/10
reverse=reverse*10+digit
print 'Reverse of ',num,' is: ',reverse
INPUT:-
Enter an integer(>1000): 987185144
OUTPUT:-
Reverse of 987185144 is: 441581789
#30
OBJECTIVE:-
Write a python script to print Fibonacci series 'first 20
elements. Some initial elements of a Fibonacci series
are:
0 1 1 2 3 5 8 ........
CODE:-
first=0
second=1
print first,second,
for a in range(1,19):
third=first+second
print third,
first,second=second,third
INPUT:-
OUTPUT:-
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
2584 4181
#31
OBJECTIVE:-
Given a list of integers, L write code to add the integers
and display the sum.
CODE:-
def sum_list(List):
sum=0
for a in List:
sum+=a
return sum
l=[1,7,8,6,10]
print 'The sum of all integers in List: ',sum_list(l)
INPUT:-
OUTPUT:-
The sum of all integers in List: 32
#32
OBJECTIVE:-
Given a list of integers, L, write code to calculate and
display the sum of all the odd numbers in the list.
CODE:-
def sum_list(List):
sum=0
for a in List:
if a%2!=0:
sum+=a
return sum
l=[1,7,8,6,10]
print 'The sum of all integers in List: ',sum_list(l)
INPUT:-
OUTPUT:-
The sum of all integers in List: 8
#33
OBJECTIVE:-
Write a function that takes any two lists L and M of the
same size as parameters and return a list which
containing elements are sums of the corresponding
elements in L and M. for instance if L=[3,1,4] and
M=[1,5,9] then new list should be equal to [4,6,13].
CODE:-
def add_lists(L,M):
new_list=[]
length=len(L)
for i in range(length):
new_list.append(L[i]+M[i])
return new_list
INPUT:-
add_lists('sd','sa')
OUTPUT:-
['ss', 'da']
#34
OBJECTIVE:-
Ask the user to enter a list of string. Create a new list
that consists of those string with their first characters
removed.
CODE:-
word_list=[]
while True:
ele=raw_input('Enter String elements in list "end" to
end: ')
if ele=='end':
break
else:
word_list.append(ele)
new_list=[]
string=''
for i in word_list:
for j in range(1,len(i)):
string+=i[j]
new_list.append(string)
string=''
print new_list
INPUT:-
Enter String elements in list "end" to end: ['sasin','ssss']
Enter String elements in list "end" to end: ['ssaa','ddss']
Enter String elements in list "end" to end: ['end']
Enter String elements in list "end" to end: [end]
Enter String elements in list "end" to end: end
OUTPUT:-
["'sasin','ssss']", "'ssaa','ddss']", "'end']", 'end]']

More Related Content

What's hot (14)

Activity ..
Activity ..Activity ..
Activity ..
 
C program to add two numbers
C program to add two numbers C program to add two numbers
C program to add two numbers
 
Mcs 011 solved assignment 2015-16
Mcs 011 solved assignment 2015-16Mcs 011 solved assignment 2015-16
Mcs 011 solved assignment 2015-16
 
Mcs 012 soved assignment 2015-16
Mcs 012 soved assignment 2015-16Mcs 012 soved assignment 2015-16
Mcs 012 soved assignment 2015-16
 
201506 CSE340 Lecture 21
201506 CSE340 Lecture 21201506 CSE340 Lecture 21
201506 CSE340 Lecture 21
 
Qno 1 (e)
Qno 1 (e)Qno 1 (e)
Qno 1 (e)
 
201506 CSE340 Lecture 23
201506 CSE340 Lecture 23201506 CSE340 Lecture 23
201506 CSE340 Lecture 23
 
Encoders
EncodersEncoders
Encoders
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
201506 CSE340 Lecture 20
201506 CSE340 Lecture 20 201506 CSE340 Lecture 20
201506 CSE340 Lecture 20
 
C Programming
C ProgrammingC Programming
C Programming
 
Decoders
DecodersDecoders
Decoders
 
Encoder & Decoder
Encoder & DecoderEncoder & Decoder
Encoder & Decoder
 
Encoders
EncodersEncoders
Encoders
 

Similar to Sasin nisar

Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdfYashMirge2
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxShamshad
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfrajatxyz
 
Programada chapter 4
Programada chapter 4Programada chapter 4
Programada chapter 4abdallaisse
 
C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdfT17Rockstar
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxjeyel85227
 
1 ECE 175 Computer Programming for Engineering Applica.docx
1  ECE 175 Computer Programming for Engineering Applica.docx1  ECE 175 Computer Programming for Engineering Applica.docx
1 ECE 175 Computer Programming for Engineering Applica.docxoswald1horne84988
 
C Language Programming Introduction Lecture
C Language Programming Introduction LectureC Language Programming Introduction Lecture
C Language Programming Introduction Lecturemyinstalab
 
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersAnswers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersSheila Sinclair
 
python file for easy way practicle programs
python file for easy way practicle programspython file for easy way practicle programs
python file for easy way practicle programsvineetdhand2004
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfparthp5150s
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docxRadhe Syam
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsProf. Dr. K. Adisesha
 

Similar to Sasin nisar (20)

Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
 
xii cs practicals
xii cs practicalsxii cs practicals
xii cs practicals
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docx
 
Python Question - Python Assignment Help
Python Question - Python Assignment HelpPython Question - Python Assignment Help
Python Question - Python Assignment Help
 
Spl book salution
Spl book salutionSpl book salution
Spl book salution
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
Programada chapter 4
Programada chapter 4Programada chapter 4
Programada chapter 4
 
C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdf
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
 
1 ECE 175 Computer Programming for Engineering Applica.docx
1  ECE 175 Computer Programming for Engineering Applica.docx1  ECE 175 Computer Programming for Engineering Applica.docx
1 ECE 175 Computer Programming for Engineering Applica.docx
 
PRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptxPRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptx
 
C Language Programming Introduction Lecture
C Language Programming Introduction LectureC Language Programming Introduction Lecture
C Language Programming Introduction Lecture
 
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersAnswers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
 
python file for easy way practicle programs
python file for easy way practicle programspython file for easy way practicle programs
python file for easy way practicle programs
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docx
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Programming egs
Programming egs Programming egs
Programming egs
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programs
 

Recently uploaded

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 

Recently uploaded (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Sasin nisar

  • 1. - Sasin Nisar - Class 12/B
  • 4. #1 OBJECTIVE:- Write a program to input any choice and to implement the following. Choice Find 1. Area of square 2. Area of rectangle 3. Area of triangle CODE:- print 'Choicet Find' print '1.t Area of square' print '2.t Area of rectangle' print '3.t Area of triangle' c = input ("nEnter any Choice: ") if(c==1): s = input("nEnter any side of the square: ") a = s*s print"Area = ",a elif(c==2): l = input("nEnter length: ") b = input("Enter breadth: ") a = l*b
  • 5. print"Area = ",a elif(c==3): x = input("nEnter first side of triangle: ") y = input("enter second side of triangle: ") z = input("enter third side of triangle: ") s = (x+y+z)/2.0 A = ((s-x)*(s-y)*(s-z))**0.5 print"Area=",A else: print "Wrong input" INPUT:- Choice Find 1. Area of square 2. Area of rectangle 3. Area of triangle Enter any Choice:1 Enter any side of square: 7 OUTPUT:- Area=49
  • 6. #2 OBJECTIVE:- Write a program to input any number and to print all natural numbers up to given number. CODE:- n = input("Enter any number: ") for i in range(1,n+1): print i, INPUT:- Enter any number: 7 OUTPUT:- 1 2 3 4 5 6 7
  • 7. #3 OBJECTIVE:- Write a program to input any number and to find sum of all natural numbers up to given number. CODE:- n = input("Enter any number") sum= 0 for i in range(1,n+1): sum = sum+i print "sum=",sum INPUT:- Enter any number: 11 OUTPUT:- Sum=66
  • 8. #4 OBJECTIVE:- Write a program to input any number and to find reverse of that number. CODE:- n = input("Enter any number: ") r = 0 while(n>0): r = r*10+n%10 n = n/10 print "reverse number is", r INPUT:- Enter any number: 76655456 OUTPUT:- reverse number is 65455667
  • 9. #5 OBJECTIVE:- Write a function which take one parameter and return binary number equivalent to that number. CODE:- def binary_converter(x): if x==0: return 0 else: bit=[] while x: bit.append(x%2) x=x/2 return bit[::-1] INPUT:- binary_converter(112) OUTPUT:- [1, 1, 1, 0, 0, 0, 0]
  • 10. #6 OBJECTIVE:- Write a program to read a number.if the number is even then print half the number otherwise print the next number. End your program by printing 'Thank you! CODE:- n=input('Enter number: ') if n%2==0: print 'the number is even:' print 'the half number is: ',n/2.0 else: print 'the number is odd: ' print 'the next number is: ',n+1 print 'Thank you!!!' INPUT:- Enter number: 44 OUTPUT:- the number is even: the half number is: 22.0 Thank you!!!
  • 11. #7 OBJECTIVE:- Write a program to compute tax payable by a person according to his salary as per following rates: salary tax rate less than 10000 0% 10000<=salary<20000 5% 20000<=salary<40000 10% 40000 or higher 12% CODE:- salary=input('Enter salary: ') if salary<10000: rate=0.0 elif salary<20000: rate=0.05 elif salary<40000: rate=0.10 else: rate=0.12 print 'you must pay',rate*salary,'as taxes'
  • 12. INPUT:-Enter salary: 20000 OUTPUT:-you must pay 2000 as taxes
  • 13. #8 OBJECTIVE:- Write a program to print sum of all natural numbers between 1 to 7. CODE:- sum=0 for i in range(1,8): sum+=i print 'sum of natural number from 1 to 7 is: ',sum INPUT:- OUTPUT:- Sum of natural number from 1 to 7 is: 28
  • 14. #9 OBJECTIVE:- Write a program to input some numbers repeatedly and print their sum. The program ends when user say no more to enter( normal termination) or program aborts when the number entered is less than zero. CODE:- count=sum=0 ans='y' while ans=='y': num=input('Enter number: ') if num<0: print 'Number entred is below zero.Aborting!!!' break sum+=num count+=1 ans=raw_input('Want to enter more numbers?(y/n)..') else: print 'you entered',count,' numbers so for.' print 'Sum of numbers entered ',sum
  • 15. INPUT:- Y Enter number: (8) Want to enter more numbers?(y/n).. y Enter number:-1 OUTPUT:- Number entred is below zero.Aborting!!! Sum of numbers entered 8
  • 16. #10 OBJECTIVE:- Write a short program to print the following series. (i) 1 4 7 10 ........... 40 (ii) 1 -4 7 -10...........-40 CODE:- #(i) for i in range(1,41,3): print i, #(ii) for i in range(1,41,3): if i%2==0: print i*(-1), else: print i, INPUT:- OUTPUT:- (i) 1 4 7 10 13 16 19 22 25 28 31 34 37 40 (ii) 1 -4 7 -10 13 -16 19 -22 25 -28 31 -34 37 -40
  • 17. #11 OBJECTIVE:- Write a short program to find average of list of numbers entered through keyboard. CODE:- sum=0 count=0 end='' while end!='end': number=raw_input('Enter a number: ') if number.lower()=='end': break sum+=float(number) count+=1 print 'the average of given numbers is: ',sum/count INPUT:- Enter a number: 1 Enter a number: 3 Enter a number: 5 Enter a number: 7
  • 18. Enter a number: 9 Enter a number: end OUTPUT:- the average of given numbers is 5.0
  • 19. #12 OBJECTIVE:- Write a Short program to find largest number of a list of numbers entered through keyboard. CODE:- max=0 while True: number=raw_input('Enter a Number: ') if number.lower()=='end': break if float(number)>max: max=float(number) print 'Maximum number among all numbers is: ',max INPUT:- Enter a Number: 23145564234 Enter a Number: 123453 Enter a Number: end OUTPUT:- Maximum number among all numbers is: 23145564234
  • 20. #13 OBJECTIVE:- Write a program to check whether a given number is palindrome or not. CODE:- num=input('Enter a number: ') tem=num rev=0 while(num>0): digit=num%10 num=num/10 rev=rev*10+digit if rev==tem: print "The number is a palindrome!" else: print "The number isn't a palindrome!" INPUT:- Enter a number:1221 OUTPUT:- The number is a palindrome!
  • 21. #14 OBJECTIVE:- Write a python program to sum of the given sequences: (i) 2/9 - 5/13 + 8/17+....... (ii)1**2+3**2+5**2+.......+n**2 CODE:- #(i) number=input('Enter number: ') num=2.0 den=9.0 sum=num/den sign=-1 for i in range(2,number+1): num=num+3 den=den+4 sum=sum+(num)/(den)*sign sign*=-1 print 'sum of series up to: ',number, ' is: ',sum
  • 22. #(ii) sum=0 num=input('Enter a Number: ') for i in range(1,2*num+1,2): sum+=i**2 print 'the sum of series up to ',num,' term is: ',sum INPUT:- (i) Enter number: 21314 (ii) Enter number: 21314 OUTPUT:- (i) sum of series up to: 21314 is: -0.318093834875 (ii) the sum of series up to 21314 term is: 12910219335754
  • 23. #15 OBJECTIVE:- Write a python program to sum the sequence a)1 + 1/1! + 1/2! + 1/3! + ........... b)x + x**2/2 + x**3/3 + ........... x**n/n CODE:- a) import math num=input('Enter a number: ') sum=1.0 for i in range(1,num): sum=sum+1.0/math.factorial(i) print 'the sum of series up to ',num,' term: ',sum b) X=input('Enter value of X: ') N=input('Enter value of N: ') sum=X for i in range(2,N+1): sum+=float(X**i)/i
  • 24. print 'the sum of series up to ',N,' with value ',X,' is: ',sum INPUT:- a)Enter a number: 48 b)Enter value of X: 48 Enter value of N: 2 OUTPUT:- a) the sum of series up to 48 term: 2.71828182846 b) the sum of series up to 2 with value 48 is: 1200.0
  • 25. #16 OBJECTIVE:- Write a program input four digit year and find entered year is leap year or not. CODE:- year =input('Enter 4 digit year: ') if (( year%400 == 0)or (( year%4 == 0 ) and ( year%100 != 0))): print year , ' is leap year' else: print year ,' is not leap year ' INPUT:- Enter 4 digit year: 2009 OUTPUT:- 2009 is not a leap year
  • 26. #17 OBJECTIVE:- Write a program using nested loop to produce the following pattern A A B A B C A B C D A B C D E A B C D E F CODE:- for i in range(65,71): for j in range(65,i+1): print chr(j), print INPUT:- OUTPUT:- A A B A B C
  • 27. A B C D A B C D E
  • 28. #18 OBJECTIVE:- Write a program using nested loops to produce a rectangle of *s with 6 rows and 20 *s per row. CODE:- for i in range(6): for i in range(20): print '*', print INPUT:- OUTPUT:- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  • 29. #19 OBJECTIVE:- Write a short program to input a digit and print it in word. CODE:- digit=input('Enter a digit: ') inword='' if digit==1: inword='one' elif digit==2: inword='two' elif digit==3: inword='three' elif digit==4: inword='four' elif digit==5: inword='five' elif digit==6: inword='six' elif digit==7:
  • 30. inword='seven' elif digit==8: inword='eight' elif digit==9: inword='nine' elif digit==0: inword='zero' else: print 'invalid digit entry: ' print 'Digit ',digit,' in word is: ',inword INPUT:- Enter a digit: 9 OUTPUT:- Digit 9 in word is: nine
  • 31. #20 OBJECTIVE:- Write a short program to check whether square root of given number prime or not. CODE:- from math import sqrt number=input('Enter a Number: ') sqr_number=sqrt(number) limit=int(sqrt(sqr_number))+1 for i in range(2,limit): if sqr_number%i==0: print 'Square root of given number is not Prime!!' break else: print 'Square root of given number is Prime!!' INPUT:- Enter a Number: 49 OUTPUT:- Square root of given number is Prime!!
  • 32. #21 OBJECTIVE:- Write a program to print first n odd number in descending order. CODE:- number=input('Enter a Number: ') for i in range(number,0,-1): if i%2!=0: print i, INPUT:- Enter a Number:12 OUTPUT:- 11 9 7 5 3 1
  • 33. #22 OBJECTIVE:-Write a program to print the following using a single loop.(no nested loop) 1 11 111 1111 11111 CODE:- n=1 for a in range(5): print n n=n*10+1 INPUT:- OUTPUT:- 1 11 111 1111 11111
  • 34. #23 OBJECTIVE:- Write a Python script to calculate sum of following series: S = (1)+(1+2)+(1+2+3)+.......+(1+2+3+.........+n) CODE:- sum=1 n=input("How many term ? ") for a in range(2,n+1): for b in range(1,a+1): sum+=b print 'Sum of ',n,' term is: ',sum INPUT:- How many term? 9 OUTPUT:- Sum of 9 term is: 165
  • 35. #24 OBJECTIVE:- Write a program to find sum of series: s=1+x+x**2+x**3+x**n CODE:- x=input("Enter value of X: ") n=input("Enter value of n: ") sum=0 for a in range(n): sum+=x**a print "Sum of first ",n,' term is: ',sum INPUT:- Enter value of X: 9 Enter value of n: 5 OUTPUT:- Sum of first 5 term is: 7381 #25
  • 36. #25 OBJECTIVE:- Write a program to input two numbers and print their LCM (least common factor) and GCD (greatest common divisor) CODE:- def gcd(n1,n2): if n1>n2: m=n2 else: m=n1 for i in range(m,0,-1): if n1%i==0 and n2%i==0: gd=i break return gd def lcm(n1,n2): prod=n1*n2 lm=prod/gcd(n1,n2) return lm number1=input('Enter first number: ')
  • 37. number2=input('Enter second number: ') print 'LCM of ',number1,' and ',number2,' is ',lcm(number1,number2) print 'GCD of ',number1,' and ',number2,' is ',gcd(number1,number2) INPUT:- Enter first number: 5 Enter second number: 4 OUTPUT:- LCM of 5 and 4 is 20 GCD of 5 and 4 is 1
  • 38. #26 OBJECTIVE:- Write python script to print following pattern. 1 1 3 1 3 5 1 3 5 7 CODE:- for a in range(3,10,2): for b in range(1,a,2): print b, print INPUT:- OUTPUT:- 1 1 3 1 3 5 1 3 5 7
  • 39. #27 OBJECTIVE:- Numbers in form 2**n-1 are call Mersenne Numbers, e.g. 2**1-1=1, 2**2-1=3,2**3-1=7. Write a python script that displays first ten Mersenne. CODE:- def Mersenne(n): return 2**n-1 print 'First ten Mersenne numbers: ' for i in range(1,11): print Mersenne(i), INPUT:- OUTPUT:- First ten Mersenne numbers: 1 3 7 15 31 63 127 255 511 1023
  • 40. #28 OBJECTIVE:- Write a python script to generate divisors of a number. CODE:- import math num=input('Enter an integer: ') print 'Divisors of numbers are: ' mid=int(math.sqrt(num)) for a in range(2,mid+1): if num%a==0: print a, INPUT:- Enter an integer: 54 OUTPUT:- Divisors of numbers are: 2 3 6
  • 41. #29 OBJECTIVE:- Write a python script to read an integer >1000 and reverse the number CODE:- num=input('Enter an integer(>1000): ') tnum=num reverse=0 while tnum: digit=tnum%10 tnum=tnum/10 reverse=reverse*10+digit print 'Reverse of ',num,' is: ',reverse INPUT:- Enter an integer(>1000): 987185144 OUTPUT:- Reverse of 987185144 is: 441581789
  • 42. #30 OBJECTIVE:- Write a python script to print Fibonacci series 'first 20 elements. Some initial elements of a Fibonacci series are: 0 1 1 2 3 5 8 ........ CODE:- first=0 second=1 print first,second, for a in range(1,19): third=first+second print third, first,second=second,third INPUT:- OUTPUT:- 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
  • 43. #31 OBJECTIVE:- Given a list of integers, L write code to add the integers and display the sum. CODE:- def sum_list(List): sum=0 for a in List: sum+=a return sum l=[1,7,8,6,10] print 'The sum of all integers in List: ',sum_list(l) INPUT:- OUTPUT:- The sum of all integers in List: 32
  • 44. #32 OBJECTIVE:- Given a list of integers, L, write code to calculate and display the sum of all the odd numbers in the list. CODE:- def sum_list(List): sum=0 for a in List: if a%2!=0: sum+=a return sum l=[1,7,8,6,10] print 'The sum of all integers in List: ',sum_list(l) INPUT:- OUTPUT:- The sum of all integers in List: 8
  • 45. #33 OBJECTIVE:- Write a function that takes any two lists L and M of the same size as parameters and return a list which containing elements are sums of the corresponding elements in L and M. for instance if L=[3,1,4] and M=[1,5,9] then new list should be equal to [4,6,13]. CODE:- def add_lists(L,M): new_list=[] length=len(L) for i in range(length): new_list.append(L[i]+M[i]) return new_list INPUT:- add_lists('sd','sa') OUTPUT:- ['ss', 'da']
  • 46. #34 OBJECTIVE:- Ask the user to enter a list of string. Create a new list that consists of those string with their first characters removed. CODE:- word_list=[] while True: ele=raw_input('Enter String elements in list "end" to end: ') if ele=='end': break else: word_list.append(ele) new_list=[] string='' for i in word_list: for j in range(1,len(i)): string+=i[j] new_list.append(string) string=''
  • 47. print new_list INPUT:- Enter String elements in list "end" to end: ['sasin','ssss'] Enter String elements in list "end" to end: ['ssaa','ddss'] Enter String elements in list "end" to end: ['end'] Enter String elements in list "end" to end: [end] Enter String elements in list "end" to end: end OUTPUT:- ["'sasin','ssss']", "'ssaa','ddss']", "'end']", 'end]']