Python Vishal
Python Vishal
Practical – 1
page 1
Practical – 2
Aim: Write a Python program to swap two variables using third variable.
Code: x= int(input("Enter The first variable "))
y=int(input("Enter the second variable"))
print(x,y)
temp = x
x=y
y=temp
print("After swapping value of x",x)
print("After swapping value of y",y)
print(x,y)
page 2
Practical – 3
Aim: Write a Python program to swap two variables without third variable.
print(p,q)
p,q=q,p
print(p,q)
Output: Enter the value of first variable5
Enter the value of second variable9
5 9
9 5
page 3
Practical – 4
Aim: Write a Python program to find the square root of a positive number.
Code: y=int(input("Enter the value of y"))
print(y)
square_root= y**0.5
49
page 4
Practical – 5
Rect_radius=l*b
Circle_radius=(2*3.14*(r*r))
page 5
Practical – 6
Aim: Write a Python program to find sum of n natural numbers without loop.
Code: n=int(input("Enter the value of n number "))
sum_n=n*(n+1)/2
page 6
Practical – 7
page 7
Practical – 8
c=a%b
c1=-a%b
c2=a%-b
print(c,c1,c2)
page 8
Set:-2
Practical – 1
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
page 9
Practical – 2
if(number>0):
elif(number<0):
else:
print("number is zero")
page 10
Practical – 3
dis = b * b - 4 * a * c
sqrt_val = math.sqrt(abs(dis))
if dis > 0:
elif dis == 0:
print(-b / (2 * a))
else:
print("Complex Roots")
equationroots(a, b, c)
2.0
-12.0
page 11
Practical – 4
if a in list:
print(f"{a} is a vowel")
else:
character: f
f isn't a vowel
page 12
Practical – 5
if(a > b) :
if (a > c) :
else :
else :
if (b > c) :
else :
number: 34
Maximum is 44
page 13
Practical – 6
Aim: WAP to calculate the salary of an employee based on following conditions (nested if-else):
if (degree == "B.E") :
if (experience < 5) :
salary = 30000
else :
salary = 40000
else :
if (experience < 5) :
salary = 50000
else :
salary = 60000
Enter Experience: 7
page 14
Practical – 7
Aim: WAP to check whether entered input is character, digit or special symbol using ladder if-
else.
Code: ch = input("Enter any character: ")
if (ch.isalpha()):
print('Character is alphabet')
elif (ch.isdigit()):
print('Character is digit')
else :
Character is alphabet
page 15
Set:-3
Practical – 1
sum = (n*(n+1))/2
page 16
Practical – 2
sum = 0
for i in range(n):
Enter a number: 3
Enter a number: 53
Enter a number: 26
Enter a number: 4
Enter a number: 9
page 17
Practical – 3
page 18
Practical – 4
n0, n1 = 0 , 1
temp = 0
print(temp)
n0 = n1
n1 = temp
temp = n0 + n1
Output: Enter a
number: 34
Fibonacci Series:
13
21
34
page 19
Practical – 5
num = str(n)
num1 = num[::-1]
num2 = int(num1)
print(num2)
5348
page 20
Practical – 6
count = 0
if n % i == 0:
count = count + 1
if count == 2:
else:
page 21
Practical – 7
Aim: WAP to print all even numbers between 1 to n except the numbers divisible by 6.
if i%2==0:
if i%6==0:
pass
else:
print(i)
page 22
Practical – 8
page 23
Practical – 9
Aim: Write a python program to check whether given number is Armstrong or not.
Code: num = int(input("Enter a number: "))
temp = num
sum = 0
num_digits = len(str(num))
digit = temp % 10
temp = temp // 10
if num == sum:
else:
page 24
Practical – 10
Aim: Write a python program to check whether given number is Palindrome or not.
Code: n = int(input("Enter a number: "))
num = str(n)
num1 = num[::-1]
num2 = int(num1)
if n == num2:
else:
page 25
Practical – 11
Aim:
For 1:-
Code: n = int(input("Enter a number: "))
print("First Output")
print()
First Output
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
for2:-
Code: print()
print("Second Output")
page 26
print("*", end=" ")
print()
* * * * * *
* * * * *
* * * *
* * *
* *
page 27