1.
Python program to find the largest number among the three input
numbers
Source Code:
num1 = int(input('Enter first number: '))
num2 = int(input('Enter second number: '))
num3 = int(input('Enter third number: '))
if (num1 >= num2) and (num1 >= num3):
print('num1 is the largest:',num1)
elif (num2 >= num1) and (num2 >= num3):
print('num2 is the largest:',num2)
else:
print('num3 is the largest:',num3)
Output:
Enter first number: 5
Enter second number: 12
Enter third number: 6
num2 is the largest: 12
2. Python program to display all the prime numbers within an interval
Source Code:
lower = int(input("enter the lower value:"))
upper =int(input("enter the upper value:"))
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
Output:
enter the lower value:5
enter the upper value:10
Prime numbers between 5 and 10 are:
3. Write a program to swap two numbers without using a temporary variable
Source Code:
a = int(input("enter the a value:"))
b =int(input("enter the b value:"))
print('before swapping the a=',a,'and','b=',b,'values')
a=a+b
b=a-b
a=a-b
print('after swapping the a=',a,'and','b=',b,'values')
Output:
enter the a value:20
enter the b value:5
before swapping the a= 20 and b= 5 values
after swapping the a= 5 and b= 20 values