R23 PYTHON LAB
R23 PYTHON LAB
1.Write
a program to find the largest element
among three Numbers.
# The following code finds the Largest of Three
Unique Numbers using if-elif-else
# Taking user input
num1 = int(input("Enter a first number : "))
num2 = int(input("Enter a second number : "))
num3 = int(input("Enter a third number : "))
# Condition checking
if num1>num2 and num1>num3:
print(f"First number ({num1}) is the largest.")
elif num2>num1 and num2>num3:
print(f"Second number ({num2}) is the largest.")
else:
print(f"Third number ({num3}) is the largest.")
Output
To print all the prime numbers between the given interval, the user has to follow the
following steps:
if number > 1:
if (number % i) == 0:
break
else:
print (number)
Output:
x = 5.4
y = 10.3
print ("Before swapping: ")
# Swap code
x = x + y # x = 15.7, y = 10.3
y = x - y # x = 15.7, y = 5.4
x = x - y # x = 10.3, y = 5.4
Output:
Before swapping:
Value of x : 5.4 and y : 10.3
After swapping:
Value of x : 10.3 and y : 5.4
Sample Output:
for a in range(1,11):
print(num,'x',a,'=',num*a)
Output
Multiplication Table of :
7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70