0% found this document useful (0 votes)
25 views7 pages

Exam Material

The document contains exam material covering various Python programming concepts like loops, conditional statements, functions etc. divided into multiple groups. It includes problems on calculating area and perimeter of circles, finding odd numbers in a range, checking for divisibility, validity of triangles, leap years, factorials, prime numbers etc. and their solutions.

Uploaded by

sajib.saha8101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views7 pages

Exam Material

The document contains exam material covering various Python programming concepts like loops, conditional statements, functions etc. divided into multiple groups. It includes problems on calculating area and perimeter of circles, finding odd numbers in a range, checking for divisibility, validity of triangles, leap years, factorials, prime numbers etc. and their solutions.

Uploaded by

sajib.saha8101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

EXAM MATERIAL

Group A:

1.calculate the area and perimeter of circle

Answer: pi=3.14

r=float(input("enter the radius of circle:"))

area=(pi*r*r)

perimeter=(2*pi*r)

print("The area of circle is",area)

print("The perimeter of circle is",perimeter)

2. print all odd numbers in a given range

Answer: n=int(input("Enter the number"))

for i in range(n):

if(i%2!=0):

print(i)

3. divisible by 5 and 11 or not

Answer: a=int(input("Enter 1st number:"))

if((a%5==0)and(a%11==0)):

print("divisible by 5 and 11")

else:

print("not divisible by 5 and 11")

4. input angles of a triangle and check whether triangle is valid or not

Answer: a=int(input("Enter 1st number:"))

b=int(input("Enter 2nd number:"))

c=int(input("Enter 3rd number:"))

sum=a+b+c

if(sum==180):

print("Triangle is valid")

else:

print("Triangle is not valid")


5. leap year or not

Answer: y=int(input("Enter 1st number:"))

if((y%4==0)and(y%100!=0)and(y%400==0)):

print("This year is a leap year")

else:

print("This year is not a leap year")

6. divisible by 3 or 5 in a given number

Answer: n=int(input("Enter the range:"))

for i in range(n):

if((i%3==0)or(i%5==0)):

print(i)

Group B:

1.largest palindrome number

Answer: x=[]

y=[]

for i in range(6):

t=int(input("Enter the number:"))

x.append(t)

print(x)

for i in x:

s=0

n=i

while(i>0):

r=i%10

s=s*10+r

i=i//10

if(s==n):

y.append(s)

print(y)

print(max(y))

2. add first n natural numbers using while loop


Answer: n=int(input("Enter the number"))

sum=0

while n>0:

sum=sum+n

n=n-1

print(sum)

3. factorial

Answer: n=int(input("Enter the number:"))

fact=1

if(n>=1):

for i in range(1,n+1):

fact=fact*i

print(fact)

4. reverse of a number

Answer: n= int(input("Enter a number:"))

sum=0

while(n>0):

a=n%10

sum=sum*10+a

n=n//10

print(sum)

6.prime or not

Answer: num = int(input("Enter a number: "))

f=0

for i in range(2,num):

if(num%i)==0:

f=1

if(f==0):

print(num,"is a prime number")


else:

print(num,"is not a prime number")

7. sum the digit of number

Answer: n=int(input("Enter a number: "))

sum=0

while(n>0):

r=n%10

sum=sum+r

n=n//10

print(sum)

8. fibbonacci series

Answer: a=[0,1]

n=int(input("Enter a number: "))

for i in range(n-1):

s=a[i]+a[i+1]

a.append(s)

print(a)

9. armstrong number

Answer: n=int(input("Enter the number:"))

s=0

result=0

result=n

while(n>0):

r=n%10

s=s+pow(r,3)

n=n//10

if(s==result):

print("armstrong number")

else:

print("not armstrong number")

Group C:
*********
*******
*****
***
*

for i in range(1,6):
print(“ ” *i + “*” * ((6-i)*2)-1)

*
**
***
****
*****
****
***
**
*

for i in range(1,10):
if(i<6):
print("*"*i)
else:
print("*"*(10-i))

*
***
*****
*******
*********
*******
*****
***
*

for i in range(1,10):
if(i<6):
print(' '*(5-i)+"*"*((2*i)-1))
else:
print(' '*(i-5)+"*"*(((10-i)*2)-1))

**********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
**********
for i in range(1,10):
if(i<6):
print("*"*(6-i)+' '*((2*i)-2)+"*"*(6-i))
else:
print("*"*(i-4)+' '*((9-i)*2)+"*"*(i-4))

*
***
*****
*******
*********

for i in range(1,10):
if(i<6):
print(' '*(5-i)+"*"*((2*i)-1))

1
22
333
4444

a="1234"
for i in range(1,5):
print(a[i-1:i]*i)

A
AB
ABC
ABCD
ABCDE

a="ABCDE"
for i in range(1,6):
print(a[:i])

1
12
123
1234

a="1234"
for i in range(1,5):
print(a[:i])
Group D:
1. What is the output of the following code?
Answer: my_list = [1, 2, 3, 4, 5]
print(my_list[2])

2. How do you check if a key is present in a dictionary?


Answer: my_dict = {'a': 1, 'b': 2, 'c': 3}
print('a' in my_dict)

3. How can you add an element at the end of a list?


Answer: my_list = [1, 2, 3]
my_list.append(4)
print(my_list)

4. How can you remove a key-value pair from a dictionary?


Answer: my_dict = {'a': 1, 'b': 2, 'c': 3}
my_dict.pop('b')
print(my_dict)

5. How do you find the intersection of two sets: {1, 2, 3} and {3, 4, 5}?
Answer: set1 = {1, 2, 3}
set2 = {3, 4, 5}
intersection_set = set1.intersection(set2)
print(intersection_set)

6. How can you get all the keys and values from a dictionary separately?
Answer: my_dict = {'a': 1, 'b': 2, 'c': 3}
keys = my_dict.keys()
values = my_dict.values()
print(keys) # Output: dict_keys(['a', 'b', 'c'])
print(values) # Output: dict_values([1, 2, 3])

7. Create two sets with some common elements and print their union.
Answer: set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}
union_set = set1.union(set2)
print(union_set)

You might also like