1..write A Python Program To Swap Two Numbers Using A Third Variable
1..write A Python Program To Swap Two Numbers Using A Third Variable
a = a+b
b = a-b
a = a-b
2.. Write a python program to swap two numbers without using third variable
x =30
y = 20
temp = x
x=y
y = temp
print(x)
print(y)
output:-
20
30
3..Write a python program to read two numbers and find the sum of their cubes
a=2
b=3
sum =0
print(sum)
output:
35.
a = 10
b = 20
sum = a+b
4. Write a python program to read three numbers and if any two variables are
equal , print that number.
if a == b or a == c:
print("The Number is 10")
else:
print("Not Equal")
output:-
The Number is 10
5. Write a python program to read three numbers and find the smallest among
them
a,b,c = 10,20,30
if a <= b and a <=c:
print(a,"is the small number")
elif b <= a and b <= c:
print(b,"is the small number")
else:
print(c,"is the small number")
output:-
10 is the small number
Write a python program to read a number ,if it is an even number , print the
square of that number and if it is odd number print cube of that number.
a = int(input("enter the number"))
if a%2 == 0:
print("a is even", a*a)
else:
print("a is odd", a*a*a)
7. Write a python program to read radius of a circle and print the area
PI =3.14
r = float(input("enter the number"))
area = PI*r*r
print("area of circle: %.2f" %area)
Write a python program to read four numbers (representing the four octets of an
IP) and check whether they all are in the range between 0 to 255
a = int(0b11111111)
b = int(0b10000000)
c = int(0b11111111)
d = int(0b10000000)
if 0<= a <=255:
print(" valid Ip")
else:
print("Not valid ip")
if 0<= b <=255:
print(" valid Ip")
else:
print("Not valid ip")
if 0<= c <=255:
print(" valid Ip")
else:
print("Not valid ip")
if 0<= d <=255:
print(" valid Ip")
else:
print("Not valid ip")