0% found this document useful (0 votes)
2 views2 pages

Python Lab Programs

The document contains three Python programs: the first finds the largest of three input numbers, the second displays all prime numbers within a specified interval, and the third swaps two numbers without using a temporary variable. Each program includes source code and example outputs demonstrating their functionality. The examples illustrate user inputs and the corresponding results for each program.

Uploaded by

25x51a3276
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)
2 views2 pages

Python Lab Programs

The document contains three Python programs: the first finds the largest of three input numbers, the second displays all prime numbers within a specified interval, and the third swaps two numbers without using a temporary variable. Each program includes source code and example outputs demonstrating their functionality. The examples illustrate user inputs and the corresponding results for each program.

Uploaded by

25x51a3276
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

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

You might also like