25 Programs
25 Programs
OUTPUT
Enter welcome message : Python welcomes you to its beautiful world.
Hello, python welcomes you to its beautiful world.
OUTPUT
Enter Number 1 : 7
Enter Number 2 : 3
Enter Number 3 : 13
Three Numbers are : 7 3 13
Sum is : 23
Q3. Write a program to input three numbers and swap them as this : 1 st number
becomes the 2nd number, 2nd number becomes the 3rd number and the 3rd number
becomes the first number.
OUTPUT
Enter number 1: 6
Enter number 2: 11
Enter number 3 : 9
Original Number : 6 11 9
After Swapping : 11 9 6
OUTPUT
Enter a number:7
Number is 7
Its cube is 343
OUTPUT
Enter value1 :14
Enter value2 :12
Enter value3 :13
Three numbers are: 14 12 13
Average of given numbers: 13.0
OUTPUT
Enter number 1 : 17
Enter number 2 : 28
Original Number : 17 28
After Swapping : 28 17
Q7. Program that takes a number and checks whether the given number is odd or
even.
OUTPUT
Enter an integer:8
8 is EVEN number.
OUTPUT
Enter first number :119
Enter second number : 3
119.0 is not divisible by 3.0
Q9. Program to display a menu for calculating area of a circle or perimeter of a
circle.
OUTPUT
Enter radius of circle : 2.5
1.Calculate Area
2.Calculate Perimeter
Enter your choice (1 or 2) :1
Area of circle with radius 2.5 is 19.6349375
Q10. Program that reads three numbers (integers) and prints them in ascending
order.
OUTPUT
Enter First number : 5
Enter Second number : 9
Enter Third number : 2
Numbers in ascending order are : 2 5 9
Q11. Program to print table of a number, say 5.
num=5
for a in range(1,11):
print(num, 'x',a, '=',num*a)
OUTPUT
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
num=int(input("Enter a number:"))
fact=1
a=1
while a <=num:
fact*=a
a+=1
print("The factorial of",num,"is",fact)
OUTPUT
Enter a number:3
The factorial of 3 is 6
Q13. Program to input a number and test if it is a prime number.
num=int(input("Enter number:"))
lim=int(num/2)+1
for i in range(2,lim):
rem=num%i
if rem==0:
print(num,"is not a prime number")
break
else:
print(num,"is a prime number")
OUTPUT
Enter number:7
7 is a prime number
Q14. Program to accept three integers and print the largest of the three. Make
use of only if statement.
x=y=z=0
x=float(input("Enter first number : "))
y=float(input("Enter second number : "))
z=float(input("Enter third number : "))
max=x
if y>max:
max=y
if z>max:
max=z
print("Largest number is",max)
OUTPUT
Enter first number: 7.235
Enter second number: 6.99
Enter third number: 7.533
Largest number is 7.533
Q15. Write a program to input an integer and check if it contains any 0 in it.
n=int(input(“Enter a number:”))
s=str(n)
If ‘0’ in s:
print(There’s a 0 in”,n)
else:
print(“No 0 in”,n)
OUTPUT
Enter a number : 6708
There's a 0 in 6708
s=input("Enter a string:")
if(s==s[::-1):
print(s,"is a Palindrome.")
else:
print(s,"is NOT a Palindrome.")
OUTPUT
Enter a string : inosuke
inosuke is NOT a Palindrome.
Q17. Write a program to input two strings. If string1 is contained in string2, then
create a third string with first four characters of string2’ added with word
‘Restore’.
s1=input("Enter string1:")
s2=input("Enter string2:")
print(“Original strings:",s1,s2)
if s1 in s2:
s3=s2[0:4]+"Restore"
print("Final strings:",s1,s3)
OUTPUT
Enter string1: tanjiro
Enter string2: kamado
Original strings: tanjiro kamado
Final strings : tanjiro kamadoRestore
Q18. Write a program that inputs a string that contains a decimal number and
prints out the decimal part of the number. For instance, if 515.8059 is given, the
program should print out 8059.
OUTPUT
Enter a string(a decimal number):515.8059
Given string: 515.8059
OUTPUT
Enter a line of text : I am under the water
I
am
under
the
water
Total words: 5
Q20. Write a python to input three angles and determine if they form a triangle or
not
Enter angle1 : 30
Enter angle2 : 60
Enter angle3 : 90
OUTPUT
At indexes 0 and -6 element : q
At indexes 1 and -5 element : w
At indexes 2 and -4 elemen : e
At indexes 3 and -3 element : r
At indexes 4 and -2 element : t
At indexes 5 and -1 element : y
Q22. Writer program to create a copy of a list. In the list’s copy, add 10 to its first
and last elements. Then display the lists.
L1 = [09 , 17 , 24 ,44]
L2=L1.copy()
Print(“Original list :”,L1)
Print(“Creating copy of the list :”,L2)
L2[0] += 10
L2[-1] += 10
Print(“Copy of list after changes :” , L2)
Print(“Original list :” L1)
OUTPUT
Original list : [09, 17 , 24 , 44]
Created copy of the list : [09 , 17 , 24 , 44]
Created copy of the after chances : [19 , 17 , 24 , 54]
Original list : [09, 17 , 24 , 44]
Q23. Write a program to calculate the mean of a given list of numbers
OUTPUT
OUTPUT
How many dice throws ? 5
Throw 1: 5
Throw 2: 4
Throw 3: 5
Throw 4: 3
Throw 5: 5
Q25. Write a program that inputs a list, replicates it twice and then prints the
sorted list in ascending and descending orders.
OUTPUT
Enter a list : [23, 11, 29]
Original list : [23, 11, 29]
Replicated list: [23, 11, 29, 23, 11, 29]
Sorted in ascending order: [11, 11, 23, 23, 29, 29]
Sorted in descending order: [29, 29, 23, 23, 11, 11]