0% found this document useful (0 votes)
103 views

1..write A Python Program To Swap Two Numbers Using A Third Variable

This document contains examples of Python programs that perform tasks like swapping numbers with and without a third variable, finding the sum of cubes of two numbers, checking if two variables are equal, finding the smallest of three numbers, checking if a number is even or odd and printing the square or cube, calculating the area of a circle, and validating an IP address. The programs demonstrate basic Python concepts like variables, conditionals, input, output, arithmetic and logical operators.

Uploaded by

sainaveen
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)
103 views

1..write A Python Program To Swap Two Numbers Using A Third Variable

This document contains examples of Python programs that perform tasks like swapping numbers with and without a third variable, finding the sum of cubes of two numbers, checking if two variables are equal, finding the smallest of three numbers, checking if a number is even or odd and printing the square or cube, calculating the area of a circle, and validating an IP address. The programs demonstrate basic Python concepts like variables, conditionals, input, output, arithmetic and logical operators.

Uploaded by

sainaveen
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/ 5

1..

Write a python program to swap two numbers using a third variable


a=2
b=3

a = a+b
b = a-b
a = a-b

print("after swipe a:", a)


print("after swipe b:",b)
output:
after swipe a: 3                                                                                                                             
after swipe b: 2  

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

sum = (a*3) + (b*3)

print(sum)

output:

35.

a = 10

b = 20

sum = a+b

print("The sum of numbers",sum)

print("the sum of cube is:",sum*3)

4. Write a python program to read three numbers and if any two variables are
equal , print that number.

a = int(input("enter the number"))


b = int(input("enter the number"))
c = int(input("enter the number"))
if a == b or a==c:
print("The number equal ",a)
elif c == b:
print("equal ",b)
else:
print("not equal ")
else:
print("Not Equal")
output:-
Not equal                                                                                                                                    
The Number is 10
2nd model:
a = 10
b = 20
c = 10

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")

You might also like