Cs Term 1 Prac.
Cs Term 1 Prac.
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
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 ")
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)
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)
20.Write a Python program to length of the string without using len function
Program output
21.