0% found this document useful (0 votes)
7 views6 pages

Solved Python Program

The document contains a comprehensive list of Python programming exercises, including functions to calculate simple interest, area and circumference of a circle, temperature conversion, and various number checks (even/odd, prime, palindrome). It also includes series generation, string manipulation, and counting vowels and consonants in a string. Each exercise is accompanied by a brief description and a sample function implementation.

Uploaded by

maliberwin4
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)
7 views6 pages

Solved Python Program

The document contains a comprehensive list of Python programming exercises, including functions to calculate simple interest, area and circumference of a circle, temperature conversion, and various number checks (even/odd, prime, palindrome). It also includes series generation, string manipulation, and counting vowels and consonants in a string. Each exercise is accompanied by a brief description and a sample function implementation.

Uploaded by

maliberwin4
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

All Important Python Programing Questions 4. Write a program to calculate and display the simple interest.

[𝑠 =
𝑝 × 𝑡 × 𝑟/100]
1. Write a program to calculate and display the area of a circle.[𝐴 = def simple():
𝜋𝑟 2 ] p=int(“Enter the principle amount”)
def area(r): t=int(“Enter the time”)
a = 3.14 * r**2 r=int(input(“Enter the rate”))
return a s=p*t*r/100
r = int(input(“Enter the radius ”)) return s
x = area()
print(“Area is ”, x) x = simple()
2. Write a program to calculate and display the circumference of a print(f“The simple interest is {x}”)
circle.[𝑐 = 2𝜋r]
def circum(r): 5. Write a program to convert the celsius temperature into Fahrenheit.
9𝐶
c = 2*3.14 * r [𝐹 = 5 + 32]
return a def temp():
r = int(input(“Enter the radius ”)) c=int(input(“Enter the temperature in celsius”))
x = circum(r) f=9*c/5+32
print(“Circumference is”, x) return f
3. Write a program to calculate and display the volume of the x= temp()
box.[𝑣 = 𝑙 × 𝑏 × ℎ] print(f“The converted temperature is {x} ”)
def volume(l,b,h): 6. Write a program to take three inputs from the user and display the
v = l*b*h average of them.
return v def average(a,b,c):
l = int(input(“Enter the length”)) a = int(input(“Enter the first number”)
b = int(input(“Enter the breadth”)) b = int(input(“Enter the second number”))
h = int(input(“Enter height”)) c = int(input(“Enter the third number”))
x = volume(l,b,h) avg = (a+b+c)/3
print(“Volume is ”,v) return avg
x = average()
print(f”The average is”, x)

1
Written By: Niraj B.K.
7. Write a program to check if the given number is even or odd. 10. Write a program to find the greatest number among two inputs.
def check(): def great():
n = int(input(“Enter the number”)) a=int(input(“Enter the first number”))
if n %2 = = 0: b=int((“Enter the second number”))
st=”even” if a>b:
else: return a
st=”odd” else:
return st return b
x = check() x=great()
print(f”The number is”, x) print(“The greatest number is”, x)
8. Write a program to check if given number is divisible by 9 or not. 11. Write a program to find the greatest number among three inputs.
def divisible(): def great():
n = int(input(“Enter the number”)) a=int(input(“Enter the first number”))
if n%9 = = 0; b=int((“Enter the second number”))
return “divisible” c=int(input(“Enter the third number”))
else: if a>b and a>c:
return “not divisible” return a
x=divisible() elif b>a and b>c:
print(“The number is”, x) return b
9. Write a program to check if the given input is positive, negative or else:
zero. return c
def pnz(): x=great()
n=int(input(“Enter the number”)) print(“The greatest number is”,x)
if n>0: 12. Write a program to find the factorial of a number taking input from
return “positive” the user.
elif n<0: def factorial():
return “negative” n=int(input(“Enter the number”))
else: f=1
return “zero” for i in range(1,n):
x = pnz() f=f*i
print(f”The number is ”, x) return f
x=factorial()
print(“The factorial of a number is”; x)

2
Written By: Niraj B.K.
13. Write a program to calculate and display the sum of digits of a return “Palindrome”
number given by the user. else:
def add(): return “Not palindrome”
n=int(input(“enter the number”)) x=add()
s=0 print(“The number is”, x)
while n!=0:
r=n%10 16. Write a program to check if the given number by user is prime or
s=s+r composite.
n=n//10 def prime():
return s n=int(input(“Enter the number”))
x=add() d=0
print(“Sum of digits is”, x) for i in range(2,n):
14. Write a program reverse number given by the user. if n % i = =0:
def add(): d=d+1
n=int(input(“enter the number”)) if d = = 0:
rev=0 return “Prime”
while n!=0: else:
r=n%10 return “Composite”
rev=rev*10+r
x=prime()
n=n//10
return rev print(f”The number is {x}”)
x=add()
print(“Sum of digits is”, x) 17. Write a program to check if the given number by user is armstrong
15. Write a program to check if the given number by the user is or not.[e.g. 13+53+33=153]
palindrome or not. def armstrong():
def add(): n=int(input(“Enter the number”))
n=int(input(“enter the number”)) num=n
num=n s=0
rev=0 while n!=0:
while n!=0: r=n%10
r=n%10 s=s+r*r*r
rev=rev*10+r n=n//10
n=n//10 if num = = s:
if num = = s: return “Armstrong”
3
Written By: Niraj B.K.
else: 20. Write a program to check if the given string from user is
return “Not armstrong” palindrome or not.
x=armstrong() def palindrome():
print(“The number is”,x) word=input(“Enter the string”).lower()
18. Write program to check if the given number is perfect number or rev=word[::-1]
not.[sum of divisor of number must be equal to it except the if rev = = word:
number itself] return ”Palindrome”
def perfect(): else:
n=int(input(“Enter the number”)) return “not palindrome”
d=0 x=palindrome()
for i in range(1,n): print(x)
if n%i= =0: 21. Write a program to print the first 10 natural integers.
d=d+1 def series():
if d = =n: for i in range(1,11):
return “perfect number” print(i, end=”,”)
else: series()
return “not perfect number” 22. Write a program to display the first 10 even integers.
x=perfect() def even():
print(“The number is”,x) a=2
19. Write a program to reverse the string taking input from for i in range(1,11):
user. print(a, end=”,”)
def reverse(): a=a+2
word=input(“Enter the word”).lower() even()
rev=word[::-1] 23. Write a program to display the first 10 odd integers.
return rev def odd():
x=reverse() a=1
print(“The reversed string is”, rev) for i in range(1,11):
print(a,end=”,”)
a=a+2
odd()

4
Written By: Niraj B.K.
24. Write a program to display the series 1,4,9,…. up to 10th terms. if i % 5 = = 0:
def series(): print(i)
for i in range(1,11): divisible_by_5()
print(i*i, end=”,”) 29. Write a program to count the total no. of vowels in a string.
series() def count():
25. Write a program to generate the series 1,8, 27,…… up to 10th word=input(“Enter the word”)
c=0
terms.
vowel=”aeiou”
def series():
for i in word:
for i in range(1,11): if i in vowel:
print(i*i*i, end=”,”) c=c+1
series() return c
26. Write a program to generate the series 5, 10, 15,…. upto 10th terms. x=count()
def series(): print(“The total no. of vowels is”,x)
a=5 30. Write a program to count the total no. of consonants in a string.
for i in range(1,11): def count():
a=a*i word=input(“Enter the word”)
print(a, end=”,”) c=0
series() consonant=”aeiou”
27. Write a program to generate the series 1,1,2,3,5,….. up to 10th for i in word:
if i not in vowel:
terms.(Fibonacci series up to 10th terms)
c=c+1
def fibo(): return c
a=1 x=count()
b=1 print(“The total no. of vowels is”,x)
print(a,b, end=”,”) 31. Write a function to count words in a sentence.
for i in range(1,9): def count():
c=a+b word=input(“Enter the word”)
print(c, end=”,”) c=1
for ch in word:
a=b
if ch = =" ":
b=c c = c+1
fibo() return c
x=count()
28. Create a function to display all numbers between 1 to 50 divisible by print(“The no. of words is”, c)
5.
def divisible_by_5():
for i in range(1, 51):
5
Written By: Niraj B.K.
6
Written By: Niraj B.K.

You might also like