Class 11 Practical Term 1 AND 2
Class 11 Practical Term 1 AND 2
, if a
number is divisible by another number).
number1 = int( input( "Enter first number : ") )
number2 = int( input ( "Enter second number : ") )
remainder = number1% number2
if remainder ==0:
print (number1, "is divisible by" , number2)
else :
print (number1, "is not divisible by" , number2)
2. Program that takes a number and checks whether the given number is odd or
even.
Program:
num = int (input( "Enter an integer:"))
if num %2 ==0 :
print ( num, "is even number . " )
else:
print (num, "is odd number ." )
Enter an integer : 8
8 is EVEN number.
3. Program that reads to two numbers and an arithmetic operator and displays
the computed result.
result = 0
if op == "+":
elif op == "-" :
elif op =="*" :
result = num1 * num2
elif op == "/" :
elif op == "%" :
else :
4 . Program that reads three numbers ( integers) and prints them in an ascending
order.
if y < z :
else :
if x < z :
else :
else :
if x < y :
else :
5.Program to calculate and print the sums of even and odd integers of the first n
natural numbers.
n = int( input ( “ Up to which natural number ? “ ) )
ctr = 1
sum _ even = sum _ odd = 0
while ctr< = n :
if ctr % 2 == 0 :
sum _even + = ctr #number is even
else :
sum _ odd + = ctr
ctr + = 1
print ( “ The sum of even integers is” , sum _ even )
print ( “ The sum of odd integers is “ , sum – odd )
else :
fact = 1
a=1
while a <=num :
a+=1 #a = a+ 1
10. Program to illustrate the difference between break and continue statements.
***
***
***
for b in range (5 , 8 ) :
print ( )
14. Write a Python script to print Fibonacci series of first 20 elements. Some initial
elements of a Fibonacci series are : 0, 1, 1, 2, 3, 5, 8….
first=0
second=1
print(first)
print(second)
third=first+second
print(third)
first,second=second,third
15. Write a Python script to read an integer > 1000 and reverse the number.
tnum=num
reverse=0
whiletnum !=0:
digit=tnum%10
tnum=int(tnum/10)
reverse=reverse*10+digit
print("Reverse of",num,"is",reverse)
summ=0
temp=num
while(temp>0):
digit=temp%10
summ+=digit**3
temp//=10
if(num==summ):
else:
output:
17.Write a program that reads a string and checks whether it is a palindrome string
or not using string slice.
Solutions :
18. Write a program to input two integers x and n, compute xn using a loop.
power=1
for a in range(n):
power=power*x
19. Write a program to input a number and calculate its double factorial.
fac=1
for i in range(num,0,-2):
fac*=i
print(num,"!! is:",fac)
( for an even integer n , the double factorial is the product of all even positive
integers less than or equal to n. For an odd integers p, the double factorial is the
product of all odd positive integers less than or equal to p. )
Output:
48
=== RESTART:
C:/Users/GOD/AppData/Local/Programs/Python/Python312/pattern.py ===
105
13
135
1357
for a in range(3,10,2):
for b in range(1,a,2):
print(b,end=” ”)
print()
21: Write a Python script that traverses through an input string and prints its
characters in different lines — two characters per line.
length = len(str)
print(str[a:a+2])
output:
co
mp
ut
er
Q22: Write a program to count the number of times a character occurs in the given
string.
Solution
c = str.count(ch)
output:
Enter the string: python
o occurs 1 times
Q23:write a program that replaces all the vowels in the string with “*”.
newStr = ""
forch in str :
lch = ch.lower()
if lch == 'a' \
or lch == 'e' \
or lch == 'i' \
or lch == 'o' \
or lch == 'u' :
newStr += '*'
else :
newStr += ch
print(newStr)
c*mp*t*rsc**nc*
newStr = ""
for ch in str :
newStr= ch+newStr
print(newStr)
margorpnohtyp
for i in range(len(lst)):
lst[i] += n
Enter a number: 10
l2 = []
for i in range(len(l1)):
l2.append(l1[i][1:])
print(l2)
fib=(0,1)
while (fib(len(fib)-1)<term:
fib_len=len(fib)
fib=fib+(fib(fib_len-2)+fib(fib_len-1))
fib_len=len(fib)
if term==0:
elif fib[fib_len-1]==term:
else:
Output:
8 is a fibonacci number
maxcount=0
mode=0
for i in tup:
count=tup.count(i)
if maxcount<count:
maxcount=count
mode=i
print("mode:",mode)
import statistics
tup_sum=sum(tup)
tup_len=len(tup)
30: Can you store the details of 10 students in a dictionary at the same time ? Details include - rollno,
name, marks, grade etc. Give example to support your answer.
n = 10
details = {}
for i in range(n):
name = input("Enter the name of student: ")
print()
print(details)
{1: ['3', 98, 'A'], 2: ['ashis', 78, 'A'], 3: ['bipin', 90, 'A'], 4:
['anjana', 87, 'C'], 5: ['rohit', 89, 'A'], 6: ['renu', 96, 'D'], 7: ['asni',
76, 'C'], 8: ['bhinu', 56, 'B'], 9: ['ranjan', 90, 'A'], 10: ['bibhn', 94,
'A']}
words=sentence.split()
d={}
key=one
if key not in d:
count=words.count(key)
d[key]=count
print(json.dumps(d,indent=1))
output:
['This', 'is', 'a', 'super', 'idea', 'This', 'idea', 'will', 'change', 'the',
'idea', 'of', 'learning']
"This": 2,
"is": 1,
"a": 1,
"super": 1,
"idea": 3,
"will": 1,
"change": 1,
"the": 1,
"of": 1,
"learning": 1
Q32: Write a program to convert a number entered by the user into its corresponding number in
words. For example, if the input is 876 then the output should be 'Eight Seven Six'.
(Hint. use dictionary for keys 0-9 and their values as equivalent words.)
digit = 0
str = ""
digit = num % 10
num = num // 10
output:
Enter a number: 56
Five Six
Enter a number: 89
Eight Nine
Q33. Write a program to create a nested tuple to store roll number, name and marks of students.
tup = ()
ans = "y"
print(tup)
Q34. Write a program to check if a number is present in the list or not. If the number is present, print
the position of the number. Print an appropriate message if the number is not present in the list.
if n in l:
else :
--------------------------
40 found at index 3
count = 0
for ch in str :
lch = ch.lower()
if lch == 'a' \
or lch == 'e' \
or lch == 'i' \
or lch == 'o' \
or lch == 'u' :
count += 1
Vowel Count = 6