Ques 1: Write a program to check number is buzz or not?
Code:-
num=int(input("enter value of number:"))
if num%7==0 or num%10==7:
print(num,"is a buzz number.")
else:
print(num,"is a not buzz number.")
Output:
Enter value of number:27
27 is a buzz number.
Ques 2: Write a program to check number is binary or not?
Code:-
num=int(input("enter value of number:"))
if num==0 or num==1:
print(num,"is a binary number.")
else:
print(num,"is a not binary number.")
Output:
Enter value of number:1
27 is a binary number.
Page No. 1
Ques 3: Write a program to check number is binary or not?
Code:-
num=int(input("enter value of number:"))
if num==0 or num==1:
print(num,"is a binary number.")
else:
print(num,"is a not binary number.")
Output:
Enter value of number:1
27 is a binary number.
Ques 4 :Write a program to check number is positive, negative and
zero?
Code:-
num=int(input("enter value of number:"))
if num>0:
print(num,"is a positive number")
elif num<0:
print(num,"is a negative number")
else:
print(num,"is a neutral number")
Output:
Enter value of number:-9
-9 is a negative number.
Page No. 2
Ques 5. Write a Program to find number is Palindrome or not?
Code:-
n=int(input("Enter the value of N:"))
temp=n
rev=0
while n>0:
rem=n%10
rev=rev*10+rem
n=n//10
if rev==temp:
print("Number is Palindrome")
else:
print("Number is not Palindrome")
Output:-
Enter the value of N : 121
Number is Palindrome
Ques 6: Write a Program to check number is perfect or not?
Code:-
n=7
sum=0
Page No. 3
for i in range(1 ,n):
if(n %i==0):
sum+=i
if (sum==n):
print(n ,"is a perfect number")
else:
print(n ,"is not a perfect number")
Output:-
7 is not a perfect number
Ques 7. Write a program to count the number of digits in number?
Code:-
n=1234
count=0
while n>0:
rem=n%10
count=count+1
n=n//10
print(count)
Output:-
4
Page No. 4
Ques 8. Write a program to calculate sum of digits of a number?
Code:-
n=int(input("Enter the value of n:"))
i=1
sum=0
while i<=n:
sum=sum + i
i=i+1
print(sum)
Output:-
Enter the value of n:5
Ques 9. Write a Program to find the factors of a number.
Code:-
n=int(input("Enter the value of n:"))
t1=0
t2=1
print(t1)
print(t2)
for i in range(1,n+1):
nt=t1+t2
t1=t2
Page No. 5
t2=nt
print(nt)
Output:-
Enter the value of n: 3
0
1
1
2
Ques 10: write a program to print ASCII code for entered string or
message.?
Code:-
message="zed-king"
for i in message:
print(f"{i}:{ord(i)}")
Output:-
z:122
e:101
d:100
-:45
k:107
i:105
Page No. 6
n:110
g:103
Ques 11: Write a program to find table of n number?
Code:-
num=int(input("enter value of number:"))
i=1
while i<=10:
print(num*i)
i=i+1
Output:
Enter value of number:7
7
14
21
28
35
42
49
56
70
Page No. 7
Ques 12. Write a Program to find number is Palindrome or not?
Code:-
n=int(input(“Enter the value of N:”))
temp=n
rev=0
while n>0:
rem=n%10
rev=rev*10+rem
n=n//10
print(rev)
Output:-
Enter the value of N : 123
321
Ques 13: write a program to print all the prime numbers within a given
range.
Code:-
start=0
end=50
print(f”prime numbers between {start} and {end} are:”)
for num in range(start,end+1):
if num>1:
for I in range(2,int(num**0.5)+1):
if num%i==0:
break
Page No. 8
else:
print(num,end=” “)
Output
prime numbers between 0 and 50 are:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
Ques 13: write a program to print display triangle * pattern.
Code:-
i=1
while i<=5:
j=1
while j<=i:
print(“*”,end=””)
j=j+1
print()
i=i+1
Output:-
*
**
Page No. 9
Ques 14: write a program to print display triangle * pattern.
Code:-
i=1
while i<=5:
j=1
while j<=i:
print(I,end=”")
j=j+1
print()
i=i+1
Output:-
1
22
333
4444
55555
Ques 14: write a program to print display triangle * pattern.
Code:-
i=1
while i<=5:
j=1
while j<=i:
print(j,end="")
j=j+1
print()
i=i+1
Page No. 10
Output:-
1
12
123
1234
12345
Ques 15: Let us take an example to demonstrate how to read lines of
files using the readline() function in Python.
Code:-
#open the [Link] in read mode. It may cause an error if no such file
exists.
fileptr = open("[Link]","r");
#stores all the data of the file into the variable content
content = [Link]()
content1 = [Link]()
#prints the content of the file
print(content)
print(content1)
#closes the opened file
[Link]()
Output:
Python is a modern-day language.
It makes things so simple.
Page No. 11
Ques 16: Write a program to check whether year is leap or not?
Code
year=int(input("enter year:"))
if year%400==0:
print(year,"is a leap year")
elif year%100==0:
print(year,"is a not leap year")
elif year%4==0:
print(year,"is a leap year")
else:
print(year,"is a not leap year")
Output:-
enter year:2022
2022 is a not leap year
Page No. 12
Ques 17: Write a program to find sum of even number between 1-10
natural number.
Code
i=1
sum=0
while i<=10:
if i%2==0:
sum=sum+i
i=i+1
print(sum)
Output:-
30
Ques 17: Write a program Swap of two number.
Code
a=int(input("enter value of a:"))
b=int(input("enter value of b:"))
print("before swapping")
print("A:",a)
print("B:",b)
swap=a
a=b
b=swap
print("A:",a)
print("B:",b)
Page No. 13
Output:-
enter value of a:10
enter value of b:20
before swapping
A: 10
B: 20
A: 20
B: 10
Ques 17: Write a program Swap of two number without Third
variable.
Code
a=int(input("enter value of a:"))
b=int(input("enter value of b:"))
print("before swapping")
print("A:",a)
print("B:",b)
a=a+b
b=a-b
a=a-b
print("A:",a)
print("B:",b)
Output:-
enter value of a:10
enter value of b:20
before swapping
A: 10
B: 20
A: 20
B: 10
Page No. 14
Ques 17: Write a program to find factoral of n number.
Code
n=int(input("enter value of n:"))
fact=1
i=n
while i>=1:
fact=fact*i
i=i-1
print("factorial is =",fact)
Output:-
enter value of n:5
factorial is = 120
Page No. 15