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

Cs Term 1 Prac.

Uploaded by

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

Cs Term 1 Prac.

Uploaded by

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

School Name: Seth Anandram Jaipuria

School
Session 2024-25

PYTHON
PROGRAMMING FILE
SUBMITTED TO: SUBMITTED BY:
1. Write a Python program to swap two variables
Program output
a= 5 The value of a after swapping: 10
b = 10 The value of b after swapping: 5

c=a
a=b
b=c

print("The value of a after swapping:",a)


print("The value of b after swapping:",b)

2. Write a Python program to input angles of a triangle and check whether triangle
is valid or not.
Program output
a = int(input('Enter 1st angle: ')) Enter 1st angle: 53
b = int(input('Enter 2nd angle: ')) Enter 2nd angle: 37
c = int(input('Enter 3rd angle: ')) Enter 3rd angle: 90
d=a+b+c the triangle is valid
if d==180:
print(" the triangle is valid ")
else:
print(" the triangle is not valid ")

3. Write a Python program to input all sides of a triangle and check whether triangle
is valid or not.
Program output
a = int(input('Enter 1st side: ')) Enter 1st side: 6
b = int(input('Enter 2nd side: ')) Enter 2nd side: 9
c = int(input('Enter 3rd side: ')) Enter 3rd side: 5
if a+b>c and b+c>a and a+c>b: the triangle is valid
print(" the triangle is valid ")

else:
print(" the triangle is not valid ")

4. Write a Python program to check whether the triangle is equilateral, isosceles or


scalene triangle.
Program output
a = int(input('Enter 1st side: ')) Enter 1st side: 2
b = int(input('Enter 2nd side: ')) Enter 2nd side: 3
c = int(input('Enter 3rd side: ')) Enter 3rd side: 6
if a==b==c: the triangle is scalene
print(" the triangle is equitorial ")
elif a==b or b==c or a==c:
print(" the triangle is isosceles ")
else:
print(" the triangle is scalene ")

5. Write a Python program to convert Celsius to Fahrenheit


Program output
a=int(input("enter the temperature in Celsius is enter the temperature in Celsius
")) is 40
b=a*9/5+32 the temperature in Fahrenheit is
print(" the temperature in Fahrenheit is ",b) 104.0

6. Write a Python program to print all-natural numbers in reverse (from n to 1).


Program output
a=int(input("enter any number")) enter any number5
for i in range(a,0,-1): 5
print(i) 4
3
2
1

7. Write a Python program to print all alphabets from a to z.


Program output
a=91 a
for i in range(97,123): b
print(chr(i)) c
:

8. Write a Python program to print all even numbers between 1 to 100


Program output
a=100 2
for i in range(2,101,2): 4
print(i) 6
8
:

9.Write a Python program to print all odd numbers between 1 to 100.


Program output
1
a=100 3
for i in range(1,100,2): 5
print(i) 7
:
10.Write a Python program to find the sum of all-natural numbers between 1 to n.
Program output
a=int(input("enter any number")) enter any number6
i=1 21
c=0
while i<=a:
c=c+i
i=i+1
print(c)

11.Write a Python program to find the sum of all even numbers between 1 to n.
Program output
a=int(input("enter any number")) enter any number6
i=2 12
c=0
while i<=a:
c=c+i
i=i+2
print(c)

12.Write a Python program to count no of vowel in given string


Program output
a=input("enter a string") enter a string krishna
b="aeiou" the no. of vowels in a string 2
cv=0
for i in a:
if(i.lower()).isalpha():
if i in b:
cv=cv+1
print("the no. of vowels in a string",cv)

13.Write a Python program to print all prime number between 1 to 100


Program output
a=100 2
for i in range(1, 101): 3
if i > 1: 5
for b in range(2, i): 7
if (i % b) == 0: 11
break 13
else: 17
print(i) 19
:
14.Write a Python program to print factorials of a given Number.
Program output
a=int(input("Enter any number: ")) Enter any number: 10
i=1 3628800
while a>=1:
i=i*a
a=a-1
print(i)

15.Write a program to check if a given string is a Palindrome


Program output
a=input("Enter the String:") Enter the String:level
l=len(a) String is a Palindrome
b=l-1
i=0
while i<b:
if(a[i]==a[b]):
i=i+1
b=b-1
else:
print("String is not a palindrome")
break
else:
print("String is a Palindrome")

16.Create a program that reverses a string without using any built-in reverse
functions.
Program output
a=input("Enter a string:") Enter a string: cbse
b="" Reversed string: esbc
for i in a:
b=i+b
print("Reversed string:",b)

17.Write a program to find the longest word in a sentence.


Program output
a=input("Enter a string:") Enter a string:my name is
b=a.split() krishna
c=0 word with maximum length is:
d="" krishna
for i in b:
x = len(i)
if x>c and i.isalpha()==True:
c=x
d=i
print("word with maximum length is:",d)
18.Write a Python program to print following pattern
10,9,8,7
6,5,4
3,2
1
Program output

19.Write a program that counts the frequency of each character in a string.


Program output

20.Write a Python program to length of the string without using len function
Program output
21.

You might also like