Computer Project Nov 10 22
Computer Project Nov 10 22
Sec. School
Python Program
Submitted to
Ghazanfer Ali Submitted
by
Name:-Anandita Singh
Class:- XI Sec:-
Maths
Roll No.:-10
INDEX
Q1. Write a program to input a welcome message and print it.
Q3. Write a program to input three numbers and swap them as this : 1st number
becomes the 2nd number, 2nd number becomes the 3rd number and the 3rd number
becomes the first number.
Q7. Program that takes a number and checks whether the given number is odd or
even.
Q9. Program to display a menu for calculating area of a circle or perimeter of a circle.
Q10. Program that reads three numbers (integers) and prints them in ascending order.
Q14. Program to accept three integers and print the largest of the three. Make use of
only if statement.
Q15. Write a program to input an integer and check if it contains any 0 in it.
Q16. Write a program to input a string and check if it is a palindrome string using a
string slice.
Q17.Write a program that inputs a line of text and prints its each word in a separate line.
Also, print the count of words in the line.
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.
Q19..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’.
Q20.. Write a 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.
Q21. Program to print elements of a list [ ‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’ ] in separate lines along
with element’s both indexes (positive and negative).
Q22. Write a python to input three angles and determine if they form a triangle or not.
Q23. Write a program that inputs a list, replicates it twice and then prints the sorted list
in ascending and descending orders.
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
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 that inputs a line of text and prints its each word in a
separate line. Also, print the count of words in the line.
OUTPUT
Enter a line of text : The moon looks lovely tonight
The
moon
looks
lovely
tonight
Total words: 5
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
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: zenitsu
Enter string2: agatsuma
Original strings: zenitsuagatsuma
Final strings :zenitsuagatsumaRestore
Q20. 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]
Q21. Program to print elements of a list [ ‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’ ] in separate lines
along with element’s both indexes (positive and negative).
L = [‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’]
Length = len(L)
For a in range(length):
Print(“At indexes”, a, “and”, (a – length), “element:”, L[a])
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. 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
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]
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 to calculate the mean of a given list of numbers
OUTPUT